OpenAPITools / OpenAPITools/openapi-generator
[BUG] Example responses return undefined
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)?
-
What's the version of OpenAPI Generator used?
-
Have you search for related issues/PRs?
-
What's the actual output vs expected output?
-
[Optional] Bounty to sponsor the fix (example)
Description
There are two related issues:
- When generating code that is
nullable: true, the example response isundefined - If an optional parameter is left out of an example response, it has an
undefinedvalue.
openapi-generator version
"@openapitools/openapi-generator-cli": "^1.0.13-4.3.1",
OpenAPI declaration file content or url
components:
schemas:
Animals:
description: 'Returns cat and/or dog'
type: object
properties:
id:
type: string
format: uuid
dog:
type: string
nullable: true
cat:
type: string
nullable: true
required: ['id']
responses:
RetrievedAnimals:
description: 'Retrieved Animals'
content:
application/json:
schema:
$ref: '#/components/schemas/Animals'
example:
id: '64acc332-382e-46f3-b060-737928686f60'
dog: null
Current output:
{
id: '64acc332-382e-46f3-b060-737928686f60',
dog: undefined,
cat: undefined
}
Expected output:
{
id: '64acc332-382e-46f3-b060-737928686f60',
dog: null,
}
Suggest a fix
#isNullable does not seem to be utilized.
I suggest returning response.json(); in all instances.
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 modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache and reproduce the issue with the Animals schema in the report. Check how nullable and omitted optional properties are rendered in the example response. Done means nullable values remain null and omitted optional properties are not emitted as undefined.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100