Bug Report Checklist
Description
When an OpenAPI 3.1 schema marks an inline object property as nullable via the array-form type: ["object", "null"], the dart-dio generator produces a non-nullable Dart field. The same null intent in other shapes is handled correctly:
| Source schema |
Generated Dart field |
type: ["object", "null"] on top-level / type-less data |
final Object? data; ✅ |
nullable: true (OAS 3.0) |
final SomeType? data; ✅ |
allOf: [$ref: ...] + nullable: true (OAS 3.0 idiom) |
final SomeType? data; ✅ |
type: ["object", "null"] on inline object with properties: |
final InlineType data; ❌ |
The last row is the bug. When the server actually returns data: null (which the spec explicitly allows), dio fails to deserialize and throws a DioException, which downstream callers misinterpret as a business error.
openapi-generator version
7.22.0 (via the Dart openapi_generator package).
OpenAPI declaration file content or url
Minimal repro:
openapi: 3.1.0
info:
title: Repro
version: "1.0"
paths:
/login:
post:
operationId: login
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/EnvelopeNullableLoginResponse"
components:
schemas:
EnvelopeNullableLoginResponse:
type: object
required: [code, data, message]
properties:
code:
type: integer
data:
# this is the field that triggers the bug
type:
- object
- "null"
description: Business data; null on failure
required:
- token
properties:
token:
type: string
message:
type: string
Generation Details
openapi-generator-cli generate -i spec.yaml -g dart-dio -o out --skip-validate-spec
No custom additionalProperties needed to reproduce. serializationLibrary set to either json_serializable or the default built_value shows the same Dart field type.
Steps to reproduce
-
Save the spec above as spec.yaml.
-
Run the generation command.
-
Open out/lib/src/model/envelope_nullable_login_response.dart.
-
Observe the data field:
@JsonKey(name: r'data', required: true, includeIfNull: true)
final EnvelopeNullableLoginResponseData data; // expected: ...Data? data
-
The synthesized inline class is generated correctly on its own — the bug is only that the outer field's type isn't suffixed with ?.
Related issues/PRs
Suggest a fix
Best guess from reading the related issues: when the dart-dio templates compute the field type for an object whose schema has an inline type: [..., "null"] array form, the isNullable flag is not making it through to the place that emits the ? suffix. The detection of the synthesized inline class itself does work (the model file is generated), so the gap is between schema-level nullability detected and field-level accessor type rendered.
Bug Report Checklist
Description
When an OpenAPI 3.1 schema marks an inline object property as nullable via the array-form
type: ["object", "null"], thedart-diogenerator produces a non-nullable Dart field. The same null intent in other shapes is handled correctly:type: ["object", "null"]on top-level / type-lessdatafinal Object? data;✅nullable: true(OAS 3.0)final SomeType? data;✅allOf: [$ref: ...]+nullable: true(OAS 3.0 idiom)final SomeType? data;✅type: ["object", "null"]on inline object withproperties:final InlineType data;❌The last row is the bug. When the server actually returns
data: null(which the spec explicitly allows),diofails to deserialize and throws aDioException, which downstream callers misinterpret as a business error.openapi-generator version
7.22.0 (via the Dart
openapi_generatorpackage).OpenAPI declaration file content or url
Minimal repro:
Generation Details
No custom
additionalPropertiesneeded to reproduce.serializationLibraryset to eitherjson_serializableor the defaultbuilt_valueshows the same Dart field type.Steps to reproduce
Save the spec above as
spec.yaml.Run the generation command.
Open
out/lib/src/model/envelope_nullable_login_response.dart.Observe the
datafield:The synthesized inline class is generated correctly on its own — the bug is only that the outer field's type isn't suffixed with
?.Related issues/PRs
$refsiblings, not array-formtype). Both reduce to: dart-dio doesn't propagateisNullableto the field accessor in every code path.nullable: true+requiredanalog of this issue. The fix likely needs to cover both shapes.type: [string, "null"], suggestingisNullablepropagation has language-agnostic gaps for OAS 3.1 array-form null.Suggest a fix
Best guess from reading the related issues: when the dart-dio templates compute the field type for an object whose schema has an inline
type: [..., "null"]array form, theisNullableflag is not making it through to the place that emits the?suffix. The detection of the synthesized inline class itself does work (the model file is generated), so the gap is between schema-level nullability detected and field-level accessor type rendered.