OpenAPITools / OpenAPITools/openapi-generator
[BUG][typescript-axios] enums types are generated by field name rather by the schema when using `withoutPrefixEnums=true` option
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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
- Create the above mentioned schema or alike
- call the POST API for http://api.openapi-generator.tech/api/gen/clients/typescript-axios
- set request options in the body with 'withoutPrefixEnums==true'
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 with the typescript-axios generator and reproduce the supplied schema using the withoutPrefixEnums=true option. Trace how referenced enums are named and generated; done means User.status and CategoryRequest.status refer to distinct UserStatus and EntityStatus enums without duplicate StatusEnum declarations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100