OpenAPITools / OpenAPITools/openapi-generator
[BUG] Duplicate enums created in Typescript generator
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?
- 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 generating the typescript client, our OpenAPI config generated from drf-spectacular is causing a duplicate enum (const) in the generated api client.
openapi-generator version
This issue was not present in 7.15 and started with 7.16.
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: The api
version: 3.76.0 (v1)
description: Documentation of API endpoints of api
paths:
/api/v1/eligibility_summary/{id}:
get:
operationId: getEligibilitySummary
description: Description of endpoint
summary: Summary of endpoint
parameters:
- in: path
name: id
schema:
type: string
required: true
security:
- jwtAuth: []
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/EligibilitySummary'
description: Very descriptive description
'404':
description: Not found
components:
schemas:
EligibilitySummary:
type: object
properties:
is_eligible:
type: boolean
exclusions:
type: object
additionalProperties:
$ref: '#/components/schemas/RuleDescriptor'
status:
nullable: true
oneOf:
- $ref: '#/components/schemas/EligibilitySummaryStatusEnum'
- $ref: '#/components/schemas/NullEnum'
required:
- exclusions
- is_eligible
- status
EligibilitySummaryStatusEnum:
enum:
- eligible
- ineligible
- conditionally_eligible
type: string
description: |-
* `eligible` - eligible
* `ineligible` - ineligible
* `conditionally_eligible` - conditionally_eligible
NullEnum:
enum:
- null
RuleDescriptor:
type: object
properties:
rule:
type: string
reason:
type: string
nullable: true
is_overrideable:
type: boolean
nullable: true
required:
- reason
- rule
securitySchemes:
jwtAuth:
type: http
scheme: bearer
bearerFormat: JWT
Abbreviated Output:
export interface EligibilitySummary {
'is_eligible': boolean;
'exclusions': { [key: string]: RuleDescriptor; };
'status': EligibilitySummaryStatusEnum | null;
}
export const EligibilitySummaryStatusEnum = {
Eligible: 'eligible',
Ineligible: 'ineligible',
ConditionallyEligible: 'conditionally_eligible'
} as const;
export type EligibilitySummaryStatusEnum = typeof EligibilitySummaryStatusEnum[keyof typeof EligibilitySummaryStatusEnum];
/**
* * `eligible` - eligible * `ineligible` - ineligible * `conditionally_eligible` - conditionally_eligible
*/
export const EligibilitySummaryStatusEnum = {
Eligible: 'eligible',
Ineligible: 'ineligible',
ConditionallyEligible: 'conditionally_eligible'
} as const;
export type EligibilitySummaryStatusEnum = typeof EligibilitySummaryStatusEnum[keyof typeof EligibilitySummaryStatusEnum];
export const NullEnum = {
} as const;
export type NullEnum = typeof NullEnum[keyof typeof NullEnum];
export interface RuleDescriptor {
'rule': string;
'reason': string | null;
'is_overrideable'?: boolean | null;
}
Generation Details
Command:
docker run --rm --workdir /github/workspace -v .:/github/workspace docker.io/openapitools/openapi-generator-cli:latest generate -g typescript-axios -o /github/workspace/typescript-axios-client -i test.yml -c config.yml --additional-properties=npmVersion="3.74.3"
Config (config.yml):
npmName: "@company/api-client"
supportsES6: true
Steps to reproduce
- Generate spec above
- Run docker cli command
- Run
yarn installin the generated directory
Suggest a fix
Rolling back to 7.15 resolves the issue
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 reproducing the duplicate enum with the provided OpenAPI spec in test.yml, config.yml, and the Docker generation command, comparing generator versions 7.15 and 7.16. Trace the TypeScript Axios generator output to identify why EligibilitySummaryStatusEnum is emitted twice. Done means the generated client contains one enum declaration and still installs successfully with yarn.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, typescript
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100