Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: fix type not being recognized when specified as array #742

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions lib/src/swagger_models/responses/swagger_schema.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {},
Expand All @@ -28,7 +28,7 @@ class SwaggerSchema {
this.readOnly = false,
this.writeOnly = false,
this.deprecated = false,
});
}) : _type = type;

@JsonKey(name: 'readOnly')
bool readOnly;
Expand All @@ -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;
Expand Down Expand Up @@ -72,8 +85,8 @@ class SwaggerSchema {

List<String> 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();
Expand All @@ -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<SwaggerSchema> oneOf;

@JsonKey(name: 'anyOf')
Expand All @@ -122,9 +138,9 @@ class SwaggerSchema {
..isNullable = (json[kIsNullable] ?? json[kNullable] ?? false) as bool;

Map<String, dynamic> toJson() => {
..._$SwaggerSchemaToJson(this),
if (enumNames != null) kEnumNames: enumNames,
};
..._$SwaggerSchemaToJson(this),
if (enumNames != null) kEnumNames: enumNames,
};
}

bool _additionalsFromJson(dynamic value) => value != false;
Expand Down
136 changes: 68 additions & 68 deletions lib/src/swagger_models/responses/swagger_schema.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading