feat(zod-openapi): add doc32() and getOpenAPI32Document() for OpenAPI 3.2 - #2136
Open
mqmalagris wants to merge 1 commit into
Open
mqmalagris wants to merge 1 commit into
mqmalagris wants to merge 1 commit into
Conversation
… 3.2 The engine bump already landed: the package pins @asteasolutions/zod-to-openapi ^9.1.0, which exports OpenApiGeneratorV32, and openapi3-ts 4.6.0 ships the oas32 types. So 3.2 only needed wiring. Add getOpenAPI32Document() and doc32() alongside the existing 3.0 and 3.1 pairs, backed by OpenApiGeneratorV32 and typed with openapi3-ts/oas32. Base path handling and generator options behave as they do for 3.1. This makes the 3.2 tag hierarchy (parent, summary, kind) usable, which is what replaces the x-tagGroups extension for sidebar grouping. doc32 mirrors doc31, so it carries the same two `any` boundaries; the eslint suppression counts for index.ts are bumped by one each to match. Closes honojs#2039
🦋 Changeset detectedLatest commit: 3208405 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The author should do the following, if applicable
pnpm changesetat the top of this repo and push the changesetCloses #2039
Problem
@hono/zod-openapican emit OpenAPI 3.0 and 3.1 documents, but not 3.2. That leaves the 3.2 tag hierarchy out of reach —parent,summaryandkindon the Tag Object — which is what replaces thex-tagGroupsextension for sidebar grouping in docs renderers.Root cause
Nothing was blocking it any more, which is the useful part of this one. The issue was filed when the package still pinned
@asteasolutions/zod-to-openapi@^8.5.0, and asked for an engine bump. That bump has since landed, so both pieces are already installed and simply unused:@asteasolutions/zod-to-openapi@^9.1.0is a current dependency and exportsOpenApiGeneratorV32alongsideOpenApiGeneratorV3/OpenApiGeneratorV31.openapi3-ts@4.6.0already ships anoas32entrypoint next tooas30/oas31.Only the wiring in
packages/zod-openapi/src/index.tswas missing.Fix
Mirrors the existing 3.0 and 3.1 pairs exactly, no new patterns:
getOpenAPI32Document(objectConfig, generatorConfig?), backed byOpenApiGeneratorV32and returningOpenAPIObjectfromopenapi3-ts/oas32. AppliesaddBasePathToDocumentthe same way its siblings do.doc32(path, configureObject, configureGenerator?), serving that document on a route.Base path handling under
.route()and the optional generator options behave as they do for 3.1.Test
5 tests in a new
OpenAPI 3.2block inpackages/zod-openapi/src/index.test.ts:getOpenAPI32Document()emitsopenapi: '3.2.0'and the registered paths.doc32()serves that document over HTTP with status 200.parent/summary/kind) survive into the document./apiyields/api/books.doc32()(checked viaunionPreferredType: 'anyOf', matching the existingdoc31generator-options test).To run:
pnpm testinpackages/zod-openapi. Result:vitest run150/150 passing withType Errors no errors,tsc -b tsconfig.jsonclean,eslintback to its baseline of 0 errors. All 5 fail against the unpatchedindex.tswithgetOpenAPI32Document is not a function/doc32 is not a function.One decision to flag
doc32mirrorsdoc31line for line, which means it carries the same twoanyboundaries:catch (e: any)and theas anyon the returned builder. Those add one@typescript-eslint/no-unsafe-argumentand oneno-unsafe-return, which pushedsrc/index.tspast its counts ineslint-suppressions.json— at which point lint reports every occurrence of those two rules in the file, not just the new ones.I bumped the two counts by one each via
eslint --suppress-rule(14 → 15 and 5 → 6, a 3-line diff) rather than writedoc32differently from its siblings. Sinceautofix.ymlonly runs--prune-suppressionsand never adds, updating the counts in the PR looked like the intended path. Say the word if you would ratherdoc32avoid theanyboundaries and leaveeslint-suppressions.jsonuntouched — happy to switch it either way.