Skip to content

Commit

Permalink
fix converting additional properties of type array.
Browse files Browse the repository at this point in the history
  • Loading branch information
hpoul committed Jan 29, 2025
1 parent d357830 commit ba2864d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 64 deletions.
2 changes: 1 addition & 1 deletion packages/openapi_code_builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 1.6.0-dev.3
## 1.6.0-dev.4

* Support for restricted `additionalProperties`

Expand Down

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

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

36 changes: 22 additions & 14 deletions packages/openapi_code_builder/lib/src/openapi_code_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,11 @@ class OpenApiLibraryGenerator {
final componentName =
_componentNameFromReferenceUri(uri) ?? _classNameForComponent(key);

if (createdSchema[schemaObject] case final ref?) {
_logger.finest('Found already created for this schema reference.');
return ref;
}

final found = createdSchema.values
.firstWhereOrNull((element) => element.symbol == componentName);
if (found != null) {
Expand Down Expand Up @@ -1409,20 +1414,23 @@ class OpenApiLibraryGenerator {
APIType.integer => expression.asA(_typeInteger),
APIType.boolean => expression.asA(refer('bool')),
APIType.array => switch (schema.items) {
final itemSchema? => expression.property('map')([
Method(
(mb) => mb
..lambda = true
..requiredParameters.add(Parameter((pb) => pb..name = 'e'))
..body = _parseJson(
parentName: '${parentName}ListItem',
schema: itemSchema,
type:
_toDartType('${parentName}ListItem', itemSchema),
expression: refer('e'))
.code,
).closure
]),
final itemSchema? => expression
.asA(_referType('List', generics: [refer('dynamic')]))
.property('map')([
Method(
(mb) => mb
..lambda = true
..requiredParameters.add(Parameter((pb) => pb..name = 'e'))
..body = _parseJson(
parentName: '${parentName}ListItem',
schema: itemSchema,
type: _toDartType(
'${parentName}ListItem', itemSchema),
expression: refer('e'))
.code,
).closure
])
.property('toList')([]),
null => throw UnimplementedError(),
},
APIType.object => type.property('fromJson')([expression]),
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi_code_builder/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: openapi_code_builder
description: Generate Dtos, client and server scaffolds for openapi specs.
version: 1.6.0-dev.3
version: 1.6.0-dev.4
homepage: https://github.com/hpoul/openapi_dart/tree/master/packages/openapi_code_builder

environment:
Expand Down

0 comments on commit ba2864d

Please sign in to comment.