Browse Source

refactor(dynamite): add default values as described by openapi

Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
pull/992/head
Nikolas Rimikis 1 year ago
parent
commit
7bae1ab83d
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 2
      packages/dynamite/dynamite/lib/src/builder/client.dart
  2. 2
      packages/dynamite/dynamite/lib/src/builder/header_serializer.dart
  3. 2
      packages/dynamite/dynamite/lib/src/builder/resolve_interface.dart
  4. 4
      packages/dynamite/dynamite/lib/src/builder/resolve_mime_type.dart
  5. 10
      packages/dynamite/dynamite/lib/src/helpers/dynamite.dart
  6. 7
      packages/dynamite/dynamite/lib/src/models/openapi/header.dart
  7. 26
      packages/dynamite/dynamite/lib/src/models/openapi/header.g.dart
  8. 13
      packages/dynamite/dynamite/lib/src/models/openapi/open_api.dart
  9. 26
      packages/dynamite/dynamite/lib/src/models/openapi/open_api.g.dart
  10. 7
      packages/dynamite/dynamite/lib/src/models/openapi/operation.dart
  11. 24
      packages/dynamite/dynamite/lib/src/models/openapi/operation.g.dart
  12. 9
      packages/dynamite/dynamite/lib/src/models/openapi/parameter.dart
  13. 19
      packages/dynamite/dynamite/lib/src/models/openapi/parameter.g.dart
  14. 7
      packages/dynamite/dynamite/lib/src/models/openapi/request_body.dart
  15. 26
      packages/dynamite/dynamite/lib/src/models/openapi/request_body.g.dart
  16. 9
      packages/dynamite/dynamite/lib/src/models/openapi/schema.dart
  17. 43
      packages/dynamite/dynamite/lib/src/models/openapi/schema.g.dart

2
packages/dynamite/dynamite/lib/src/builder/client.dart

@ -234,7 +234,7 @@ Iterable<Method> buildTags(
).forEach(code.writeln); ).forEach(code.writeln);
final operationParameters = ListBuilder<Parameter>(); final operationParameters = ListBuilder<Parameter>();
final annotations = operation.deprecated ?? false ? refer('Deprecated').call([refer("''")]) : null; final annotations = operation.deprecated ? refer('Deprecated').call([refer("''")]) : null;
var returnDataType = 'void'; var returnDataType = 'void';
var returnHeadersType = 'void'; var returnHeadersType = 'void';

2
packages/dynamite/dynamite/lib/src/builder/header_serializer.dart

@ -122,7 +122,7 @@ Iterable<String> deserializeProperty(
state, state,
'${identifier}_${toDartName(propertyName, uppercaseFirstCharacter: true)}', '${identifier}_${toDartName(propertyName, uppercaseFirstCharacter: true)}',
propertySchema, propertySchema,
nullable: isDartParameterNullable(schema.required?.contains(propertyName), propertySchema), nullable: isDartParameterNullable(schema.required.contains(propertyName), propertySchema),
); );
yield "case '$propertyName':"; yield "case '$propertyName':";

2
packages/dynamite/dynamite/lib/src/builder/resolve_interface.dart

@ -34,7 +34,7 @@ TypeResultObject resolveInterface(
'${identifier}_${toDartName(propertyName, uppercaseFirstCharacter: true)}', '${identifier}_${toDartName(propertyName, uppercaseFirstCharacter: true)}',
propertySchema, propertySchema,
nullable: isDartParameterNullable( nullable: isDartParameterNullable(
schema.required?.contains(propertyName), schema.required.contains(propertyName),
propertySchema, propertySchema,
), ),
); );

4
packages/dynamite/dynamite/lib/src/builder/resolve_mime_type.dart

