Skip to content

Commit ee32096

Browse files
committed
If map is not required and is not explicitly nullable, default to empty map
1 parent a2ddac2 commit ee32096

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 0.7.24
4+
5+
* If map is not required and is not explicitly nullable, default to empty map
6+
37
## 0.7.23
48

59
* Improved support for nullable `Map` types

lib/src/generators/schema.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,8 +899,13 @@ class SchemaGenerator extends BaseGenerator {
899899
map: (s) => s,
900900
orElse: () => p,
901901
);
902+
// If map is not required and is not explicitly nullable, default to empty map
903+
if (!required && p.nullable != true) {
904+
p = p.copyWith(defaultValue: {}, nullable: false);
905+
}
902906
var (c, nullable) = propHeader(p.defaultValue, p.description);
903907
var valueType = p.valueSchema?.toDartType(unions: _unions) ?? 'dynamic';
908+
904909
c += "Map<String,$valueType> ${nullable ? '?' : ''} $name,\n\n";
905910
file.writeAsStringSync(c, mode: FileMode.append);
906911
},

lib/src/version.dart

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: openapi_spec
22
description: OpenAPI Specification generator using native Dart code, as well as an all-in-one parser of existing specifications.
3-
version: 0.7.23
3+
version: 0.7.24
44
maintainer: Taza Technology LLC
55
repository: https://github.com/tazatechnology/openapi_spec
66
issue_tracker: https://github.com/tazatechnology/openapi_spec/issues

0 commit comments

Comments
 (0)