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

Openapi property with the type const resolving as z.unknown() #290

Open
zamaraevk opened this issue Apr 19, 2024 · 0 comments
Open

Openapi property with the type const resolving as z.unknown() #290

zamaraevk opened this issue Apr 19, 2024 · 0 comments

Comments

@zamaraevk
Copy link

Read before opening

  • Did you search the current list of issues ? https://github.com/astahmer/openapi-zod-client/issues
  • Is your issue related to zod or zodios ? This might be out-of-scope for us.
  • Are you using a Swagger v2 input schema ? This is not supported and should migrate to OpenAPI V3+. You can do so by using the official Swagger Editor: https://editor.swagger.io/ using the Edit -> Convert to OpenAPI 3.0 menu
  • Do you really need runtime validation ? If not, you might be interested in typed-openapi

Describe the bug
A clear and concise description of what the bug is.

I am trying to generate zod schema from openapi json file where property type as const and it's generates z.unknown()

Minimal reproduction

  • Either paste your input OpenAPI schema reduced to the relevant part here
  • OR paste a link to the online playground (hit cmd+s or click in the Actions > Save) to generate a shareable link

"components": { "schemas": { "Pet": { "type": "object", "required": ["id", "name"], "properties": { "id": { "type": "integer", "format": "int64" }, "name": { "type": "string" }, "tag": { "type": "string" }, "type": { "const": "BULLDOG", "title": "Type of dog" } } },

RESULT:

const Pet = z .object({ id: z.number().int(), name: z.string(), tag: z.string().optional(), type: z.unknown().optional() }) .passthrough();

Expected behavior
A clear and concise description of what you expected to happen. Ideally, what the generated code would look like.

Should be:

z.literal("BULLDOG").optional()

Additional context
Add any other context about the problem here.

LINK to Playground

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

No branches or pull requests

1 participant