Browse Source

Merge pull request #137 from provokateurin/feature/json-encoded-string-fields-spec

dynamite: Support JSON encoded string fields as per spec
pull/138/head
Kate 2 years ago committed by GitHub
parent
commit
b6173fde19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      packages/dynamite/lib/src/models/schema.dart
  2. 12
      packages/dynamite/lib/src/models/schema.g.dart
  3. 2
      packages/dynamite/lib/src/openapi_builder.dart

10
packages/dynamite/lib/src/models/schema.dart

@ -1,4 +1,3 @@
import 'package:dynamite/src/models/media_type.dart';
import 'package:json_annotation/json_annotation.dart';
part 'schema.g.dart';
@ -20,7 +19,8 @@ class Schema {
this.required,
this.items,
this.additionalProperties,
this.content,
this.contentMediaType,
this.contentSchema,
});
factory Schema.fromJson(final Map<String, dynamic> json) => _$SchemaFromJson(json);
@ -59,7 +59,9 @@ class Schema {
final bool? additionalProperties;
final Map<String, MediaType>? content;
final String? contentMediaType;
bool get isJsonString => type == 'string' && content?['application/json']?.schema != null;
final Schema? contentSchema;
bool get isJsonString => type == 'string' && contentMediaType == 'application/json' && contentSchema != null;
}

12
packages/dynamite/lib/src/models/schema.g.dart

@ -24,7 +24,8 @@ Schema _$SchemaFromJson(Map<String, dynamic> json) {
'required',
'items',
'additionalProperties',
'content'
'contentMediaType',
'contentSchema'
],
);
return Schema(
@ -44,9 +45,9 @@ Schema _$SchemaFromJson(Map<String, dynamic> json) {
required: (json['required'] as List<dynamic>?)?.map((e) => e as String).toList(),
items: json['items'] == null ? null : Schema.fromJson(json['items'] as Map<String, dynamic>),
additionalProperties: json['additionalProperties'] as bool?,
content: (json['content'] as Map<String, dynamic>?)?.map(
(k, e) => MapEntry(k, MediaType.fromJson(e as Map<String, dynamic>)),
),
contentMediaType: json['contentMediaType'] as String?,
contentSchema:
json['contentSchema'] == null ? null : Schema.fromJson(json['contentSchema'] as Map<String, dynamic>),
);
}
@ -73,6 +74,7 @@ Map<String, dynamic> _$SchemaToJson(Schema instance) {
writeNotNull('required', instance.required);
writeNotNull('items', instance.items?.toJson());
writeNotNull('additionalProperties', instance.additionalProperties);
writeNotNull('content', instance.content?.map((k, e) => MapEntry(k, e.toJson())));
writeNotNull('contentMediaType', instance.contentMediaType);
writeNotNull('contentSchema', instance.contentSchema?.toJson());
return val;
}

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

@ -1332,7 +1332,7 @@ TypeResult resolveType(
spec,
state,
identifier,
schema.content!['application/json']!.schema!,
schema.contentSchema!,
extraJsonSerializableValues: extraJsonSerializableValues,
);
break;

Loading…
Cancel
Save