Skip to content

feat: add OpenApiGeneratorV32 for OpenAPI 3.2#388

Merged
AGalabov merged 3 commits into
asteasolutions:masterfrom
bookernath:feat/oas-3.2
Jul 14, 2026
Merged

feat: add OpenApiGeneratorV32 for OpenAPI 3.2#388
AGalabov merged 3 commits into
asteasolutions:masterfrom
bookernath:feat/oas-3.2

Conversation

@bookernath

@bookernath bookernath commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Resolves #385.

Adds OpenApiGeneratorV32 for generating OpenAPI 3.2.x documents, following the subclass approach (option a) that @AGalabov agreed with on the issue.

Approach

OpenAPI 3.2 keeps the 3.1 JSON Schema dialect (2020-12), so schema generation is identical to 3.1. Rather than duplicate that logic, the new generator reuses OpenApiGeneratorV31Specifics and only layers on the document-structure fields introduced in 3.2:

  • itemSchema on a media type — describes each item of a sequential stream (text/event-stream, application/jsonl, application/json-seq, …). A Zod schema is converted and registered exactly like schema (so it $refs a component); a raw SchemaObject/ReferenceObject is passed through.
  • itemEncoding / prefixEncoding on media types
  • Reusable media types via components.mediaTypes, with media type $refs passed through from content
  • summary and an optional description on responses
  • the query HTTP method on routes

Dependency

Requires the oas32 module from openapi3-ts, added in metadevpro/openapi3-ts#158 and published in 4.6.0. The dependency range is bumped ^4.1.2^4.6.0 accordingly, and the lockfile is synced so npm ci stays green in CI.

Notes

  • The lazy transformer needed a cast because openapi3-ts >= 4.2 added an optional $ref to SchemaObject, so 'in' no longer narrows the union.
  • Webhook generation runs before final component assembly so webhook-only named schemas and itemSchemas resolve correctly.

Tests

  • New spec/v3.2.spec.ts covering the 3.2-specific behavior, reusable media type refs, webhook-only item schemas, and encoding pass-through
  • Full suite green locally: build, tests, type tests (tsd), and prettier

3.2 keeps the 3.1 JSON Schema dialect (2020-12), so OpenApiGeneratorV32
reuses the 3.1 specifics and only adds the new document-structure fields:

- itemSchema on media types (text/event-stream, application/jsonl, ...),
  converted and registered like schema when given a Zod type
- itemEncoding / prefixEncoding on media types
- optional response description + summary
- query HTTP method on routes

Requires openapi3-ts with the oas32 module (metadevpro/openapi3-ts#158).

The lazy transformer cast is needed because openapi3-ts >= 4.2 added an
optional $ref to SchemaObject, so 'in' no longer narrows the union.
Comment thread src/v3.2/openapi-generator.ts Outdated
Comment thread spec/v3.2/media-types.spec.ts
Comment thread src/openapi-generator.ts Outdated
Comment thread src/openapi-generator.ts Outdated
Comment thread src/openapi-generator.ts Outdated
Comment thread src/openapi-registry.ts Outdated
Comment thread src/openapi-registry.ts Outdated

@AGalabov AGalabov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some more casts that I do not like. Otherwise it is getting closer to what I envision

Comment thread src/v3.0/openapi-generator.ts Outdated
Comment thread src/v3.0/openapi-generator.ts Outdated
Comment thread src/openapi-generator.ts
@bookernath

Copy link
Copy Markdown
Contributor Author

Agreed that the casts in the v3.0 and v3.1 generators weren’t necessary, removed those. I also narrowed the remaining component casts to only the raw user-provided schema and parameter buckets while keeping generated values type-checked.

@AGalabov
AGalabov merged commit d2ac6bd into asteasolutions:master Jul 14, 2026
3 checks passed
@AGalabov

Copy link
Copy Markdown
Member

@bookernath thank you for this contribution! 🚀

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 this pull request may close these issues.

Proposal: OpenAPI 3.2 support — OpenApiGeneratorV32 subclass vs. a version option?

2 participants