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 579bf8a commit 4073835
Showing 1 changed file with 26 additions and 10 deletions.
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 @@ -29,7 +29,7 @@ class SwaggerSchema {
this.readOnly = false,
this.writeOnly = 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

0 comments on commit 4073835

Please sign in to comment.