From 77eeebc5d38557c522421bfefff4e34c76baefe2 Mon Sep 17 00:00:00 2001 From: Herbert Poul Date: Sun, 12 May 2024 15:47:46 +0200 Subject: [PATCH] make additionalProperties nullable. --- .../openapi_code_builder/example/pubspec.lock | 16 ++++++++++++---- .../lib/src/openapi_code_builder.dart | 19 ++++++++++++++----- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/packages/openapi_code_builder/example/pubspec.lock b/packages/openapi_code_builder/example/pubspec.lock index 8bb9c23..7bb9b1e 100644 --- a/packages/openapi_code_builder/example/pubspec.lock +++ b/packages/openapi_code_builder/example/pubspec.lock @@ -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: @@ -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: @@ -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: diff --git a/packages/openapi_code_builder/lib/src/openapi_code_builder.dart b/packages/openapi_code_builder/lib/src/openapi_code_builder.dart index caf1847..833dbb1 100644 --- a/packages/openapi_code_builder/lib/src/openapi_code_builder.dart +++ b/packages/openapi_code_builder/lib/src/openapi_code_builder.dart @@ -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( @@ -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 @@ -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)) @@ -1584,11 +1587,16 @@ class OpenApiCodeBuilder extends Builder { }; } -TypeReference _referType(String name, - {String? url, List? generics}) => +TypeReference _referType( + String name, { + String? url, + List? generics, + bool? isNullable, +}) => TypeReference((trb) => trb ..symbol = name ..url = url + ..isNullable = isNullable ..types.addAll(generics!)); extension on Reference { @@ -1650,6 +1658,7 @@ extension DynamicExt on dynamic { extension ObjectExt on T { T? takeIf(bool Function(T that) predicate) => predicate(this) ? this : null; + R let(R Function(T that) op) => op(this); }