We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Double arrays will generate with invalid defaults in the event of null values encountered during deserialization
This will generate the following invalid deserializer:
class WithNonNullableArray { /// Returns a new [WithNonNullableArray] instance. WithNonNullableArray({ this.subarray = const [], }); /* omitted */ List<List<int>> subarray; static WithNonNullableArray? fromJson(dynamic value) { if (value is Map) { final json = value.cast<String, dynamic>(); /* omitted */ return WithNonNullableArray( subarray: json[r'subarray'] is List ? (json[r'subarray'] as List).map( (e) => e == null ? null : (e as List).cast<int>() ).toList() : null, ); } return null; } }
Null isn't valid here, and so becomes a syntax error. The proper typing of the defaults for this example should be <int>[]
<int>[]
Latest commit as of 9/18/22 (863dbc7)
openapi: 3.0.3 info: version: "1.1" title: Dart Uint8list Demo servers: - url: "localhost" variables: host: default: localhost paths: /item: get: operationId: GetItem description: "Should return an Item" responses: "200": description: items content: application/json: schema: $ref: "#components/schemas/WithNonNullableArray" components: schemas: WithNonNullableArray: type: object required: [subarray] properties: subarray: type: array minItems: 12 maxItems: 12 items: $ref: "#/components/schemas/SubArray" WithNullableArray: type: object required: [subarray] properties: months: type: array nullable: true items: $ref: "#/components/schemas/SubArray" SubArray: type: array items: type: integer format: int32
Changing the native_class.mustache file to include
native_class.mustache
(e) => e == null ? {{#required}}{{#isNullable}}null{{/isNullable}}{{^isNullable}}const <{{items.items.dataType}}>[]{{/isNullable}}{{/required}}{{^required}}null{{/required}}
Changes the output to be more appropriate:
return WithNonNullableArray( subarray: json[r'subarray'] is List ? (json[r'subarray'] as List).map( (e) => e == null ? const <int>[] : (e as List).cast<int>() ).toList() : const <int>[], );
The text was updated successfully, but these errors were encountered:
[Dart] Added non-invalid defaults for non nullable array of arrays (O…
bb37004
…penAPITools#13460)
[Dart] Fix array of array nullable and non-nullable value generation (#…
341a853
…13461) * [Dart] Added non-invalid defaults for non nullable array of arrays (#13460) * [Dart] Update samples
Successfully merging a pull request may close this issue.
Bug Report Checklist
Description
Double arrays will generate with invalid defaults in the event of null values encountered during deserialization
This will generate the following invalid deserializer:
Null isn't valid here, and so becomes a syntax error. The proper typing of the defaults for this example should be
<int>[]
openapi-generator version
Latest commit as of 9/18/22 (863dbc7)
OpenAPI declaration file content or url
Specfile
Suggest a fix
Changing the
native_class.mustache
file to includeChanges the output to be more appropriate:
The text was updated successfully, but these errors were encountered: