diff --git a/lib/src/swagger_models/responses/swagger_schema.dart b/lib/src/swagger_models/responses/swagger_schema.dart index 8eb649a0..5321b8c5 100644 --- a/lib/src/swagger_models/responses/swagger_schema.dart +++ b/lib/src/swagger_models/responses/swagger_schema.dart @@ -6,7 +6,7 @@ part 'swagger_schema.g.dart'; @JsonSerializable() class SwaggerSchema { SwaggerSchema({ - this.type = '', + dynamic type = '', this.originalRef = '', this.enumValuesObj = const [], this.properties = const {}, @@ -28,7 +28,7 @@ class SwaggerSchema { this.readOnly = false, this.writeOnly = false, this.deprecated = false, - }); + }) : _type = type; @JsonKey(name: 'readOnly') bool readOnly; @@ -37,7 +37,20 @@ class SwaggerSchema { bool writeOnly; @JsonKey(name: 'type') - String type; + dynamic _type; + String get type { + if (_type is String?) return _type as String? ?? ''; + if (_type is List) { + for (final types in _type as List) { + if ((types as String?) != 'null') return types ?? ''; + } + } + return ''; + } + + set type(dynamic value) { + _type = value; + } @JsonKey(name: 'deprecated') bool deprecated; @@ -72,8 +85,8 @@ class SwaggerSchema { List get enumValues { final values = (msEnum?.values.isNotEmpty == true - ? msEnum?.values.map((e) => e.value) - : enumValuesObj) ?? + ? msEnum?.values.map((e) => e.value) + : enumValuesObj) ?? []; return values.map((e) => e.toString()).toList(); @@ -95,12 +108,15 @@ class SwaggerSchema { @JsonKey(name: 'nullable') bool? isNullable; - bool get shouldBeNullable => isNullable == true || readOnly || writeOnly; + bool get shouldBeNullable => + isNullable == true || + readOnly || + writeOnly || + (_type is List && (_type as List).contains('null')); @JsonKey(name: 'schema') SwaggerSchema? schema; - @JsonKey(name: 'oneOf') List oneOf; @JsonKey(name: 'anyOf') @@ -122,9 +138,9 @@ class SwaggerSchema { ..isNullable = (json[kIsNullable] ?? json[kNullable] ?? false) as bool; Map toJson() => { - ..._$SwaggerSchemaToJson(this), - if (enumNames != null) kEnumNames: enumNames, - }; + ..._$SwaggerSchemaToJson(this), + if (enumNames != null) kEnumNames: enumNames, + }; } bool _additionalsFromJson(dynamic value) => value != false; diff --git a/lib/src/swagger_models/responses/swagger_schema.g.dart b/lib/src/swagger_models/responses/swagger_schema.g.dart index 9ff3f5ea..44366f25 100644 --- a/lib/src/swagger_models/responses/swagger_schema.g.dart +++ b/lib/src/swagger_models/responses/swagger_schema.g.dart @@ -8,97 +8,97 @@ part of 'swagger_schema.dart'; SwaggerSchema _$SwaggerSchemaFromJson(Map json) => SwaggerSchema( - type: json['type'] as String? ?? '', - originalRef: json['originalRef'] as String? ?? '', - enumValuesObj: json['enum'] as List? ?? const [], - properties: (json['properties'] as Map?)?.map( - (k, e) => - MapEntry(k, SwaggerSchema.fromJson(e as Map)), + type: json['type'], + originalRef: json['originalRef'] as String? ?? '', + enumValuesObj: json['enum'] as List? ?? const [], + properties: (json['properties'] as Map?)?.map( + (k, e) => + MapEntry(k, SwaggerSchema.fromJson(e as Map)), ) ?? - const {}, - items: json['items'] == null - ? null - : SwaggerSchema.fromJson(json['items'] as Map), - ref: json[r'$ref'] as String? ?? '', - defaultValue: json['default'], - format: json['format'] as String? ?? '', - schema: json['schema'] == null - ? null - : SwaggerSchema.fromJson(json['schema'] as Map), - oneOf: (json['oneOf'] as List?) + const {}, + items: json['items'] == null + ? null + : SwaggerSchema.fromJson(json['items'] as Map), + ref: json[r'$ref'] as String? ?? '', + defaultValue: json['default'], + format: json['format'] as String? ?? '', + schema: json['schema'] == null + ? null + : SwaggerSchema.fromJson(json['schema'] as Map), + oneOf: (json['oneOf'] as List?) ?.map((e) => SwaggerSchema.fromJson(e as Map)) .toList() ?? - const [], - anyOf: (json['anyOf'] as List?) + const [], + anyOf: (json['anyOf'] as List?) ?.map((e) => SwaggerSchema.fromJson(e as Map)) .toList() ?? - const [], - allOf: (json['allOf'] as List?) + const [], + allOf: (json['allOf'] as List?) ?.map((e) => SwaggerSchema.fromJson(e as Map)) .toList() ?? - const [], - required: json['required'] == null - ? const [] - : _requiredFromJson(json['required']), - description: json['description'] as String? ?? '', - enumNames: (json['enumNames'] as List?) - ?.map((e) => e as String) - .toList(), - isNullable: json['nullable'] as bool?, - hasAdditionalProperties: json['additionalProperties'] == null - ? false - : _additionalsFromJson(json['additionalProperties']), - msEnum: json['x-ms-enum'] == null - ? null - : MsEnum.fromJson(json['x-ms-enum'] as Map), - title: json['title'] as String? ?? '', - readOnly: json['readOnly'] as bool? ?? false, - writeOnly: json['writeOnly'] as bool? ?? false, - deprecated: json['deprecated'] as bool? ?? false, + const [], + required: json['required'] == null + ? const [] + : _requiredFromJson(json['required']), + description: json['description'] as String? ?? '', + enumNames: (json['enumNames'] as List?) + ?.map((e) => e as String) + .toList(), + isNullable: json['nullable'] as bool?, + hasAdditionalProperties: json['additionalProperties'] == null + ? false + : _additionalsFromJson(json['additionalProperties']), + msEnum: json['x-ms-enum'] == null + ? null + : MsEnum.fromJson(json['x-ms-enum'] as Map), + title: json['title'] as String? ?? '', + readOnly: json['readOnly'] as bool? ?? false, + writeOnly: json['writeOnly'] as bool? ?? false, + deprecated: json['deprecated'] as bool? ?? false, ); Map _$SwaggerSchemaToJson(SwaggerSchema instance) => { - 'readOnly': instance.readOnly, - 'writeOnly': instance.writeOnly, - 'type': instance.type, - 'deprecated': instance.deprecated, - 'title': instance.title, - 'format': instance.format, - 'default': instance.defaultValue, - 'originalRef': instance.originalRef, - r'$ref': instance.ref, - 'description': instance.description, - 'enum': instance.enumValuesObj, - 'x-ms-enum': instance.msEnum, - 'required': instance.required, - 'items': instance.items, - 'properties': instance.properties, - 'nullable': instance.isNullable, - 'schema': instance.schema, - 'oneOf': instance.oneOf, - 'anyOf': instance.anyOf, - 'allOf': instance.allOf, - 'additionalProperties': instance.hasAdditionalProperties, - 'enumNames': instance.enumNames, + 'readOnly': instance.readOnly, + 'writeOnly': instance.writeOnly, + 'type': instance.type, + 'deprecated': instance.deprecated, + 'title': instance.title, + 'format': instance.format, + 'default': instance.defaultValue, + 'originalRef': instance.originalRef, + r'$ref': instance.ref, + 'description': instance.description, + 'enum': instance.enumValuesObj, + 'x-ms-enum': instance.msEnum, + 'required': instance.required, + 'items': instance.items, + 'properties': instance.properties, + 'nullable': instance.isNullable, + 'schema': instance.schema, + 'oneOf': instance.oneOf, + 'anyOf': instance.anyOf, + 'allOf': instance.allOf, + 'additionalProperties': instance.hasAdditionalProperties, + 'enumNames': instance.enumNames, }; MsEnum _$MsEnumFromJson(Map json) => MsEnum( values: (json['values'] as List?) - ?.map((e) => MsEnumValue.fromJson(e as Map)) - .toList() ?? + ?.map((e) => MsEnumValue.fromJson(e as Map)) + .toList() ?? const [], - ); +); Map _$MsEnumToJson(MsEnum instance) => { 'values': instance.values, - }; +}; MsEnumValue _$MsEnumValueFromJson(Map json) => MsEnumValue( value: json['value'] ?? const [], - ); +); Map _$MsEnumValueToJson(MsEnumValue instance) => { - 'value': instance.value, + 'value': instance.value, };