Skip to content

Commit

Permalink
fix: read nullable property from anyOf types
Browse files Browse the repository at this point in the history
  • Loading branch information
MohiuddinM committed Sep 25, 2024
1 parent 3a5b3f3 commit 078fea1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion swagger_parser/lib/src/parser/parser/open_api_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,15 @@ class OpenApiParser {
final propertyValue = props[propertyName] as Map<String, dynamic>;
final nullablePropertyValue =
propertyValue[_nullableConst].toString().toBool();
final isNullable = nullablePropertyValue ?? false;

var isNullable = nullablePropertyValue ?? false;
if (!isNullable) {
if (propertyValue case {_anyOfConst: final List<dynamic> anyOf}) {
isNullable = anyOf.any(
(e) => e is Map<String, dynamic> && e['type'] == 'null',
);
}
}

final isRequired = requiredParameters.contains(propertyName);
final typeWithImport = _findType(
Expand Down

0 comments on commit 078fea1

Please sign in to comment.