Skip to content

feat(standard-json-openapi): add package for Standard JSON Schema OpenAPI - #2044

Open
gusanthiago wants to merge 10 commits into
honojs:mainfrom
gusanthiago:feat/standard-json-openapi
Open

feat(standard-json-openapi): add package for Standard JSON Schema OpenAPI#2044
gusanthiago wants to merge 10 commits into
honojs:mainfrom
gusanthiago:feat/standard-json-openapi

Conversation

@gusanthiago

@gusanthiago gusanthiago commented Jul 21, 2026

Copy link
Copy Markdown

Hey everyone, this supersedes #2042 based on the review there, and should close #1763.

Summary

@hono/zod-openapi takes Zod and nothing else today. This new package, @hono/standard-json-openapi, takes schemas from any library implementing Standard JSON Schema — ArkType, Valibot once wrapped with toStandardJsonSchema(), and Zod 4, which ships it natively. A route can mix them.

import { OpenAPIHono, createRoute } from '@hono/standard-json-openapi'
import { type } from 'arktype'

const app = new OpenAPIHono()

app.openapi(
  createRoute({
    method: 'post',
    path: '/users',
    request: {
      body: {
        required: true,
        content: { 'application/json': { schema: type({ name: 'string' }) } },
      },
    },
    responses: { 200: { description: 'Created' } },
  }),
  (c) => c.json({ name: c.req.valid('json').name }, 200)
)

Solution

@asteasolutions/zod-to-openapi reads Zod internals, so a foreign schema cannot go to it directly. Non-Zod schemas are hidden inside a Zod carrier (z.string().openapi(jsonSchema)) — the generator merges .openapi() metadata over whatever it generated, so the output comes entirely from ~standard.jsonSchema. Zod schemas are never converted and behave exactly as before.

Test

pnpm test in packages/standard-json-openapi — 18 pass. They cover ArkType and mixed routes: validation, parameters, input vs output, response headers and sub-apps.

The author should do the following, if applicable

  • Add tests
  • Run tests
  • pnpm changeset at the top of this repo and push the changeset
  • Follow the contribution guide

@changeset-bot

changeset-bot Bot commented Jul 21, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 981c521

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@hono/standard-json-openapi Minor

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

@KTrain5169 KTrain5169 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please just don't try and force Zod into the package here

Comment thread packages/standard-json-openapi/README.md Outdated
Comment thread packages/standard-json-openapi/README.md Outdated
Comment thread packages/standard-json-openapi/README.md Outdated
Comment thread packages/standard-json-openapi/README.md Outdated
Comment thread packages/standard-json-openapi/README.md Outdated
Comment thread packages/standard-json-openapi/src/index.ts Outdated
@gusanthiago

Copy link
Copy Markdown
Author

Hey @KTrain5169, thanks for the review

  • I dropped Zod as a runtime dependency so we can decouple that part;
  • Simplified some logic around the module to avoid excessive implementations;
  • Adjusted other points about README.md.

Let me know if it is okay now

@gusanthiago
gusanthiago requested a review from KTrain5169 July 29, 2026 04:29

@KTrain5169 KTrain5169 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I haven't been able to take a proper look at the code myself yet as I don't really have time to experiment to the level required to have a thorough code review

Comment thread packages/standard-json-openapi/README.md Outdated
Comment thread packages/standard-json-openapi/README.md Outdated

## Limitations

- **Request header arrays are documentation only.** `request.headers` accepts an array of schemas so several can be described, but only a single schema is validated at runtime.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Any reason why this is the case?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

No reason; that was gap — the array never reached a validator, so nothing was validated. Now each schema validates. Only the typing stays limited, since Hono has a single header target. Adjusted the Limitation and added a test.

Comment thread packages/standard-json-openapi/CHANGELOG.md Outdated
Comment thread packages/standard-json-openapi/package.json Outdated
Comment on lines +6 to +8
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.cts",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@yusukebe Should middlewares be published as ESM-only?

Comment thread packages/standard-json-openapi/package.json
Comment thread .changeset/standard-json-openapi.md Outdated
…penapi

* Added missing schema libraries sample like zod mini / zod 4 / arktype / validbot
* Fixed gap of validate('header', route.request?,headers)
* Added valibot + valibot/to-json-schema in devDeps
@gusanthiago
gusanthiago requested a review from KTrain5169 August 2, 2026 04:01
@gusanthiago

gusanthiago commented Aug 6, 2026

Copy link
Copy Markdown
Author

@KTrain5169

I did adjustments mentioned in the PR. Let me know if I need to work on anything more.

Thanks for the review

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.

Standard (json) schema support for @hono/(zod-)openapi

2 participants