Skip to content

Commit

Permalink
bug: fix type not being recognized when specified as array (epam-cros…
Browse files Browse the repository at this point in the history
…s-platform-lab#742)

* bug: fix type not being recognized when specified as array

* bug: fix null type in array

* bug: fix nullable type not being propagated
  • Loading branch information
juliansteenbakker authored and AnnaKandel committed Nov 3, 2024
1 parent 0e4e697 commit aacb05d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 38 deletions.
38 changes: 27 additions & 11 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,8 +28,8 @@ class SwaggerSchema {
this.title = '',
this.readOnly = false,
this.writeOnly = false,
this.deprecated = false,
});
this.deprecated = false,
}) : _type = type;

@JsonKey(name: 'readOnly')
bool readOnly;
Expand All @@ -38,7 +38,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 @@ -76,8 +89,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 @@ -99,12 +112,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 @@ -126,9 +142,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
54 changes: 27 additions & 27 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.

0 comments on commit aacb05d

Please sign in to comment.