openapi-generator
openapi-generator copied to clipboard
[REQ] [typescript-axios] Use generated enums in operations
Is your feature request related to a problem? Please describe.
When using API functions generated from this, I want to be able to also use the enum types. The enums are generated for models, but they should also be generated for operations too.
Describe the solution you'd like
Generate and use enum types in operations.
Describe alternatives you've considered
Just hard-coding the enum values when using operations, but that's not great.
Additional context
e.g.
findPetsByStatus: async (status: Array<'available' | 'pending' | 'sold'>, ...
should be
findPetsByStatus: async (status: Array<FindPetsByStatusStatusEnum>, ...
...
export const FindPetsByStatusStatusEnum = {
Available: 'available',
Pending: 'pending',
Sold: 'sold'
} as const;
export type FindPetsByStatusStatusEnum = typeof FindPetsByStatusStatusEnum[keyof typeof FindPetsByStatusStatusEnum];
up
this is my .yaml
schemas:
ErrorCode:
type: string
enum:
- MISSING_PARAMETER
- MISSING_TOKEN
- INVALID_TOKEN
- ACTION_NOT_ALLOWED
- NOT_FOUND
- SERVER_ERROR
- UNEXPECTED_ERROR
I want
export enum ErrorStateEnum {
MissingParameter = 'MISSING_PARAMETER',
MissingToken = 'MISSING_TOKEN',
InvalidToken = 'INVALID_TOKEN',
ActionNotAllowed = 'ACTION_NOT_ALLOWED',
NotFound = 'NOT_FOUND',
ServerError = 'SERVER_ERROR',
UnexpectedError = 'UNEXPECTED_ERROR'
}
but now
export const ErrorCode = {
MissingParameter: 'MISSING_PARAMETER',
MissingToken: 'MISSING_TOKEN',
InvalidToken: 'INVALID_TOKEN',
ActionNotAllowed: 'ACTION_NOT_ALLOWED',
NotFound: 'NOT_FOUND',
ServerError: 'SERVER_ERROR',
UnexpectedError: 'UNEXPECTED_ERROR'
} as const;
export type ErrorCode = typeof ErrorCode[keyof typeof ErrorCode];
Is there a good solution?
bump