OpenAPITools / OpenAPITools/openapi-generator
[BUG] [dart-dio] The array is recognized as an object (3.1.0 - only)
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
When use $ref with file 'api.json', 'array' in spec will generate code for 'object' type,
openapi-generator version
3.1.0 - bug
3.0.3 - work fine
OpenAPI declaration file content or url
Create api.json, it reproduce only when use $ref with file.
{
"paths": {
"/testUrl": {
"post": {
"operationId": "testUrl1",
"tags": [
"test"
],
"requestBody": {
"required": true,
"description": "Input data",
"content": {
"application/json": {
"schema": {
"$ref": "api.json#/components/schemas/Type1"
}
}
}
},
"responses": {
"200": {
"description": "Updated data",
"content": {
"application/json": {
"schema": {
"$ref": "api.json#/components/schemas/Type2"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"Type1": {
"type": "object",
"properties": {
"arr3": {
"type": "array",
"items": {
"type": "string"
}
},
"arr4": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"Type2": {
"type": "object",
"properties": {
"arr1": {
"type": "array",
"items": {
"type": "string"
}
},
"arr2": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
},
"openapi": "3.1.0",
"info": {
"version": "1.0.0",
"title": "API part",
"license": {
"name": "MIT",
"identifier": "MIT"
}
},
"servers": [
{
"url": "http://localhost:8090/v1"
},
{
"url": "http://localhost:8080/v1"
}
]
}
Generation Details
CLI generates incorrect TestUrl1200Response class, when use $ref with file
@BuiltValueField(wireName: r'arr1')
BuiltList<String>? get arr1;
@BuiltValueField(wireName: r'arr2')
JsonObject? get arr2;
expected
BuiltList<String>? get arr2;
for spec:
"Type2": {
"type": "object",
"properties": {
"arr1": {
"type": "array",
"items": {
"type": "string"
}
},
"arr2": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
Steps to reproduce
- Create 'api.json'
- Run openapi-generator 3.1.0
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
Start with the api.json reproduction and run the OpenAPI Generator CLI for the Dart Dio target using the reported 3.1.0 setup; compare the generated TestUrl1200Response fields for arr1 and arr2. Check the generated output against the 3.0.3 result and the expected BuiltList type for arr2. Done means an external $ref no longer causes this array to be generated as JsonObject.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100