OpenAPITools / OpenAPITools/openapi-generator
[BUG] typescript-fetch since 7.4.0 ignores nullable: true
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
Hello since update to 7.4.0, nullable: true anotation is ignored and typescript generated interface doesn´t include "| null"
openapi-generator version
7.4.0
OpenAPI declaration file content or url
openapi: 3.0.1
info:
title: TEST
description: TEST
version: 1.0.0
servers:
- url: /
description: Default Server URL
paths:
/api/test:
post:
tags:
- Test
operationId: test
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/ResponseObject'
responses:
'200':
description: OK
content:
'*/*':
schema:
$ref: '#/components/schemas/ResponseObject'
components:
schemas:
ResponseObject:
type: object
properties:
code:
type: integer
nullable: true
Generation Details
I generate it using npm package: "@openapitools/openapi-generator-cli": "^2.13.1".
With command npx openapi-generator-cli generate with following configuration
{
"$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
"spaces": 4,
"generator-cli": {
"version": "7.4.0",
"useDocker": true,
"generators": {
"v3.0": {
"generatorName": "typescript-fetch",
"glob": "openapi/*.{json,yaml}",
"output": "src/openapi/#{name}",
"typeMappings": {
"Date": "string"
},
"additionalProperties": {
"prefixParameterInterfaces": true,
"useSingleRequestParameter": false,
"supportsES6": true
}
}
}
}
}
Steps to reproduce
If you generate source code from this provided yaml with 7.4.0 you will get generated output where ResponseObject.ts is defined like this:
export interface ResponseObject {
/**
*
* @type {number}
* @memberof ResponseObject
*/
code?: number;
}
but with all previouse versions it was like this
export interface ResponseObject {
/**
*
* @type {number}
* @memberof ResponseObject
*/
code?: number | null;
}
It looks like version 7.4.0 started to ignore nullable: true anotation.
Related issues/PRs
Maybe related to this issue ? #18005
Suggest a fix
Output should look like this:
export interface ResponseObject {
/**
*
* @type {number}
* @memberof ResponseObject
*/
code?: number | null;
}
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 by running the supplied OpenAPI YAML through the typescript-fetch generator at version 7.4.0 and compare the generated ResponseObject.ts with output from a previous version. Trace how nullable: true is handled during generation; done means the generated code includes number | null and the regression is covered by an appropriate generator test.
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
- Mostly clear
- Newbie friendliness
- 35/100