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

[zod-openapi] generateSchema creates incorrect schema type #192

Closed
ilia373 opened this issue Mar 23, 2024 · 4 comments · Fixed by #206
Closed

[zod-openapi] generateSchema creates incorrect schema type #192

ilia373 opened this issue Mar 23, 2024 · 4 comments · Fixed by #206

Comments

@ilia373
Copy link

ilia373 commented Mar 23, 2024

generateSchema creates incorrect schema type:

according to specification type field:
image

generated schema type field as array:
image

swagger reports unknown type field:

image

used versions:

"@anatine/zod-openapi": "^2.2.0",
"zod": "^3.22.4",
"@fastify/swagger": "^8.14.0",
"@fastify/swagger-ui": "^3.0.0"

node v21.2.0

@aslansky
Copy link

Same problem here. The change was introduced in 2.2.5. Works with version 2.2.4. For example the parseObject function in zod-openapi.ts now returns type: ['object' as SchemaObjectType] before it was just type: "object". But not sure if this is the problem.

@kerolloz
Copy link

Try to use openAPI version 3.1.0

@adambrgmn
Copy link
Contributor

adambrgmn commented Apr 12, 2024

Hey, I just encountered this issue as well. Fortunately I was able to catch it. But it is a pretty significant change to introduce in a patch version bump.

At the same time I want to say that I'm otherwise very happy with these packages, and it has helped us a lot! So no shadow upon the maintainers, I know the struggle! I just want to know the reasoning behind change and what we need to do to handle it on our end, if there is anything?

I'm not really sure what @kerolloz mean with testing openAPI v3.1.0?

The code example in this repo (SwaggerModule.createDocument(app, new DocumentBuilder().build()) output a swagger schema with openapi version 3.0.0. And as far as I know there's no way to modify this or tell it to adhere to another version of the schema.

I'm happy to provide a PR with some kind of fix if it would be appreciated!

@adambrgmn
Copy link
Contributor

I see the changes were introduced in #173. And after reading thru the discussions I understand the desire from some teams to use this. But at the same time I wonder if there's anything that could be done to support multiple version maybe? Or maybe revert this for the 2.2 version line and release it in v3 (or if need be v2.3.0)?

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

Successfully merging a pull request may close this issue.

4 participants