Skip to content

[BUG] Duplicate enums created in Typescript generator #22057

@chrishoffman

Description

@chrishoffman

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 install in the generated directory
Suggest a fix

Rolling back to 7.15 resolves the issue

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions