OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Dart] schema property of type: array and nullable: true with no default value should use null in constructor
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
openapi-generator version
commit 8511ce360c7f9166828bf71a4fd61fad107b63c1, May 7
OpenAPI declaration file content or url
openapi: 3.0.3
info:
version: "1.1"
title: Dart Nullable List
servers:
- url: 'localhost'
variables:
host:
default: localhost
components:
schemas:
ItemWithNullableArray:
type: object
properties:
nullableList:
type: array
nullable: true
items:
type: string
paths:
/items:
get:
operationId: ItemWithNullableArray
responses:
"200":
description: A list of ItemWithNullableArray
content:
application/json:
schema:
$ref: '#/components/schemas/ItemWithNullableArray'
Generation Details
The output for lists in Dart uses the default const [], but if no default value is supplied, and the property is nullable, it should probably be null instead.
class ItemWithNullableArray {
/// Returns a new [ItemWithNullableArray] instance.
ItemWithNullableArray({
this.nullableList = const [],
});
List<String>? nullableList;
}
instead it'd be nice to get this:
class ItemWithNullableArray {
/// Returns a new [ItemWithNullableArray] instance.
ItemWithNullableArray({
this.nullableList,
});
List<String>? nullableList;
}
Otherwise, until support for OAS 3.1 comes along, there's no way to make default-null containers in Dart, despite the requirements of certain API specifications.
Steps to reproduce
openapi-generator.jar generate -i spec.yaml -g dart -o nullable
Related issues/PRs
Suggest a fix
- Adjust the Mustache templates to generate
nullfor the combination ofisContainer && isNullable && !defaultValue
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the provided OpenAPI declaration with openapi-generator.jar generate -i spec.yaml -g dart -o nullable and inspect the generated constructor. Start with the Dart Mustache templates, focusing on the isContainer, isNullable, and missing-default combination. Done means a nullable array without a default generates a null constructor value rather than const [], while other list defaults remain unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 30/100