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

Add support for discriminator on native enums properties #210

7 changes: 7 additions & 0 deletions src/openapi-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,13 @@
return;
}

if (isZodType(value, 'ZodNativeEnum')) {
Object.values(value._def.values).forEach((enumValue: string) => {

Check failure on line 731 in src/openapi-generator.ts

View workflow job for this annotation

GitHub Actions / build-and-test (14.x)

Argument of type '(enumValue: string) => void' is not assignable to parameter of type '(value: unknown, index: number, array: unknown[]) => void'.

Check failure on line 731 in src/openapi-generator.ts

View workflow job for this annotation

GitHub Actions / build-and-test (16.x)

Argument of type '(enumValue: string) => void' is not assignable to parameter of type '(value: unknown, index: number, array: unknown[]) => void'.

Check failure on line 731 in src/openapi-generator.ts

View workflow job for this annotation

GitHub Actions / build-and-test (18.x)

Argument of type '(enumValue: string) => void' is not assignable to parameter of type '(value: unknown, index: number, array: unknown[]) => void'.
Copy link
Collaborator

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?

mapping[enumValue] = this.generateSchemaRef(refId);
});
return;
}

const literalValue = value?._def.value;

// This should never happen because Zod checks the disciminator type but to keep the types happy
Expand Down
Loading