Skip to content

Commit

Permalink
make additionalProperties nullable.
Browse files Browse the repository at this point in the history
  • Loading branch information
hpoul committed May 12, 2024
1 parent 246f4a3 commit 77eeebc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
16 changes: 12 additions & 4 deletions packages/openapi_code_builder/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -366,14 +366,14 @@ packages:
path: "../../openapi_base"
relative: true
source: path
version: "1.1.0+3"
version: "1.3.1"
openapi_code_builder:
dependency: "direct dev"
description:
path: ".."
relative: true
source: path
version: "1.2.0"
version: "1.3.0"
package_config:
dependency: transitive
description:
Expand Down Expand Up @@ -470,6 +470,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.10.0"
sprintf:
dependency: transitive
description:
name: sprintf
sha256: "1fc9ffe69d4df602376b52949af107d8f5703b77cda567c4d7d86a0693120f23"
url: "https://pub.dev"
source: hosted
version: "7.0.0"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -546,10 +554,10 @@ packages:
dependency: transitive
description:
name: uuid
sha256: "648e103079f7c64a36dc7d39369cabb358d377078a051d6ae2ad3aa539519313"
sha256: "814e9e88f21a176ae1359149021870e87f7cddaf633ab678a5d2b0bff7fd1ba8"
url: "https://pub.dev"
source: hosted
version: "3.0.7"
version: "4.4.0"
watcher:
dependency: transitive
description:
Expand Down
19 changes: 14 additions & 5 deletions packages/openapi_code_builder/lib/src/openapi_code_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class OpenApiLibraryGenerator {
refer('OpenApiClientBase', 'package:openapi_base/openapi_base.dart');
final _hasSuccessResponse =
refer('HasSuccessResponse', 'package:openapi_base/openapi_base.dart');

// final _openApiHttpHeaders =
// refer('OpenApiHttpHeaders', 'package:openapi_base/openapi_base.dart');
final _openApiClientRequestBodyJson = refer(
Expand Down Expand Up @@ -1277,9 +1278,11 @@ class OpenApiLibraryGenerator {
..name = '_additionalProperties'
..type = _referType(
'Map',
generics: [_typeString, refer('Object')],
generics: [_typeString, _referType('Object', isNullable: true)],
)
..assignment = literalMap({}, _typeString, refer('Object')).code
..assignment = literalMap(
{}, _typeString, _referType('Object', isNullable: true))
.code
..modifier = FieldModifier.final$));
cb.methods.add(
Method((mb) => mb
Expand All @@ -1300,7 +1303,7 @@ class OpenApiLibraryGenerator {
cb.methods.add(
Method((mb) => mb
..name = 'operator[]'
..returns = refer('Object')
..returns = _referType('Object', isNullable: true)
..requiredParameters.add(Parameter((pb) => pb
..name = 'key'
..type = _typeString))
Expand Down Expand Up @@ -1584,11 +1587,16 @@ class OpenApiCodeBuilder extends Builder {
};
}

TypeReference _referType(String name,
{String? url, List<Reference>? generics}) =>
TypeReference _referType(
String name, {
String? url,
List<Reference>? generics,
bool? isNullable,
}) =>
TypeReference((trb) => trb
..symbol = name
..url = url
..isNullable = isNullable
..types.addAll(generics!));

extension on Reference {
Expand Down Expand Up @@ -1650,6 +1658,7 @@ extension DynamicExt<T> on dynamic {

extension ObjectExt<T> on T {
T? takeIf(bool Function(T that) predicate) => predicate(this) ? this : null;

R let<R>(R Function(T that) op) => op(this);
}

Expand Down

0 comments on commit 77eeebc

Please sign in to comment.