Skip to content

Commit

Permalink
If map is not required and is not explicitly nullable, default to emp…
Browse files Browse the repository at this point in the history
…ty map
  • Loading branch information
walsha2 committed Sep 12, 2024
1 parent a2ddac2 commit ee32096
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.7.24

* If map is not required and is not explicitly nullable, default to empty map

## 0.7.23

* Improved support for nullable `Map` types
Expand Down
5 changes: 5 additions & 0 deletions lib/src/generators/schema.dart
Original file line number Diff line number Diff line change
Expand Up @@ -899,8 +899,13 @@ class SchemaGenerator extends BaseGenerator {
map: (s) => s,
orElse: () => p,
);
// If map is not required and is not explicitly nullable, default to empty map
if (!required && p.nullable != true) {
p = p.copyWith(defaultValue: {}, nullable: false);
}
var (c, nullable) = propHeader(p.defaultValue, p.description);
var valueType = p.valueSchema?.toDartType(unions: _unions) ?? 'dynamic';

c += "Map<String,$valueType> ${nullable ? '?' : ''} $name,\n\n";
file.writeAsStringSync(c, mode: FileMode.append);
},
Expand Down
2 changes: 1 addition & 1 deletion lib/src/version.dart

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

2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: openapi_spec
description: OpenAPI Specification generator using native Dart code, as well as an all-in-one parser of existing specifications.
version: 0.7.23
version: 0.7.24
maintainer: Taza Technology LLC
repository: https://github.com/tazatechnology/openapi_spec
issue_tracker: https://github.com/tazatechnology/openapi_spec/issues
Expand Down

0 comments on commit ee32096

Please sign in to comment.