Openapi-generator: [BUG][typescript-axios] enums types are generated by field name rather by the schema when using `withoutPrefixEnums=true` option

Created on 20 Aug 2019  ·  3Comments  ·  Source: OpenAPITools/openapi-generator

Description

using typescript-axios generator and withoutPrefixEnums==true yields to enums that are getting created by the referencing entity parameter name rather the schema declared enum name.

Eventually this causes conflicts between enums that overrides one another when two entities use same parameter to reference the same enum.

openapi-generator version

Using the online version (latest) that is currently on v4.1.0 released

OpenAPI declaration file content or url

consider the following schema with two components that have a status parameter that is referencing EntityStatus enum

components:
  schemas:
    User:
      type: object
      properties:
        name:
          type: string
        status:
          $ref: '#/components/schemas/UserStatus'
      required:
        - name
    CategoryRequest:
      type: object
      properties:
        name:
          type: string
        status:
          $ref: '#/components/schemas/EntityStatus'
          default: DRAFT
      required:
        - name
    EntityStatus:
      type: string
      enum:
        - PUBLISH
        - DRAFT
        - PENDING
        - ARCHIVE
        - DELETE
    UserStatus:
      type: string
      enum:
        - ACTIVATION_REQUIRED
        - KYC_REQUIRED
        - ACTIVE
        - SUSPENDED

The desired output would be

/**
 * 
 * @export
 * @interface User
 */
export interface User{
   /**
     * 
     * @type {string}
     * @memberof User
     */
    name: string;
    /**
     * 
     * @type {string}
     * @memberof User
     */
    status?: UserStatus;
}

/**
 * 
 * @export
 * @interface CategoryRequest
 */
export interface CategoryRequest {
    /**
     * 
     * @type {string}
     * @memberof CategoryRequest
     */
    name: string;
    /**
     * 
     * @type {string}
     * @memberof CategoryRequest
     */
    status?: EntityStatus;
}

/**
    * @export
    * @enum {string}
    */
export enum UserStatus{
    PUBLISH = 'ACTIVE',
    DRAFT = 'SUSPENDED',
    PENDING = 'BLOCKED'
}

/**
    * @export
    * @enum {string}
    */
export enum EntityStatus{
    PUBLISH = 'PUBLISH',
    DRAFT = 'DRAFT',
    PENDING = 'PENDING',
    ARCHIVE = 'ARCHIVE',
    DELETE = 'DELETE'
}

yet the actual result is:

/**
 * 
 * @export
 * @interface User
 */
export interface User{
   /**
     * 
     * @type {string}
     * @memberof User
     */
    name: string;
    /**
     * 
     * @type {string}
     * @memberof User
     */
    status?: StatusEnum;
}

/**
 * 
 * @export
 * @interface CategoryRequest
 */
export interface CategoryRequest {
    /**
     * 
     * @type {string}
     * @memberof CategoryRequest
     */
    name: string;
    /**
     * 
     * @type {string}
     * @memberof CategoryRequest
     */
    status?: StatusEnum;
}
/**
    * @export
    * @enum {string}
    */
export enum StatusEnum{
    PUBLISH = 'PUBLISH',
    DRAFT = 'DRAFT',
    PENDING = 'PENDING',
    ARCHIVE = 'ARCHIVE',
    DELETE = 'DELETE'
}

/**
    * @export
    * @enum {string}
    */
export enum StatusEnum{
    ACTIVE= 'ACTIVE',
    SUSPENDED= 'SUSPENDED',
    BLOCKED= 'BLOCKED'
}
Steps to reproduce
TypeScript Bug

All 3 comments

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@mistriel would you like to implement a fix for that?

I do, it's a matter of time and availability

On Tue, Aug 20, 2019, 08:53 Esteban Gehring notifications@github.com
wrote:

@mistriel https://github.com/mistriel would you like to implement a fix
for that?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/OpenAPITools/openapi-generator/issues/3697?email_source=notifications&email_token=AAZ4UVDVYCBU4SPG3FWMWDTQFOBEFA5CNFSM4INIFV52YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4VEOUQ#issuecomment-522864466,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAZ4UVESBJ4ZRFBMAZE7TIDQFOBEFANCNFSM4INIFV5Q
.

Was this page helpful?
0 / 5 - 0 ratings