Compile error with default value for string enum
Describe the bug I have the following string enum schema for a query parameter with a default value:
OrderByDirection:
description: The sort order for query results.
type: string
enum: [asc, desc]
default: desc
The generated client doesn't compile because you can't assign a string literal to an enum:
TSError: ⨯ Unable to compile TypeScript:
../shared/src/ApiClient/services/V1Service.ts:24:9 - error TS2322: Type '"desc"' is not assignable to type 'OrderByDirection'.
24 orderByDirection: OrderByDirection = 'desc',
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I'm also running into this issue. The simplest fix from the codegen side might be to wrap the enum in a template literal, e.g.
orderByDirection: `${OrderByDirection}` = 'desc',
If this is feasible I'm happy to do a PR. In the meantime, I've been using the --useUnionTypes to not generate enums at all.
Hi @nerdyman, this package isn't maintained at the moment so a pull request is unlikely to be merged I'm afraid
No worries, thanks for the quick reply @mrlubos