anatine / zod-plugins

Plugins and utilities for Zod
591 stars 84 forks source link

Bring back support for Open API v3.0 #206

Closed adambrgmn closed 2 weeks ago

adambrgmn commented 1 month ago

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 generateSchemaopenApiVersion 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

nx-cloud[bot] commented 1 month ago

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 65fc3d351b9128010733a644d4a141f100e44b35. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 2 targets - [`nx affected:test --base=origin/main --codeCoverage`](https://cloud.nx.app/runs/9xnJXBSE0B?utm_source=pull-request&utm_medium=comment) - [`nx affected:lint --base=origin/main`](https://cloud.nx.app/runs/EiesgjrzV7?utm_source=pull-request&utm_medium=comment)

Sent with 💌 from NxCloud.

RobbyUitbeijerse commented 2 weeks ago

Hey there! We would love this PR to be merged. We're in the middle of migrating from the recently archived nestjs-zod to @anatine/zod-nestjs and @anatine/zod-openapi. The migration was simple and smooth - but due to certain tools and generators not supporting 3.1.0 yet, we're stuck with wrapping it up. We would love those tools to support it, but supporting 3.0 in anatine packages seems more reasonable.