@ -77,7 +77,7 @@ Iterable<String> resolveMimeTypeEncode(
case 'application/x-www-form-urlencoded': case 'application/x-www-form-urlencoded':
final dartParameterRequired = isRequired( final dartParameterRequired = isRequired(
operation.requestBody!.required, operation.requestBody!.required,
mediaType.schema?.$default, mediaType.schema,
); );
b.add( b.add(
Parameter( Parameter(
@ -100,7 +100,7 @@ Iterable<String> resolveMimeTypeEncode(
case 'application/octet-stream': case 'application/octet-stream':
final dartParameterRequired = isRequired( final dartParameterRequired = isRequired(
operation.requestBody!.required, operation.requestBody!.required,
mediaType.schema?.$default, mediaType.schema,
); );
b.add( b.add(
Parameter( Parameter(

10
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'; String clientName(final String tag) => '${toDartName(tag, uppercaseFirstCharacter: true)}Client';
bool isDartParameterNullable( bool isDartParameterNullable(
final bool? required, final bool required,
final openapi.Schema? schema, final openapi.Schema? schema,
) => ) =>
(!(required ?? false) && schema?.$default == null) || (schema?.nullable ?? false); (!required && schema?.$default == null) || (schema?.nullable ?? false);
bool isRequired( bool isRequired(
final bool? required, final bool required,
final dynamic default_, final openapi.Schema? schema,
) => ) =>
(required ?? false) && default_ == null; required && schema?.$default == null;
int sortRequiredParameters(final openapi.Parameter a, final openapi.Parameter b) { int sortRequiredParameters(final openapi.Parameter a, final openapi.Parameter b) {
if (a.isDartRequired != b.isDartRequired) { if (a.isDartRequired != b.isDartRequired) {

7
packages/dynamite/dynamite/lib/src/models/openapi/header.dart

@ -14,7 +14,12 @@ abstract class Header implements Built<Header, HeaderBuilder> {
@BuiltValueField(compare: false) @BuiltValueField(compare: false)
String? get description; String? get description;
bool? get required; bool get required;
Schema? get schema; Schema? get schema;
@BuiltValueHook(finalizeBuilder: true)
static void _defaults(final HeaderBuilder b) {
b.required ??= false;
}
} }

26
packages/dynamite/dynamite/lib/src/models/openapi/header.g.dart

@ -16,7 +16,10 @@ class _$HeaderSerializer implements StructuredSerializer<Header> {
@override @override
Iterable<Object?> serialize(Serializers serializers, Header object, {FullType specifiedType = FullType.unspecified}) { Iterable<Object?> serialize(Serializers serializers, Header object, {FullType specifiedType = FullType.unspecified}) {
final result = <Object?>[]; final result = <Object?>[
'required',
serializers.serialize(object.required, specifiedType: const FullType(bool)),
];
Object? value; Object? value;
value = object.description; value = object.description;
if (value != null) { if (value != null) {
@ -24,12 +27,6 @@ class _$HeaderSerializer implements StructuredSerializer<Header> {
..add('description') ..add('description')
..add(serializers.serialize(value, specifiedType: const FullType(String))); ..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; value = object.schema;
if (value != null) { if (value != null) {
result result
@ -54,7 +51,7 @@ class _$HeaderSerializer implements StructuredSerializer<Header> {
result.description = serializers.deserialize(value, specifiedType: const FullType(String)) as String?; result.description = serializers.deserialize(value, specifiedType: const FullType(String)) as String?;
break; break;
case 'required': 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; break;
case 'schema': case 'schema':
result.schema.replace(serializers.deserialize(value, specifiedType: const FullType(Schema))! as Schema); result.schema.replace(serializers.deserialize(value, specifiedType: const FullType(Schema))! as Schema);
@ -70,13 +67,15 @@ class _$Header extends Header {
@override @override
final String? description; final String? description;
@override @override
final bool? required; final bool required;
@override @override
final Schema? schema; final Schema? schema;
factory _$Header([void Function(HeaderBuilder)? updates]) => (HeaderBuilder()..update(updates))._build(); 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 @override
Header rebuild(void Function(HeaderBuilder) updates) => (toBuilder()..update(updates)).build(); Header rebuild(void Function(HeaderBuilder) updates) => (toBuilder()..update(updates)).build();
@ -152,9 +151,14 @@ class HeaderBuilder implements Builder<Header, HeaderBuilder> {
Header build() => _build(); Header build() => _build();
_$Header _build() { _$Header _build() {
Header._defaults(this);
_$Header _$result; _$Header _$result;
try { 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 (_) { } catch (_) {
late String _$failedField; late String _$failedField;
try { try {

13
packages/dynamite/dynamite/lib/src/models/openapi/open_api.dart

@ -21,7 +21,7 @@ abstract class OpenAPI implements Built<OpenAPI, OpenAPIBuilder> {
Info get info; Info get info;
BuiltList<Server>? get servers; BuiltList<Server> get servers;
BuiltList<BuiltMap<String, BuiltList<String>>>? get security; BuiltList<BuiltMap<String, BuiltList<String>>>? get security;
@ -33,6 +33,17 @@ abstract class OpenAPI implements Built<OpenAPI, OpenAPIBuilder> {
bool get hasAnySecurity => components?.securitySchemes?.isNotEmpty ?? false; 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<String> formattedTagsFor(final String? tag) sync* { Iterable<String> formattedTagsFor(final String? tag) sync* {
final matchedTags = tags?.where((final t) => t.name == tag); final matchedTags = tags?.where((final t) => t.name == tag);

26
packages/dynamite/dynamite/lib/src/models/openapi/open_api.g.dart

@ -22,14 +22,10 @@ class _$OpenAPISerializer implements StructuredSerializer<OpenAPI> {
serializers.serialize(object.version, specifiedType: const FullType(String)), serializers.serialize(object.version, specifiedType: const FullType(String)),
'info', 'info',
serializers.serialize(object.info, specifiedType: const FullType(Info)), serializers.serialize(object.info, specifiedType: const FullType(Info)),
'servers',
serializers.serialize(object.servers, specifiedType: const FullType(BuiltList, [FullType(Server)])),
]; ];
Object? value; Object? value;
value = object.servers;
if (value != null) {
result
..add('servers')
..add(serializers.serialize(value, specifiedType: const FullType(BuiltList, [FullType(Server)])));
}
value = object.security; value = object.security;
if (value != null) { if (value != null) {
result result
@ -119,7 +115,7 @@ class _$OpenAPI extends OpenAPI {
@override @override
final Info info; final Info info;
@override @override
final BuiltList<Server>? servers; final BuiltList<Server> servers;
@override @override
final BuiltList<BuiltMap<String, BuiltList<String>>>? security; final BuiltList<BuiltMap<String, BuiltList<String>>>? security;
@override @override
@ -132,10 +128,17 @@ class _$OpenAPI extends OpenAPI {
factory _$OpenAPI([void Function(OpenAPIBuilder)? updates]) => (OpenAPIBuilder()..update(updates))._build(); factory _$OpenAPI([void Function(OpenAPIBuilder)? updates]) => (OpenAPIBuilder()..update(updates))._build();
_$OpenAPI._( _$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._() { : super._() {
BuiltValueNullFieldError.checkNotNull(version, r'OpenAPI', 'version'); BuiltValueNullFieldError.checkNotNull(version, r'OpenAPI', 'version');
BuiltValueNullFieldError.checkNotNull(info, r'OpenAPI', 'info'); BuiltValueNullFieldError.checkNotNull(info, r'OpenAPI', 'info');
BuiltValueNullFieldError.checkNotNull(servers, r'OpenAPI', 'servers');
} }
@override @override
@ -224,7 +227,7 @@ class OpenAPIBuilder implements Builder<OpenAPI, OpenAPIBuilder> {
if ($v != null) { if ($v != null) {
_version = $v.version; _version = $v.version;
_info = $v.info.toBuilder(); _info = $v.info.toBuilder();
_servers = $v.servers?.toBuilder(); _servers = $v.servers.toBuilder();
_security = $v.security?.toBuilder(); _security = $v.security?.toBuilder();
_tags = $v.tags?.toBuilder(); _tags = $v.tags?.toBuilder();
_components = $v.components?.toBuilder(); _components = $v.components?.toBuilder();
@ -249,13 +252,14 @@ class OpenAPIBuilder implements Builder<OpenAPI, OpenAPIBuilder> {
OpenAPI build() => _build(); OpenAPI build() => _build();
_$OpenAPI _build() { _$OpenAPI _build() {
OpenAPI._defaults(this);
_$OpenAPI _$result; _$OpenAPI _$result;
try { try {
_$result = _$v ?? _$result = _$v ??
_$OpenAPI._( _$OpenAPI._(
version: BuiltValueNullFieldError.checkNotNull(version, r'OpenAPI', 'version'), version: BuiltValueNullFieldError.checkNotNull(version, r'OpenAPI', 'version'),
info: info.build(), info: info.build(),
servers: _servers?.build(), servers: servers.build(),
security: _security?.build(), security: _security?.build(),
tags: _tags?.build(), tags: _tags?.build(),
components: _components?.build(), components: _components?.build(),
@ -266,7 +270,7 @@ class OpenAPIBuilder implements Builder<OpenAPI, OpenAPIBuilder> {
_$failedField = 'info'; _$failedField = 'info';
info.build(); info.build();
_$failedField = 'servers'; _$failedField = 'servers';
_servers?.build(); servers.build();
_$failedField = 'security'; _$failedField = 'security';
_security?.build(); _security?.build();
_$failedField = 'tags'; _$failedField = 'tags';

7
packages/dynamite/dynamite/lib/src/models/openapi/operation.dart

@ -23,7 +23,7 @@ abstract class Operation implements Built<Operation, OperationBuilder> {
@BuiltValueField(compare: false) @BuiltValueField(compare: false)
String? get description; String? get description;
bool? get deprecated; bool get deprecated;
BuiltList<String>? get tags; BuiltList<String>? get tags;
@ -35,6 +35,11 @@ abstract class Operation implements Built<Operation, OperationBuilder> {
BuiltList<BuiltMap<String, BuiltList<String>>>? get security; BuiltList<BuiltMap<String, BuiltList<String>>>? get security;
@BuiltValueHook(finalizeBuilder: true)
static void _defaults(final OperationBuilder b) {
b.deprecated ??= false;
}
Iterable<String> formattedDescription( Iterable<String> formattedDescription(
final String methodName, { final String methodName, {
final bool isRawRequest = false, final bool isRawRequest = false,

24
packages/dynamite/dynamite/lib/src/models/openapi/operation.g.dart

@ -17,7 +17,10 @@ class _$OperationSerializer implements StructuredSerializer<Operation> {
@override @override
Iterable<Object?> serialize(Serializers serializers, Operation object, Iterable<Object?> serialize(Serializers serializers, Operation object,
{FullType specifiedType = FullType.unspecified}) { {FullType specifiedType = FullType.unspecified}) {
final result = <Object?>[]; final result = <Object?>[
'deprecated',
serializers.serialize(object.deprecated, specifiedType: const FullType(bool)),
];
Object? value; Object? value;
value = object.operationId; value = object.operationId;
if (value != null) { if (value != null) {
@ -37,12 +40,6 @@ class _$OperationSerializer implements StructuredSerializer<Operation> {
..add('description') ..add('description')
..add(serializers.serialize(value, specifiedType: const FullType(String))); ..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; value = object.tags;
if (value != null) { if (value != null) {
result result
@ -104,7 +101,7 @@ class _$OperationSerializer implements StructuredSerializer<Operation> {
result.description = serializers.deserialize(value, specifiedType: const FullType(String)) as String?; result.description = serializers.deserialize(value, specifiedType: const FullType(String)) as String?;
break; break;
case 'deprecated': 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; break;
case 'tags': case 'tags':
result.tags.replace(serializers.deserialize(value, result.tags.replace(serializers.deserialize(value,
@ -146,7 +143,7 @@ class _$Operation extends Operation {
@override @override
final String? description; final String? description;
@override @override
final bool? deprecated; final bool deprecated;
@override @override
final BuiltList<String>? tags; final BuiltList<String>? tags;
@override @override
@ -164,13 +161,15 @@ class _$Operation extends Operation {
{this.operationId, {this.operationId,
this.summary, this.summary,
this.description, this.description,
this.deprecated, required this.deprecated,
this.tags, this.tags,
this.parameters, this.parameters,
this.requestBody, this.requestBody,
this.responses, this.responses,
this.security}) this.security})
: super._(); : super._() {
BuiltValueNullFieldError.checkNotNull(deprecated, r'Operation', 'deprecated');
}
@override @override
Operation rebuild(void Function(OperationBuilder) updates) => (toBuilder()..update(updates)).build(); Operation rebuild(void Function(OperationBuilder) updates) => (toBuilder()..update(updates)).build();
@ -295,6 +294,7 @@ class OperationBuilder implements Builder<Operation, OperationBuilder> {
Operation build() => _build(); Operation build() => _build();
_$Operation _build() { _$Operation _build() {
Operation._defaults(this);
_$Operation _$result; _$Operation _$result;
try { try {
_$result = _$v ?? _$result = _$v ??
@ -302,7 +302,7 @@ class OperationBuilder implements Builder<Operation, OperationBuilder> {
operationId: operationId, operationId: operationId,
summary: summary, summary: summary,
description: description, description: description,
deprecated: deprecated, deprecated: BuiltValueNullFieldError.checkNotNull(deprecated, r'Operation', 'deprecated'),
tags: _tags?.build(), tags: _tags?.build(),
parameters: _parameters?.build(), parameters: _parameters?.build(),
requestBody: _requestBody?.build(), requestBody: _requestBody?.build(),

9
packages/dynamite/dynamite/lib/src/models/openapi/parameter.dart

@ -22,11 +22,16 @@ abstract class Parameter implements Built<Parameter, ParameterBuilder> {
@BuiltValueField(compare: false) @BuiltValueField(compare: false)
String? get description; String? get description;
bool? get required; bool get required;
Schema? get schema; 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 { String get formattedDescription {
final name = toDartName(this.name); final name = toDartName(this.name);

19
packages/dynamite/dynamite/lib/src/models/openapi/parameter.g.dart

@ -22,6 +22,8 @@ class _$ParameterSerializer implements StructuredSerializer<Parameter> {
serializers.serialize(object.name, specifiedType: const FullType(String)), serializers.serialize(object.name, specifiedType: const FullType(String)),
'in', 'in',
serializers.serialize(object.$in, specifiedType: const FullType(String)), serializers.serialize(object.$in, specifiedType: const FullType(String)),
'required',
serializers.serialize(object.required, specifiedType: const FullType(bool)),
]; ];
Object? value; Object? value;
value = object.description; value = object.description;
@ -30,12 +32,6 @@ class _$ParameterSerializer implements StructuredSerializer<Parameter> {
..add('description') ..add('description')
..add(serializers.serialize(value, specifiedType: const FullType(String))); ..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; value = object.schema;
if (value != null) { if (value != null) {
result result
@ -66,7 +62,7 @@ class _$ParameterSerializer implements StructuredSerializer<Parameter> {
result.description = serializers.deserialize(value, specifiedType: const FullType(String)) as String?; result.description = serializers.deserialize(value, specifiedType: const FullType(String)) as String?;
break; break;
case 'required': 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; break;
case 'schema': case 'schema':
result.schema.replace(serializers.deserialize(value, specifiedType: const FullType(Schema))! as Schema); result.schema.replace(serializers.deserialize(value, specifiedType: const FullType(Schema))! as Schema);
@ -86,15 +82,17 @@ class _$Parameter extends Parameter {
@override @override
final String? description; final String? description;
@override @override
final bool? required; final bool required;
@override @override
final Schema? schema; final Schema? schema;
factory _$Parameter([void Function(ParameterBuilder)? updates]) => (ParameterBuilder()..update(updates))._build(); 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(name, r'Parameter', 'name');
BuiltValueNullFieldError.checkNotNull($in, r'Parameter', '\$in'); BuiltValueNullFieldError.checkNotNull($in, r'Parameter', '\$in');
BuiltValueNullFieldError.checkNotNull(required, r'Parameter', 'required');
} }
@override @override
@ -189,6 +187,7 @@ class ParameterBuilder implements Builder<Parameter, ParameterBuilder> {
Parameter build() => _build(); Parameter build() => _build();
_$Parameter _build() { _$Parameter _build() {
Parameter._defaults(this);
_$Parameter _$result; _$Parameter _$result;
try { try {
_$result = _$v ?? _$result = _$v ??
@ -196,7 +195,7 @@ class ParameterBuilder implements Builder<Parameter, ParameterBuilder> {
name: BuiltValueNullFieldError.checkNotNull(name, r'Parameter', 'name'), name: BuiltValueNullFieldError.checkNotNull(name, r'Parameter', 'name'),
$in: BuiltValueNullFieldError.checkNotNull($in, r'Parameter', '\$in'), $in: BuiltValueNullFieldError.checkNotNull($in, r'Parameter', '\$in'),
description: description, description: description,
required: required, required: BuiltValueNullFieldError.checkNotNull(required, r'Parameter', 'required'),
schema: _schema?.build()); schema: _schema?.build());
} catch (_) { } catch (_) {
late String _$failedField; late String _$failedField;

7
packages/dynamite/dynamite/lib/src/models/openapi/request_body.dart

@ -17,5 +17,10 @@ abstract class RequestBody implements Built<RequestBody, RequestBodyBuilder> {
BuiltMap<String, MediaType>? get content; BuiltMap<String, MediaType>? get content;
bool? get required; bool get required;
@BuiltValueHook(finalizeBuilder: true)
static void _defaults(final RequestBodyBuilder b) {
b.required ??= false;
}
} }

26
packages/dynamite/dynamite/lib/src/models/openapi/request_body.g.dart

@ -17,7 +17,10 @@ class _$RequestBodySerializer implements StructuredSerializer<RequestBody> {
@override @override
Iterable<Object?> serialize(Serializers serializers, RequestBody object, Iterable<Object?> serialize(Serializers serializers, RequestBody object,
{FullType specifiedType = FullType.unspecified}) { {FullType specifiedType = FullType.unspecified}) {
final result = <Object?>[]; final result = <Object?>[
'required',
serializers.serialize(object.required, specifiedType: const FullType(bool)),
];
Object? value; Object? value;
value = object.description; value = object.description;
if (value != null) { if (value != null) {
@ -32,12 +35,6 @@ class _$RequestBodySerializer implements StructuredSerializer<RequestBody> {
..add(serializers.serialize(value, ..add(serializers.serialize(value,
specifiedType: const FullType(BuiltMap, [FullType(String), FullType(MediaType)]))); 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; return result;
} }
@ -60,7 +57,7 @@ class _$RequestBodySerializer implements StructuredSerializer<RequestBody> {
specifiedType: const FullType(BuiltMap, [FullType(String), FullType(MediaType)]))!); specifiedType: const FullType(BuiltMap, [FullType(String), FullType(MediaType)]))!);
break; break;
case 'required': 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; break;
} }
} }
@ -75,12 +72,14 @@ class _$RequestBody extends RequestBody {
@override @override
final BuiltMap<String, MediaType>? content; final BuiltMap<String, MediaType>? content;
@override @override
final bool? required; final bool required;
factory _$RequestBody([void Function(RequestBodyBuilder)? updates]) => factory _$RequestBody([void Function(RequestBodyBuilder)? updates]) =>
(RequestBodyBuilder()..update(updates))._build(); (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 @override
RequestBody rebuild(void Function(RequestBodyBuilder) updates) => (toBuilder()..update(updates)).build(); RequestBody rebuild(void Function(RequestBodyBuilder) updates) => (toBuilder()..update(updates)).build();
@ -156,9 +155,14 @@ class RequestBodyBuilder implements Builder<RequestBody, RequestBodyBuilder> {
RequestBody build() => _build(); RequestBody build() => _build();
_$RequestBody _build() { _$RequestBody _build() {
RequestBody._defaults(this);
_$RequestBody _$result; _$RequestBody _$result;
try { 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 (_) { } catch (_) {
late String _$failedField; late String _$failedField;
try { try {

9
packages/dynamite/dynamite/lib/src/models/openapi/schema.dart

@ -28,7 +28,7 @@ abstract class Schema implements Built<Schema, SchemaBuilder> {
@BuiltValueField(compare: false) @BuiltValueField(compare: false)
String? get description; String? get description;
bool? get deprecated; bool get deprecated;
String? get type; String? get type;
@ -42,7 +42,7 @@ abstract class Schema implements Built<Schema, SchemaBuilder> {
BuiltMap<String, Schema>? get properties; BuiltMap<String, Schema>? get properties;
BuiltList<String>? get required; BuiltList<String> get required;
Schema? get items; Schema? get items;
@ -65,4 +65,9 @@ abstract class Schema implements Built<Schema, SchemaBuilder> {
bool get isContentString => type == 'string' && (contentMediaType?.isNotEmpty ?? false) && contentSchema != null; bool get isContentString => type == 'string' && (contentMediaType?.isNotEmpty ?? false) && contentSchema != null;
Iterable<String> get formattedDescription => descriptionToDocs(description); Iterable<String> get formattedDescription => descriptionToDocs(description);
@BuiltValueHook(finalizeBuilder: true)
static void _defaults(final SchemaBuilder b) {
b.deprecated ??= false;
}
} }

43
packages/dynamite/dynamite/lib/src/models/openapi/schema.g.dart

@ -16,7 +16,12 @@ class _$SchemaSerializer implements StructuredSerializer<Schema> {
@override @override
Iterable<Object?> serialize(Serializers serializers, Schema object, {FullType specifiedType = FullType.unspecified}) { Iterable<Object?> serialize(Serializers serializers, Schema object, {FullType specifiedType = FullType.unspecified}) {
final result = <Object?>[]; final result = <Object?>[
'deprecated',
serializers.serialize(object.deprecated, specifiedType: const FullType(bool)),
'required',
serializers.serialize(object.required, specifiedType: const FullType(BuiltList, [FullType(String)])),
];
Object? value; Object? value;
value = object.ref; value = object.ref;
if (value != null) { if (value != null) {
@ -48,12 +53,6 @@ class _$SchemaSerializer implements StructuredSerializer<Schema> {
..add('description') ..add('description')
..add(serializers.serialize(value, specifiedType: const FullType(String))); ..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; value = object.type;
if (value != null) { if (value != null) {
result result
@ -85,12 +84,6 @@ class _$SchemaSerializer implements StructuredSerializer<Schema> {
..add(serializers.serialize(value, ..add(serializers.serialize(value,
specifiedType: const FullType(BuiltMap, [FullType(String), FullType(Schema)]))); 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; value = object.items;
if (value != null) { if (value != null) {
result result
@ -178,7 +171,7 @@ class _$SchemaSerializer implements StructuredSerializer<Schema> {
result.description = serializers.deserialize(value, specifiedType: const FullType(String)) as String?; result.description = serializers.deserialize(value, specifiedType: const FullType(String)) as String?;
break; break;
case 'deprecated': 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; break;
case 'type': case 'type':
result.type = serializers.deserialize(value, specifiedType: const FullType(String)) as String?; result.type = serializers.deserialize(value, specifiedType: const FullType(String)) as String?;
@ -250,7 +243,7 @@ class _$Schema extends Schema {
@override @override
final String? description; final String? description;
@override @override
final bool? deprecated; final bool deprecated;
@override @override
final String? type; final String? type;
@override @override
@ -262,7 +255,7 @@ class _$Schema extends Schema {
@override @override
final BuiltMap<String, Schema>? properties; final BuiltMap<String, Schema>? properties;
@override @override
final BuiltList<String>? required; final BuiltList<String> required;
@override @override
final Schema? items; final Schema? items;
@override @override
@ -290,13 +283,13 @@ class _$Schema extends Schema {
this.anyOf, this.anyOf,
this.allOf, this.allOf,
this.description, this.description,
this.deprecated, required this.deprecated,
this.type, this.type,
this.format, this.format,
this.$default, this.$default,
this.$enum, this.$enum,
this.properties, this.properties,
this.required, required this.required,
this.items, this.items,
this.additionalProperties, this.additionalProperties,
this.contentMediaType, this.contentMediaType,
@ -306,7 +299,10 @@ class _$Schema extends Schema {
this.minLength, this.minLength,
this.maxLength, this.maxLength,
this.nullable}) this.nullable})
: super._(); : super._() {
BuiltValueNullFieldError.checkNotNull(deprecated, r'Schema', 'deprecated');
BuiltValueNullFieldError.checkNotNull(required, r'Schema', 'required');
}
@override @override
Schema rebuild(void Function(SchemaBuilder) updates) => (toBuilder()..update(updates)).build(); Schema rebuild(void Function(SchemaBuilder) updates) => (toBuilder()..update(updates)).build();
@ -498,7 +494,7 @@ class SchemaBuilder implements Builder<Schema, SchemaBuilder> {
_$default = $v.$default; _$default = $v.$default;
_$enum = $v.$enum?.toBuilder(); _$enum = $v.$enum?.toBuilder();
_properties = $v.properties?.toBuilder(); _properties = $v.properties?.toBuilder();
_required = $v.required?.toBuilder(); _required = $v.required.toBuilder();
_items = $v.items?.toBuilder(); _items = $v.items?.toBuilder();
_additionalProperties = $v.additionalProperties?.toBuilder(); _additionalProperties = $v.additionalProperties?.toBuilder();
_contentMediaType = $v.contentMediaType; _contentMediaType = $v.contentMediaType;
@ -528,6 +524,7 @@ class SchemaBuilder implements Builder<Schema, SchemaBuilder> {
Schema build() => _build(); Schema build() => _build();
_$Schema _build() { _$Schema _build() {
Schema._defaults(this);
_$Schema _$result; _$Schema _$result;
try { try {
_$result = _$v ?? _$result = _$v ??
@ -537,13 +534,13 @@ class SchemaBuilder implements Builder<Schema, SchemaBuilder> {
anyOf: _anyOf?.build(), anyOf: _anyOf?.build(),
allOf: _allOf?.build(), allOf: _allOf?.build(),
description: description, description: description,
deprecated: deprecated, deprecated: BuiltValueNullFieldError.checkNotNull(deprecated, r'Schema', 'deprecated'),
type: type, type: type,
format: format, format: format,
$default: $default, $default: $default,
$enum: _$enum?.build(), $enum: _$enum?.build(),
properties: _properties?.build(), properties: _properties?.build(),
required: _required?.build(), required: required.build(),
items: _items?.build(), items: _items?.build(),
additionalProperties: _additionalProperties?.build(), additionalProperties: _additionalProperties?.build(),
contentMediaType: contentMediaType, contentMediaType: contentMediaType,
@ -568,7 +565,7 @@ class SchemaBuilder implements Builder<Schema, SchemaBuilder> {
_$failedField = 'properties'; _$failedField = 'properties';
_properties?.build(); _properties?.build();
_$failedField = 'required'; _$failedField = 'required';
_required?.build(); required.build();
_$failedField = 'items'; _$failedField = 'items';
_items?.build(); _items?.build();
_$failedField = 'additionalProperties'; _$failedField = 'additionalProperties';

Loading…
Cancel
Save