Bring back support for Open API v3.0 #206
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey and thank you for a very nice project! It helps us a lot.
As mentioned in issue #192 version 2.2.4 of
@anatine/zod-openapi
introduced support for OpenAPI v3.1. But by doing so it also dropped support for v3.0 it seems.I should mention that I am not an expert in the OpenAPI spec, so I can't tell what broke other than that 3.0 only supports
type
as a string union, not an array,which seems to be supported in 3.1 and implemented in this package.
I've seen the discussions around supporting 3.1 and acknowledge that it is needed. But the fact is that this change broke the integration with NestJS's swagger
implementation which is still emitting 3.0 schemas. And this was introduced as a patch release, and not a major.
My proposal is to support both of the specs together by introducing a new paramater to
generateSchema
–openApiVersion
which can be either'3.0' | '3.1'
.To not break anyone already relying on the 3.1 support of
generateSchema
I decided to set the default to 3.1.But for
patchNestSwagger
I decided to set the default to 3.0 as to not break support for NestJS's swagger module.Please let me know what you think about this change and if you see another solution that might be better suited. Also let me know if you want me to add more tests
to validate the 3.0 behaviour.
Fixes #192