OpenAPITools / OpenAPITools/openapi-generator
[BUG] Duplicated Interface created with typescript-axios and nullable option.
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
I have 1 type of object and I want to also use it as nullable: true. But adding the nullable: true option in an object create a new model instead of reusing the current one.
openapi-generator version
@openapitools/openapi-generator-cli 2.4.18
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: test
version: local
paths:
/test:
get:
responses:
'200':
content:
application/json:
schema:
type: object
title: ParentObject
properties:
requiredChild:
type: object
title: ChildObject
properties:
name:
type: string
nullableChild:
type: object
title: ChildObject
properties:
name:
type: string
nullable: true
Generation Details
npx @openapitools/openapi-generator-cli@latest generate -i test.yaml -g typescript-axios -o ./test/
this will generate api.ts with the following model.
/**
*
* @export
* @interface ChildObject
*/
export interface ChildObject {
/**
*
* @type {string}
* @memberof ChildObject
*/
name?: string;
}
/**
*
* @export
* @interface ChildObject1
*/
export interface ChildObject1 {
/**
*
* @type {string}
* @memberof ChildObject1
*/
name?: string;
}
/**
*
* @export
* @interface ParentObject
*/
export interface ParentObject {
/**
*
* @type {ChildObject}
* @memberof ParentObject
*/
requiredChild?: ChildObject;
/**
*
* @type {ChildObject1}
* @memberof ParentObject
*/
nullableChild?: ChildObject1 | null;
}
Since the nullable field does not impact the interface of ChildObject, a new object name ChildObject1 should not be generated and both requiredChild and nullableChild should use the same interface.
Expected output:
/**
*
* @export
* @interface ChildObject
*/
export interface ChildObject {
/**
*
* @type {string}
* @memberof ChildObject
*/
name?: string;
}
/**
*
* @export
* @interface ParentObject
*/
export interface ParentObject {
/**
*
* @type {ChildObject}
* @memberof ParentObject
*/
requiredChild?: ChildObject;
/**
*
* @type {ChildObject1}
* @memberof ParentObject
*/
nullableChild?: ChildObject | 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 reported command with the inline OpenAPI declaration in test.yaml and inspect the generated api.ts from the typescript-axios generator. Trace how the requiredChild and nullableChild schemas are named and compared. Done means both properties reference ChildObject while nullableChild retains its null type, without generating ChildObject1.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100