Skip to content

fix: generate valid OpenAPI 3.1 documents#210

Open
mrlubos wants to merge 1 commit intorhinobase:mainfrom
mrlubos:fix/openapi-3-1
Open

fix: generate valid OpenAPI 3.1 documents#210
mrlubos wants to merge 1 commit intorhinobase:mainfrom
mrlubos:fix/openapi-3-1

Conversation

@mrlubos
Copy link

@mrlubos mrlubos commented Jan 10, 2026

@MathurAditya724 this one is WIP. I opened related pull requests in standard-community/standard-json#10 and standard-community/standard-openapi#10.

Let me explain what's going on, there are a few problems:

  1. This package can generate invalid OpenAPI specs. Since such functionality is the focus of this package, this is a big one. Absolute showstopper.
  2. Why does it generate invalid specs? Because some vendors use different JSON Schema version by default and OpenAPI 3.1 is based on 2020-12.
  3. We can configure the output version though! Well, we could configure it, if hono-openapi allowed us. It does NOT allow us to pass options to downstream vendors.
  4. I'm experiencing issues with Valibot specifically, but I wouldn't be surprised if similar issues occur with other vendors. @valibot/to-json-schema@1.5.0 added support for draft 2020-12, so in theory as long as I pass options, I should be good. But even passing options doesn't work for me. I suspect it's because my environment still uses 1.3.0, hence me trying to bump all minimum versions

Perhaps the other pull requests aren't needed since I'm able to generate correct schemas here.

Comment on lines 219 to 226
"items": [
{
"type": "string",
},
{
"type": "number",
},
],
Copy link
Author

Choose a reason for hiding this comment

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

This is incorrect

Comment on lines 238 to 242
const result = await raw.schema.toOpenAPISchema({
target: 'draft-2020-12',
});
Copy link
Author

Choose a reason for hiding this comment

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

We probably want to pass this only for Valibot since other vendors might have different options

Comment on lines +220 to +227
"prefixItems": [
{
"type": "string",
},
{
"type": "number",
},
],
Copy link
Author

Choose a reason for hiding this comment

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

Now it's correct

}
`;

exports[`arktype > with options 1`] = `
Copy link
Author

Choose a reason for hiding this comment

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

But other tests fail as a result

Comment on lines +238 to +242
const result = await raw.schema.toOpenAPISchema({
options: {
target: 'draft-2020-12',
},
});
Copy link
Author

Choose a reason for hiding this comment

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

So we want to ensure this is applied only to Valibot

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 19, 2026

Open in StackBlitz

npm i https://pkg.pr.new/rhinobase/hono-openapi@210

commit: 64cfb80

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.

1 participant