Browse Source

dynamite,nextcloud: Parse oneOf, anyOf and allOf more strictly

pull/91/head
jld3103 2 years ago
parent
commit
5bad634842
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 34
      packages/dynamite/lib/src/openapi_builder.dart
  2. 4
      packages/nextcloud/lib/src/nextcloud.openapi.dart
  3. 49
      packages/nextcloud/lib/src/nextcloud.openapi.g.dart

34
packages/dynamite/lib/src/openapi_builder.dart

@ -225,6 +225,7 @@ class OpenAPIBuilder implements Builder {
final String identifier, final String identifier,
final Schema schema, { final Schema schema, {
final bool ignoreEnum = false, final bool ignoreEnum = false,
final Map<String, String>? extraJsonSerializableValues,
}) { }) {
TypeResolveResult? result; TypeResolveResult? result;
if (schema.ref != null) { if (schema.ref != null) {
@ -232,13 +233,26 @@ class OpenAPIBuilder implements Builder {
result = resolveType( result = resolveType(
name, name,
spec.components!.schemas![name]!, spec.components!.schemas![name]!,
extraJsonSerializableValues: extraJsonSerializableValues,
); );
} else if (schema.ofs != null) { } else if (schema.ofs != null) {
if (!resolvedTypes.contains(identifier)) { if (!resolvedTypes.contains(identifier)) {
resolvedTypes.add(identifier); resolvedTypes.add(identifier);
final results = final results = schema.ofs!
schema.ofs!.map((final s) => resolveType('$identifier${schema.ofs!.indexOf(s)}', s)).toList(); .map(
(final s) => resolveType(
'$identifier${schema.ofs!.indexOf(s)}',
s,
extraJsonSerializableValues: {
'disallowUnrecognizedKeys': 'true',
if (extraJsonSerializableValues != null) ...{
...extraJsonSerializableValues,
},
},
),
)
.toList();
output.add( output.add(
Class( Class(
@ -383,6 +397,7 @@ class OpenAPIBuilder implements Builder {
final subResult = resolveType( final subResult = resolveType(
identifier, identifier,
schema.items!, schema.items!,
extraJsonSerializableValues: extraJsonSerializableValues,
); );
result = TypeResolveResult( result = TypeResolveResult(
'List<${subResult.typeName}>', 'List<${subResult.typeName}>',
@ -425,7 +440,18 @@ class OpenAPIBuilder implements Builder {
'/// ${schema.description!}', '/// ${schema.description!}',
], ],
]) ])
..annotations.add(refer('JsonSerializable').call([])) ..annotations.add(
refer('JsonSerializable').call(
[],
{
if (extraJsonSerializableValues != null) ...{
for (final key in extraJsonSerializableValues.keys) ...{
key: refer(extraJsonSerializableValues[key]!),
},
},
},
),
)
..constructors.addAll( ..constructors.addAll(
[ [
Constructor( Constructor(
@ -476,6 +502,7 @@ class OpenAPIBuilder implements Builder {
uppercaseFirstCharacter: true, uppercaseFirstCharacter: true,
), ),
schema.properties![propertyName]!, schema.properties![propertyName]!,
extraJsonSerializableValues: extraJsonSerializableValues,
); );
final propertySchema = schema.properties![propertyName]!; final propertySchema = schema.properties![propertyName]!;
@ -554,6 +581,7 @@ class OpenAPIBuilder implements Builder {
'$identifier${_toDartName(value.toString(), uppercaseFirstCharacter: true)}', '$identifier${_toDartName(value.toString(), uppercaseFirstCharacter: true)}',
schema, schema,
ignoreEnum: true, ignoreEnum: true,
extraJsonSerializableValues: extraJsonSerializableValues,
); );
b b
..name = _toDartName(value.toString()) ..name = _toDartName(value.toString())

4
packages/nextcloud/lib/src/nextcloud.openapi.dart

@ -3223,7 +3223,7 @@ class UserStatusClearAtTime {
// coverage:ignore-end // coverage:ignore-end
} }
@JsonSerializable() @JsonSerializable(disallowUnrecognizedKeys: true)
class UserStatusClearAt { class UserStatusClearAt {
UserStatusClearAt({ UserStatusClearAt({
this.type, this.type,
@ -3422,7 +3422,7 @@ class UserStatusFindStatus {
// coverage:ignore-end // coverage:ignore-end
} }
@JsonSerializable() @JsonSerializable(disallowUnrecognizedKeys: true)
class UserStatus { class UserStatus {
UserStatus({ UserStatus({
this.userId, this.userId,

49
packages/nextcloud/lib/src/nextcloud.openapi.g.dart

@ -1507,10 +1507,16 @@ Map<String, dynamic> _$ProvisioningApiUserToJson(ProvisioningApiUser instance) =
'ocs': instance.ocs?.toJson(), 'ocs': instance.ocs?.toJson(),
}; };
UserStatusClearAt _$UserStatusClearAtFromJson(Map<String, dynamic> json) => UserStatusClearAt( UserStatusClearAt _$UserStatusClearAtFromJson(Map<String, dynamic> json) {
type: $enumDecodeNullable(_$UserStatusClearAtTypeEnumMap, json['type']), $checkKeys(
time: json['time'] == null ? null : UserStatusClearAtTime.fromJson(json['time']), json,
); allowedKeys: const ['type', 'time'],
);
return UserStatusClearAt(
type: $enumDecodeNullable(_$UserStatusClearAtTypeEnumMap, json['type']),
time: json['time'] == null ? null : UserStatusClearAtTime.fromJson(json['time']),
);
}
Map<String, dynamic> _$UserStatusClearAtToJson(UserStatusClearAt instance) => <String, dynamic>{ Map<String, dynamic> _$UserStatusClearAtToJson(UserStatusClearAt instance) => <String, dynamic>{
'type': _$UserStatusClearAtTypeEnumMap[instance.type], 'type': _$UserStatusClearAtTypeEnumMap[instance.type],
@ -1586,16 +1592,31 @@ Map<String, dynamic> _$UserStatusFindStatusToJson(UserStatusFindStatus instance)
'ocs': instance.ocs?.toJson(), 'ocs': instance.ocs?.toJson(),
}; };
UserStatus _$UserStatusFromJson(Map<String, dynamic> json) => UserStatus( UserStatus _$UserStatusFromJson(Map<String, dynamic> json) {
userId: json['userId'] as String?, $checkKeys(
message: json['message'] as String?, json,
messageId: json['messageId'] as String?, allowedKeys: const [
messageIsPredefined: json['messageIsPredefined'] as bool?, 'userId',
icon: json['icon'] as String?, 'message',
clearAt: json['clearAt'] == null ? null : UserStatusClearAtWrap.fromJson(json['clearAt']), 'messageId',
status: $enumDecodeNullable(_$UserStatusTypeEnumMap, json['status']), 'messageIsPredefined',
statusIsUserDefined: json['statusIsUserDefined'] as bool?, 'icon',
); 'clearAt',
'status',
'statusIsUserDefined'
],
);
return UserStatus(
userId: json['userId'] as String?,
message: json['message'] as String?,
messageId: json['messageId'] as String?,
messageIsPredefined: json['messageIsPredefined'] as bool?,
icon: json['icon'] as String?,
clearAt: json['clearAt'] == null ? null : UserStatusClearAtWrap.fromJson(json['clearAt']),
status: $enumDecodeNullable(_$UserStatusTypeEnumMap, json['status']),
statusIsUserDefined: json['statusIsUserDefined'] as bool?,
);
}
Map<String, dynamic> _$UserStatusToJson(UserStatus instance) => <String, dynamic>{ Map<String, dynamic> _$UserStatusToJson(UserStatus instance) => <String, dynamic>{
'userId': instance.userId, 'userId': instance.userId,

Loading…
Cancel
Save