-
Notifications
You must be signed in to change notification settings - Fork 67
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
Add support for discriminator on native enums properties #210
Add support for discriminator on native enums properties #210
Conversation
…[command] Options: -V, --version output the version number -d, --sdkDir <sdkDir> sdkDir, default: process.cwd()/service -t, --templatePath <templatePath> templatePath -t, --type <type> ts/js, default ts -c, --camelCase <camelCase> filename style, true 为大驼峰,lower 为小驼峰 -d, --sdkDir <sdkDir> sdkDir, default: process.cwd()/service -t, --templatePath <templatePath> templatePath -t, --type <type> ts/js, default ts -c, --camelCase <camelCase> filename style, true 为大驼峰,lower 为小驼峰 -h, --help output usage information Commands: url <url> swagger2/oas3 json data url data <filePath> swagger2/oas3 json data file config <cfgPath> config path *
…ject added format: date-time to for in Usage: openapi-generator [options…
removed old change I made on dates
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shaikegross thank you for this PR - left a small question in the code. Additionally:
-
In this repo we try our best to keep everything new tested - so would you be open to adding a test for that scenario - there is a
discriminated-union.spec.ts
file where we have a z.enum test that you can use as a base. -
Your build is failing - you have a typescript error.
@@ -727,6 +727,13 @@ export class OpenAPIGenerator { | |||
return; | |||
} | |||
|
|||
if (isZodType(value, 'ZodNativeEnum')) { | |||
Object.values(value._def.values).forEach((enumValue: string) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need Object.values here as opposed to the direct usage of value._def.values
above?
Currently discriminating on a field, which changes between different NativeEnum types causes model definition to be incorrect as mapping from discriminator field doesn't map to each of the enum values.
I used the same solution that existed for ZodEnum, and applied it for ZodNativeEnum