Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REQ] [typescript-axios] Use generated enums in operations #13439

Open
chaayac opened this issue Sep 16, 2022 · 3 comments · Fixed by #13438
Open

[REQ] [typescript-axios] Use generated enums in operations #13439

chaayac opened this issue Sep 16, 2022 · 3 comments · Fixed by #13438

Comments

@chaayac
Copy link
Contributor

chaayac commented Sep 16, 2022

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];
@chaayac chaayac changed the title [REQ] Use generated enums in operations for typescript-axios [REQ] [typescript-axios] Use generated enums in operations Sep 16, 2022
@galihputera
Copy link

up

@ganbowengo
Copy link

ganbowengo commented Sep 21, 2022

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?

@Tohusk
Copy link

Tohusk commented Sep 26, 2022

bump

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants