From 7bae1ab83def15a69d036e2c317c5a5dd27c560e Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Mon, 16 Oct 2023 17:43:04 +0200 Subject: [PATCH] refactor(dynamite): add default values as described by openapi Signed-off-by: Nikolas Rimikis --- .../dynamite/lib/src/builder/client.dart | 2 +- .../lib/src/builder/header_serializer.dart | 2 +- .../lib/src/builder/resolve_interface.dart | 2 +- .../lib/src/builder/resolve_mime_type.dart | 4 +- .../dynamite/lib/src/helpers/dynamite.dart | 10 ++--- .../lib/src/models/openapi/header.dart | 7 ++- .../lib/src/models/openapi/header.g.dart | 26 ++++++----- .../lib/src/models/openapi/open_api.dart | 13 +++++- .../lib/src/models/openapi/open_api.g.dart | 26 ++++++----- .../lib/src/models/openapi/operation.dart | 7 ++- .../lib/src/models/openapi/operation.g.dart | 24 +++++------ .../lib/src/models/openapi/parameter.dart | 9 +++- .../lib/src/models/openapi/parameter.g.dart | 19 ++++---- .../lib/src/models/openapi/request_body.dart | 7 ++- .../src/models/openapi/request_body.g.dart | 26 ++++++----- .../lib/src/models/openapi/schema.dart | 9 +++- .../lib/src/models/openapi/schema.g.dart | 43 +++++++++---------- 17 files changed, 140 insertions(+), 96 deletions(-) diff --git a/packages/dynamite/dynamite/lib/src/builder/client.dart b/packages/dynamite/dynamite/lib/src/builder/client.dart index 54adbe4c..d3f9a03c 100644 --- a/packages/dynamite/dynamite/lib/src/builder/client.dart +++ b/packages/dynamite/dynamite/lib/src/builder/client.dart @@ -234,7 +234,7 @@ Iterable buildTags( ).forEach(code.writeln); final operationParameters = ListBuilder(); - final annotations = operation.deprecated ?? false ? refer('Deprecated').call([refer("''")]) : null; + final annotations = operation.deprecated ? refer('Deprecated').call([refer("''")]) : null; var returnDataType = 'void'; var returnHeadersType = 'void'; diff --git a/packages/dynamite/dynamite/lib/src/builder/header_serializer.dart b/packages/dynamite/dynamite/lib/src/builder/header_serializer.dart index ebe8c6ca..77535531 100644 --- a/packages/dynamite/dynamite/lib/src/builder/header_serializer.dart +++ b/packages/dynamite/dynamite/lib/src/builder/header_serializer.dart @@ -122,7 +122,7 @@ Iterable deserializeProperty( state, '${identifier}_${toDartName(propertyName, uppercaseFirstCharacter: true)}', propertySchema, - nullable: isDartParameterNullable(schema.required?.contains(propertyName), propertySchema), + nullable: isDartParameterNullable(schema.required.contains(propertyName), propertySchema), ); yield "case '$propertyName':"; diff --git a/packages/dynamite/dynamite/lib/src/builder/resolve_interface.dart b/packages/dynamite/dynamite/lib/src/builder/resolve_interface.dart index c870a363..0a67357d 100644 --- a/packages/dynamite/dynamite/lib/src/builder/resolve_interface.dart +++ b/packages/dynamite/dynamite/lib/src/builder/resolve_interface.dart @@ -34,7 +34,7 @@ TypeResultObject resolveInterface( '${identifier}_${toDartName(propertyName, uppercaseFirstCharacter: true)}', propertySchema, nullable: isDartParameterNullable( - schema.required?.contains(propertyName), + schema.required.contains(propertyName), propertySchema, ), ); diff --git a/packages/dynamite/dynamite/lib/src/builder/resolve_mime_type.dart b/packages/dynamite/dynamite/lib/src/builder/resolve_mime_type.dart index 3130248d..98329604 100644 --- a/packages/dynamite/dynamite/lib/src/builder/resolve_mime_type.dart +++ b/packages/dynamite/dynamite/lib/src/builder/resolve_mime_type.dart @@ -77,7 +77,7 @@ Iterable resolveMimeTypeEncode( case 'application/x-www-form-urlencoded': final dartParameterRequired = isRequired( operation.requestBody!.required, - mediaType.schema?.$default, + mediaType.schema, ); b.add( Parameter( @@ -100,7 +100,7 @@ Iterable resolveMimeTypeEncode( case 'application/octet-stream': final dartParameterRequired = isRequired( operation.requestBody!.required, - mediaType.schema?.$default, + mediaType.schema, ); b.add( Parameter( diff --git a/packages/dynamite/dynamite/lib/src/helpers/dynamite.dart b/packages/dynamite/dynamite/lib/src/helpers/dynamite.dart index 8df4768b..e093efbb 100644 --- a/packages/dynamite/dynamite/lib/src/helpers/dynamite.dart +++ b/packages/dynamite/dynamite/lib/src/helpers/dynamite.dart @@ -18,16 +18,16 @@ String filterMethodName(final String operationId, final String tag) { String clientName(final String tag) => '${toDartName(tag, uppercaseFirstCharacter: true)}Client'; bool isDartParameterNullable( - final bool? required, + final bool required, final openapi.Schema? schema, ) => - (!(required ?? false) && schema?.$default == null) || (schema?.nullable ?? false); + (!required && schema?.$default == null) || (schema?.nullable ?? false); bool isRequired( - final bool? required, - final dynamic default_, + final bool required, + final openapi.Schema? schema, ) => - (required ?? false) && default_ == null; + required && schema?.$default == null; int sortRequiredParameters(final openapi.Parameter a, final openapi.Parameter b) { if (a.isDartRequired != b.isDartRequired) { diff --git a/packages/dynamite/dynamite/lib/src/models/openapi/header.dart b/packages/dynamite/dynamite/lib/src/models/openapi/header.dart index a9623417..32ac6b01 100644 --- a/packages/dynamite/dynamite/lib/src/models/openapi/header.dart +++ b/packages/dynamite/dynamite/lib/src/models/openapi/header.dart @@ -14,7 +14,12 @@ abstract class Header implements Built { @BuiltValueField(compare: false) String? get description; - bool? get required; + bool get required; Schema? get schema; + + @BuiltValueHook(finalizeBuilder: true) + static void _defaults(final HeaderBuilder b) { + b.required ??= false; + } } diff --git a/packages/dynamite/dynamite/lib/src/models/openapi/header.g.dart b/packages/dynamite/dynamite/lib/src/models/openapi/header.g.dart index f3071cbe..965aec23 100644 --- a/packages/dynamite/dynamite/lib/src/models/openapi/header.g.dart +++ b/packages/dynamite/dynamite/lib/src/models/openapi/header.g.dart @@ -16,7 +16,10 @@ class _$HeaderSerializer implements StructuredSerializer
{ @override Iterable serialize(Serializers serializers, Header object, {FullType specifiedType = FullType.unspecified}) { - final result = []; + final result = [ + 'required', + serializers.serialize(object.required, specifiedType: const FullType(bool)), + ]; Object? value; value = object.description; if (value != null) { @@ -24,12 +27,6 @@ class _$HeaderSerializer implements StructuredSerializer
{ ..add('description') ..add(serializers.serialize(value, specifiedType: const FullType(String))); } - value = object.required; - if (value != null) { - result - ..add('required') - ..add(serializers.serialize(value, specifiedType: const FullType(bool))); - } value = object.schema; if (value != null) { result @@ -54,7 +51,7 @@ class _$HeaderSerializer implements StructuredSerializer
{ result.description = serializers.deserialize(value, specifiedType: const FullType(String)) as String?; break; case 'required': - result.required = serializers.deserialize(value, specifiedType: const FullType(bool)) as bool?; + result.required = serializers.deserialize(value, specifiedType: const FullType(bool))! as bool; break; case 'schema': result.schema.replace(serializers.deserialize(value, specifiedType: const FullType(Schema))! as Schema); @@ -70,13 +67,15 @@ class _$Header extends Header { @override final String? description; @override - final bool? required; + final bool required; @override final Schema? schema; factory _$Header([void Function(HeaderBuilder)? updates]) => (HeaderBuilder()..update(updates))._build(); - _$Header._({this.description, this.required, this.schema}) : super._(); + _$Header._({this.description, required this.required, this.schema}) : super._() { + BuiltValueNullFieldError.checkNotNull(required, r'Header', 'required'); + } @override Header rebuild(void Function(HeaderBuilder) updates) => (toBuilder()..update(updates)).build(); @@ -152,9 +151,14 @@ class HeaderBuilder implements Builder { Header build() => _build(); _$Header _build() { + Header._defaults(this); _$Header _$result; try { - _$result = _$v ?? _$Header._(description: description, required: required, schema: _schema?.build()); + _$result = _$v ?? + _$Header._( + description: description, + required: BuiltValueNullFieldError.checkNotNull(required, r'Header', 'required'), + schema: _schema?.build()); } catch (_) { late String _$failedField; try { diff --git a/packages/dynamite/dynamite/lib/src/models/openapi/open_api.dart b/packages/dynamite/dynamite/lib/src/models/openapi/open_api.dart index 0f33dba2..56f9be66 100644 --- a/packages/dynamite/dynamite/lib/src/models/openapi/open_api.dart +++ b/packages/dynamite/dynamite/lib/src/models/openapi/open_api.dart @@ -21,7 +21,7 @@ abstract class OpenAPI implements Built { Info get info; - BuiltList? get servers; + BuiltList get servers; BuiltList>>? get security; @@ -33,6 +33,17 @@ abstract class OpenAPI implements Built { bool get hasAnySecurity => components?.securitySchemes?.isNotEmpty ?? false; + @BuiltValueHook(finalizeBuilder: true) + static void _defaults(final OpenAPIBuilder b) { + if (b.servers.isEmpty) { + b.servers.add( + Server( + (final b) => b.url = '/', + ), + ); + } + } + Iterable formattedTagsFor(final String? tag) sync* { final matchedTags = tags?.where((final t) => t.name == tag); diff --git a/packages/dynamite/dynamite/lib/src/models/openapi/open_api.g.dart b/packages/dynamite/dynamite/lib/src/models/openapi/open_api.g.dart index a3dcf370..55bebec4 100644 --- a/packages/dynamite/dynamite/lib/src/models/openapi/open_api.g.dart +++ b/packages/dynamite/dynamite/lib/src/models/openapi/open_api.g.dart @@ -22,14 +22,10 @@ class _$OpenAPISerializer implements StructuredSerializer { serializers.serialize(object.version, specifiedType: const FullType(String)), 'info', serializers.serialize(object.info, specifiedType: const FullType(Info)), + 'servers', + serializers.serialize(object.servers, specifiedType: const FullType(BuiltList, [FullType(Server)])), ]; Object? value; - value = object.servers; - if (value != null) { - result - ..add('servers') - ..add(serializers.serialize(value, specifiedType: const FullType(BuiltList, [FullType(Server)]))); - } value = object.security; if (value != null) { result @@ -119,7 +115,7 @@ class _$OpenAPI extends OpenAPI { @override final Info info; @override - final BuiltList? servers; + final BuiltList servers; @override final BuiltList>>? security; @override @@ -132,10 +128,17 @@ class _$OpenAPI extends OpenAPI { factory _$OpenAPI([void Function(OpenAPIBuilder)? updates]) => (OpenAPIBuilder()..update(updates))._build(); _$OpenAPI._( - {required this.version, required this.info, this.servers, this.security, this.tags, this.components, this.paths}) + {required this.version, + required this.info, + required this.servers, + this.security, + this.tags, + this.components, + this.paths}) : super._() { BuiltValueNullFieldError.checkNotNull(version, r'OpenAPI', 'version'); BuiltValueNullFieldError.checkNotNull(info, r'OpenAPI', 'info'); + BuiltValueNullFieldError.checkNotNull(servers, r'OpenAPI', 'servers'); } @override @@ -224,7 +227,7 @@ class OpenAPIBuilder implements Builder { if ($v != null) { _version = $v.version; _info = $v.info.toBuilder(); - _servers = $v.servers?.toBuilder(); + _servers = $v.servers.toBuilder(); _security = $v.security?.toBuilder(); _tags = $v.tags?.toBuilder(); _components = $v.components?.toBuilder(); @@ -249,13 +252,14 @@ class OpenAPIBuilder implements Builder { OpenAPI build() => _build(); _$OpenAPI _build() { + OpenAPI._defaults(this); _$OpenAPI _$result; try { _$result = _$v ?? _$OpenAPI._( version: BuiltValueNullFieldError.checkNotNull(version, r'OpenAPI', 'version'), info: info.build(), - servers: _servers?.build(), + servers: servers.build(), security: _security?.build(), tags: _tags?.build(), components: _components?.build(), @@ -266,7 +270,7 @@ class OpenAPIBuilder implements Builder { _$failedField = 'info'; info.build(); _$failedField = 'servers'; - _servers?.build(); + servers.build(); _$failedField = 'security'; _security?.build(); _$failedField = 'tags'; diff --git a/packages/dynamite/dynamite/lib/src/models/openapi/operation.dart b/packages/dynamite/dynamite/lib/src/models/openapi/operation.dart index bd431f39..d28f6089 100644 --- a/packages/dynamite/dynamite/lib/src/models/openapi/operation.dart +++ b/packages/dynamite/dynamite/lib/src/models/openapi/operation.dart @@ -23,7 +23,7 @@ abstract class Operation implements Built { @BuiltValueField(compare: false) String? get description; - bool? get deprecated; + bool get deprecated; BuiltList? get tags; @@ -35,6 +35,11 @@ abstract class Operation implements Built { BuiltList>>? get security; + @BuiltValueHook(finalizeBuilder: true) + static void _defaults(final OperationBuilder b) { + b.deprecated ??= false; + } + Iterable formattedDescription( final String methodName, { final bool isRawRequest = false, diff --git a/packages/dynamite/dynamite/lib/src/models/openapi/operation.g.dart b/packages/dynamite/dynamite/lib/src/models/openapi/operation.g.dart index 58ac4928..e8eb5df0 100644 --- a/packages/dynamite/dynamite/lib/src/models/openapi/operation.g.dart +++ b/packages/dynamite/dynamite/lib/src/models/openapi/operation.g.dart @@ -17,7 +17,10 @@ class _$OperationSerializer implements StructuredSerializer { @override Iterable serialize(Serializers serializers, Operation object, {FullType specifiedType = FullType.unspecified}) { - final result = []; + final result = [ + 'deprecated', + serializers.serialize(object.deprecated, specifiedType: const FullType(bool)), + ]; Object? value; value = object.operationId; if (value != null) { @@ -37,12 +40,6 @@ class _$OperationSerializer implements StructuredSerializer { ..add('description') ..add(serializers.serialize(value, specifiedType: const FullType(String))); } - value = object.deprecated; - if (value != null) { - result - ..add('deprecated') - ..add(serializers.serialize(value, specifiedType: const FullType(bool))); - } value = object.tags; if (value != null) { result @@ -104,7 +101,7 @@ class _$OperationSerializer implements StructuredSerializer { result.description = serializers.deserialize(value, specifiedType: const FullType(String)) as String?; break; case 'deprecated': - result.deprecated = serializers.deserialize(value, specifiedType: const FullType(bool)) as bool?; + result.deprecated = serializers.deserialize(value, specifiedType: const FullType(bool))! as bool; break; case 'tags': result.tags.replace(serializers.deserialize(value, @@ -146,7 +143,7 @@ class _$Operation extends Operation { @override final String? description; @override - final bool? deprecated; + final bool deprecated; @override final BuiltList? tags; @override @@ -164,13 +161,15 @@ class _$Operation extends Operation { {this.operationId, this.summary, this.description, - this.deprecated, + required this.deprecated, this.tags, this.parameters, this.requestBody, this.responses, this.security}) - : super._(); + : super._() { + BuiltValueNullFieldError.checkNotNull(deprecated, r'Operation', 'deprecated'); + } @override Operation rebuild(void Function(OperationBuilder) updates) => (toBuilder()..update(updates)).build(); @@ -295,6 +294,7 @@ class OperationBuilder implements Builder { Operation build() => _build(); _$Operation _build() { + Operation._defaults(this); _$Operation _$result; try { _$result = _$v ?? @@ -302,7 +302,7 @@ class OperationBuilder implements Builder { operationId: operationId, summary: summary, description: description, - deprecated: deprecated, + deprecated: BuiltValueNullFieldError.checkNotNull(deprecated, r'Operation', 'deprecated'), tags: _tags?.build(), parameters: _parameters?.build(), requestBody: _requestBody?.build(), diff --git a/packages/dynamite/dynamite/lib/src/models/openapi/parameter.dart b/packages/dynamite/dynamite/lib/src/models/openapi/parameter.dart index d23147f6..719c6a71 100644 --- a/packages/dynamite/dynamite/lib/src/models/openapi/parameter.dart +++ b/packages/dynamite/dynamite/lib/src/models/openapi/parameter.dart @@ -22,11 +22,16 @@ abstract class Parameter implements Built { @BuiltValueField(compare: false) String? get description; - bool? get required; + bool get required; Schema? get schema; - bool get isDartRequired => isRequired(required, schema?.$default); + @BuiltValueHook(finalizeBuilder: true) + static void _defaults(final ParameterBuilder b) { + b.required ??= false; + } + + bool get isDartRequired => isRequired(required, schema); String get formattedDescription { final name = toDartName(this.name); diff --git a/packages/dynamite/dynamite/lib/src/models/openapi/parameter.g.dart b/packages/dynamite/dynamite/lib/src/models/openapi/parameter.g.dart index 5302e334..2b1f5d40 100644 --- a/packages/dynamite/dynamite/lib/src/models/openapi/parameter.g.dart +++ b/packages/dynamite/dynamite/lib/src/models/openapi/parameter.g.dart @@ -22,6 +22,8 @@ class _$ParameterSerializer implements StructuredSerializer { serializers.serialize(object.name, specifiedType: const FullType(String)), 'in', serializers.serialize(object.$in, specifiedType: const FullType(String)), + 'required', + serializers.serialize(object.required, specifiedType: const FullType(bool)), ]; Object? value; value = object.description; @@ -30,12 +32,6 @@ class _$ParameterSerializer implements StructuredSerializer { ..add('description') ..add(serializers.serialize(value, specifiedType: const FullType(String))); } - value = object.required; - if (value != null) { - result - ..add('required') - ..add(serializers.serialize(value, specifiedType: const FullType(bool))); - } value = object.schema; if (value != null) { result @@ -66,7 +62,7 @@ class _$ParameterSerializer implements StructuredSerializer { result.description = serializers.deserialize(value, specifiedType: const FullType(String)) as String?; break; case 'required': - result.required = serializers.deserialize(value, specifiedType: const FullType(bool)) as bool?; + result.required = serializers.deserialize(value, specifiedType: const FullType(bool))! as bool; break; case 'schema': result.schema.replace(serializers.deserialize(value, specifiedType: const FullType(Schema))! as Schema); @@ -86,15 +82,17 @@ class _$Parameter extends Parameter { @override final String? description; @override - final bool? required; + final bool required; @override final Schema? schema; factory _$Parameter([void Function(ParameterBuilder)? updates]) => (ParameterBuilder()..update(updates))._build(); - _$Parameter._({required this.name, required this.$in, this.description, this.required, this.schema}) : super._() { + _$Parameter._({required this.name, required this.$in, this.description, required this.required, this.schema}) + : super._() { BuiltValueNullFieldError.checkNotNull(name, r'Parameter', 'name'); BuiltValueNullFieldError.checkNotNull($in, r'Parameter', '\$in'); + BuiltValueNullFieldError.checkNotNull(required, r'Parameter', 'required'); } @override @@ -189,6 +187,7 @@ class ParameterBuilder implements Builder { Parameter build() => _build(); _$Parameter _build() { + Parameter._defaults(this); _$Parameter _$result; try { _$result = _$v ?? @@ -196,7 +195,7 @@ class ParameterBuilder implements Builder { name: BuiltValueNullFieldError.checkNotNull(name, r'Parameter', 'name'), $in: BuiltValueNullFieldError.checkNotNull($in, r'Parameter', '\$in'), description: description, - required: required, + required: BuiltValueNullFieldError.checkNotNull(required, r'Parameter', 'required'), schema: _schema?.build()); } catch (_) { late String _$failedField; diff --git a/packages/dynamite/dynamite/lib/src/models/openapi/request_body.dart b/packages/dynamite/dynamite/lib/src/models/openapi/request_body.dart index f89d5310..9b74cf13 100644 --- a/packages/dynamite/dynamite/lib/src/models/openapi/request_body.dart +++ b/packages/dynamite/dynamite/lib/src/models/openapi/request_body.dart @@ -17,5 +17,10 @@ abstract class RequestBody implements Built { BuiltMap? get content; - bool? get required; + bool get required; + + @BuiltValueHook(finalizeBuilder: true) + static void _defaults(final RequestBodyBuilder b) { + b.required ??= false; + } } diff --git a/packages/dynamite/dynamite/lib/src/models/openapi/request_body.g.dart b/packages/dynamite/dynamite/lib/src/models/openapi/request_body.g.dart index 0d6da890..3452a7fc 100644 --- a/packages/dynamite/dynamite/lib/src/models/openapi/request_body.g.dart +++ b/packages/dynamite/dynamite/lib/src/models/openapi/request_body.g.dart @@ -17,7 +17,10 @@ class _$RequestBodySerializer implements StructuredSerializer { @override Iterable serialize(Serializers serializers, RequestBody object, {FullType specifiedType = FullType.unspecified}) { - final result = []; + final result = [ + 'required', + serializers.serialize(object.required, specifiedType: const FullType(bool)), + ]; Object? value; value = object.description; if (value != null) { @@ -32,12 +35,6 @@ class _$RequestBodySerializer implements StructuredSerializer { ..add(serializers.serialize(value, specifiedType: const FullType(BuiltMap, [FullType(String), FullType(MediaType)]))); } - value = object.required; - if (value != null) { - result - ..add('required') - ..add(serializers.serialize(value, specifiedType: const FullType(bool))); - } return result; } @@ -60,7 +57,7 @@ class _$RequestBodySerializer implements StructuredSerializer { specifiedType: const FullType(BuiltMap, [FullType(String), FullType(MediaType)]))!); break; case 'required': - result.required = serializers.deserialize(value, specifiedType: const FullType(bool)) as bool?; + result.required = serializers.deserialize(value, specifiedType: const FullType(bool))! as bool; break; } } @@ -75,12 +72,14 @@ class _$RequestBody extends RequestBody { @override final BuiltMap? content; @override - final bool? required; + final bool required; factory _$RequestBody([void Function(RequestBodyBuilder)? updates]) => (RequestBodyBuilder()..update(updates))._build(); - _$RequestBody._({this.description, this.content, this.required}) : super._(); + _$RequestBody._({this.description, this.content, required this.required}) : super._() { + BuiltValueNullFieldError.checkNotNull(required, r'RequestBody', 'required'); + } @override RequestBody rebuild(void Function(RequestBodyBuilder) updates) => (toBuilder()..update(updates)).build(); @@ -156,9 +155,14 @@ class RequestBodyBuilder implements Builder { RequestBody build() => _build(); _$RequestBody _build() { + RequestBody._defaults(this); _$RequestBody _$result; try { - _$result = _$v ?? _$RequestBody._(description: description, content: _content?.build(), required: required); + _$result = _$v ?? + _$RequestBody._( + description: description, + content: _content?.build(), + required: BuiltValueNullFieldError.checkNotNull(required, r'RequestBody', 'required')); } catch (_) { late String _$failedField; try { diff --git a/packages/dynamite/dynamite/lib/src/models/openapi/schema.dart b/packages/dynamite/dynamite/lib/src/models/openapi/schema.dart index 145e59e6..ad7732ac 100644 --- a/packages/dynamite/dynamite/lib/src/models/openapi/schema.dart +++ b/packages/dynamite/dynamite/lib/src/models/openapi/schema.dart @@ -28,7 +28,7 @@ abstract class Schema implements Built { @BuiltValueField(compare: false) String? get description; - bool? get deprecated; + bool get deprecated; String? get type; @@ -42,7 +42,7 @@ abstract class Schema implements Built { BuiltMap? get properties; - BuiltList? get required; + BuiltList get required; Schema? get items; @@ -65,4 +65,9 @@ abstract class Schema implements Built { bool get isContentString => type == 'string' && (contentMediaType?.isNotEmpty ?? false) && contentSchema != null; Iterable get formattedDescription => descriptionToDocs(description); + + @BuiltValueHook(finalizeBuilder: true) + static void _defaults(final SchemaBuilder b) { + b.deprecated ??= false; + } } diff --git a/packages/dynamite/dynamite/lib/src/models/openapi/schema.g.dart b/packages/dynamite/dynamite/lib/src/models/openapi/schema.g.dart index bc90ddda..90cee067 100644 --- a/packages/dynamite/dynamite/lib/src/models/openapi/schema.g.dart +++ b/packages/dynamite/dynamite/lib/src/models/openapi/schema.g.dart @@ -16,7 +16,12 @@ class _$SchemaSerializer implements StructuredSerializer { @override Iterable serialize(Serializers serializers, Schema object, {FullType specifiedType = FullType.unspecified}) { - final result = []; + final result = [ + 'deprecated', + serializers.serialize(object.deprecated, specifiedType: const FullType(bool)), + 'required', + serializers.serialize(object.required, specifiedType: const FullType(BuiltList, [FullType(String)])), + ]; Object? value; value = object.ref; if (value != null) { @@ -48,12 +53,6 @@ class _$SchemaSerializer implements StructuredSerializer { ..add('description') ..add(serializers.serialize(value, specifiedType: const FullType(String))); } - value = object.deprecated; - if (value != null) { - result - ..add('deprecated') - ..add(serializers.serialize(value, specifiedType: const FullType(bool))); - } value = object.type; if (value != null) { result @@ -85,12 +84,6 @@ class _$SchemaSerializer implements StructuredSerializer { ..add(serializers.serialize(value, specifiedType: const FullType(BuiltMap, [FullType(String), FullType(Schema)]))); } - value = object.required; - if (value != null) { - result - ..add('required') - ..add(serializers.serialize(value, specifiedType: const FullType(BuiltList, [FullType(String)]))); - } value = object.items; if (value != null) { result @@ -178,7 +171,7 @@ class _$SchemaSerializer implements StructuredSerializer { result.description = serializers.deserialize(value, specifiedType: const FullType(String)) as String?; break; case 'deprecated': - result.deprecated = serializers.deserialize(value, specifiedType: const FullType(bool)) as bool?; + result.deprecated = serializers.deserialize(value, specifiedType: const FullType(bool))! as bool; break; case 'type': result.type = serializers.deserialize(value, specifiedType: const FullType(String)) as String?; @@ -250,7 +243,7 @@ class _$Schema extends Schema { @override final String? description; @override - final bool? deprecated; + final bool deprecated; @override final String? type; @override @@ -262,7 +255,7 @@ class _$Schema extends Schema { @override final BuiltMap? properties; @override - final BuiltList? required; + final BuiltList required; @override final Schema? items; @override @@ -290,13 +283,13 @@ class _$Schema extends Schema { this.anyOf, this.allOf, this.description, - this.deprecated, + required this.deprecated, this.type, this.format, this.$default, this.$enum, this.properties, - this.required, + required this.required, this.items, this.additionalProperties, this.contentMediaType, @@ -306,7 +299,10 @@ class _$Schema extends Schema { this.minLength, this.maxLength, this.nullable}) - : super._(); + : super._() { + BuiltValueNullFieldError.checkNotNull(deprecated, r'Schema', 'deprecated'); + BuiltValueNullFieldError.checkNotNull(required, r'Schema', 'required'); + } @override Schema rebuild(void Function(SchemaBuilder) updates) => (toBuilder()..update(updates)).build(); @@ -498,7 +494,7 @@ class SchemaBuilder implements Builder { _$default = $v.$default; _$enum = $v.$enum?.toBuilder(); _properties = $v.properties?.toBuilder(); - _required = $v.required?.toBuilder(); + _required = $v.required.toBuilder(); _items = $v.items?.toBuilder(); _additionalProperties = $v.additionalProperties?.toBuilder(); _contentMediaType = $v.contentMediaType; @@ -528,6 +524,7 @@ class SchemaBuilder implements Builder { Schema build() => _build(); _$Schema _build() { + Schema._defaults(this); _$Schema _$result; try { _$result = _$v ?? @@ -537,13 +534,13 @@ class SchemaBuilder implements Builder { anyOf: _anyOf?.build(), allOf: _allOf?.build(), description: description, - deprecated: deprecated, + deprecated: BuiltValueNullFieldError.checkNotNull(deprecated, r'Schema', 'deprecated'), type: type, format: format, $default: $default, $enum: _$enum?.build(), properties: _properties?.build(), - required: _required?.build(), + required: required.build(), items: _items?.build(), additionalProperties: _additionalProperties?.build(), contentMediaType: contentMediaType, @@ -568,7 +565,7 @@ class SchemaBuilder implements Builder { _$failedField = 'properties'; _properties?.build(); _$failedField = 'required'; - _required?.build(); + required.build(); _$failedField = 'items'; _items?.build(); _$failedField = 'additionalProperties';