Skip to content

Conversation

@MathurAditya724
Copy link
Member

@MathurAditya724 MathurAditya724 commented Jun 29, 2025

Resolves #130, Resolves #125, Resolves #122, Resolves #116, Resolves #115, Resolves #114, Resolves #99, Resolves #97, Resolves #86, Resolves #82, Resolves #81, Resolves #78, Resolves #76, Resolves #67, Resolves #65, Resolves #61

  • Removed NX and made the package structure simpler
  • Support for Standard Schema
  • Add zod 4 Support
  • New response middleware for getting types in the handler
  • Optimisations

@MathurAditya724 MathurAditya724 self-assigned this Jun 29, 2025
@rawnly
Copy link

rawnly commented Jul 6, 2025

Hey any plan to release an RC or Beta for this?

@MathurAditya724
Copy link
Member Author

Yeah, will release an RC today

@vnphanquang
Copy link

Would love if the RC can include #127 as well. Thanks a lot!

@vladshcherbin
Copy link

I'd also love to test the RC version

@mstibbard
Copy link

Also keen :)

@MathurAditya724
Copy link
Member Author

Sorry for the delay guys, just got busy. I will try to release a RC today for sure.

@rawnly
Copy link

rawnly commented Jul 16, 2025

So far no RC? I have a client project blocked by this atm :(, gotta rollback everything to older versions

@MathurAditya724
Copy link
Member Author

Hey Guys, I just released hono-openapi@0.5-rc.0(https://www.npmjs.com/package/hono-openapi/v/0.5.0-rc.0) check it out!

Here are the docs - https://rc.honohub.dev

@mstibbard
Copy link

Legend thank you! Was openAPIRouteHandler exported?

@Dom-Mac
Copy link

Dom-Mac commented Jul 26, 2025

Hey mate, hope you had a nice weekend :)

Same error here, only the zod-to-json-schema error disappeared for me, effect and valibot errors are still there!

✘ [ERROR] Build failed with 2 errors:

  ✘ [ERROR] Could not resolve "effect"
  
      ../../node_modules/@standard-community/standard-json/dist/effect-BHXCUs57.js:4:48:
        4 │   const { JSONSchema } = await tryImport(import('effect'), "effect");
          ╵                                                 ~~~~~~~~
  
    You can mark the path "effect" as external to exclude it from the bundle, which will remove this
  error and leave the unresolved path in the bundle. You can also add ".catch()" here to handle this
  failure at run-time instead of bundle-time.
  
  
  ✘ [ERROR] Could not resolve "@valibot/to-json-schema"
  
      ../../node_modules/@standard-community/standard-json/dist/valibot-B3sSM057.js:5:11:
        5 │     import('@valibot/to-json-schema'),
          ╵            ~~~~~~~~~~~~~~~~~~~~~~~~~
  
    You can mark the path "@valibot/to-json-schema" as external to exclude it from the bundle, which
  will remove this error and leave the unresolved path in the bundle. You can also add ".catch()"
  here to handle this failure at run-time instead of bundle-time.
  

Thanks for the quick answer and for your work!

@ImBIOS
Copy link

ImBIOS commented Jul 28, 2025

@MathurAditya724 I noticed you do repetitive manual labor for RC publishing in PR, here you go I automate it for you and all the contributors:

@mstibbard
Copy link

I still get all 3 errors when trying to run with wrangler on RC3.

 ✘ [ERROR] Could not resolve "effect"
...
  ✘ [ERROR] Could not resolve "@valibot/to-json-schema"
...
  ✘ [ERROR] Could not resolve "zod-to-json-schema"

It also does not like the way I've defined my ErrorResponse but that might be a zod v4 registry thing, or maybe even just a me-issue. Basically I have a shared error response schema for easy reuse, but using it causes the first hono route schema to not generate correctly... I know that's confusing, I'm happy to upload the simplest reproduction I can make if you are interested...

@ayame113
Copy link

ayame113 commented Jul 30, 2025

Thank you for this awesome project!

I am trying to use hono-openapi@0.5.0-rc.3 and zod v4. When I installed it, I got the following error.
Currently, peerDependency appears to only include zod v3. Would it be possible to include zod v4 in peer dependency?

Sorry, maybe standard-community/standard-openapi#2 is needed first to get zod v4 dependencies to work.
Anyway thanks for this project!

$ npm i hono-openapi@0.5.0-rc.3
npm error While resolving: undefined@undefined
npm error Found: zod@4.0.14
npm error node_modules/zod
npm error   zod@"^4.0.14" from the root project
npm error   peerOptional zod@"^3.25.0 || ^4.0.0" from @standard-community/standard-json@0.3.0-rc.3
npm error   node_modules/@standard-community/standard-json
npm error     peer @standard-community/standard-json@"^0.3.0-rc.3" from hono-openapi@0.5.0-rc.3
npm error     node_modules/hono-openapi
npm error       hono-openapi@"0.5.0-rc.3" from the root project
npm error     peer @standard-community/standard-json@"^0.3.0-rc.1" from @standard-community/standard-openapi@0.2.0-rc.1
npm error     node_modules/@standard-community/standard-openapi
npm error       peer @standard-community/standard-openapi@"^0.2.0-rc.1" from hono-openapi@0.5.0-rc.3
npm error       node_modules/hono-openapi
npm error         hono-openapi@"0.5.0-rc.3" from the root project
npm error   2 more (@standard-community/standard-openapi, zod-openapi)
npm error
npm error Could not resolve dependency:
npm error peerOptional zod@"^3.23.8" from hono-openapi@0.5.0-rc.3
npm error node_modules/hono-openapi
npm error   hono-openapi@"0.5.0-rc.3" from the root project

@MathurAditya724
Copy link
Member Author

Just released @standard-community/standard-json RC 4 can you try to install that and check does it now works in cloudflare?

@MathurAditya724
Copy link
Member Author

@MathurAditya724 I noticed you do repetitive manual labor for RC publishing in PR, here you go I automate it for you and all the contributors:

Thanks for the initiative, really appreciate it. Just wanted to know, will it be better if we use pkg.new CI thing?

@mstibbard
Copy link

It also does not like the way I've defined my ErrorResponse but that might be a zod v4 registry thing, or maybe even just a me-issue. Basically I have a shared error response schema for easy reuse, but using it causes the first hono route schema to not generate correctly... I know that's confusing, I'm happy to upload the simplest reproduction I can make if you are interested...

Here's a reproduction for the:

  1. imports issue ([ERROR] Could not resolve "effect" / "@valibot/to-json-schema" / "zod-to-json-schema"); and
  2. unusual openapi schema generation behavior (to do with reusable ErrorResponse?)

@MathurAditya724
Copy link
Member Author

It also does not like the way I've defined my ErrorResponse but that might be a zod v4 registry thing, or maybe even just a me-issue. Basically I have a shared error response schema for easy reuse, but using it causes the first hono route schema to not generate correctly... I know that's confusing, I'm happy to upload the simplest reproduction I can make if you are interested...

Here's a reproduction for the:

  1. imports issue ([ERROR] Could not resolve "effect" / "@valibot/to-json-schema" / "zod-to-json-schema"); and
  2. unusual openapi schema generation behavior (to do with reusable ErrorResponse?)

I am not seeing this error, maybe it was happening previously because of cache. Can you try to do a clean install?
image
image

@MathurAditya724
Copy link
Member Author

I will be merging this in an hour, so if anyone can test it out before that or facing some issues let me know. I have already released RC 4 for testing.

This will be getting released as v1

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a major v0.5 release that simplifies the package structure by removing NX, adds support for Standard Schema V1 and Zod v4, introduces response middleware for better type inference, and includes various optimizations.

Key changes include:

  • Complete architectural refactor from NX-based monorepo to simplified single package
  • Migration to Standard Schema V1 compliance for universal validation library support
  • New response middleware system for improved type safety

Reviewed Changes

Copilot reviewed 72 out of 75 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/handler.ts Core OpenAPI spec generation logic with caching and improved path filtering
src/middlewares.ts New validator and response description middleware with Standard Schema support
src/types.ts Type definitions for the new architecture including response handlers
src/utils.ts Utility functions for path conversion, operation ID generation, and schema merging
package.json Updated to single package configuration with Standard Schema dependencies
Comments suppressed due to low confidence (2)

src/handler.ts:1

  • The @ts-expect-error comment indicates a type mismatch. Consider properly typing the mergeParameters function or adding appropriate type assertions to resolve this issue.
import type { Context, Env, Hono } from "hono";

src/handler.ts:1

  • The @ts-expect-error comment indicates a type issue with the paths object assignment. Consider properly typing the paths object structure or using appropriate type assertions.
import type { Context, Env, Hono } from "hono";

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +184 to +190
// @ts-expect-error
paths[path][method] = mergeSpecs(
route,
...pathContext,
paths[path]?.[method],
specs,
);
Copy link

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

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

The @ts-expect-error comment indicates a type issue that should be resolved. Consider properly typing the paths object or using a more specific type assertion to improve code maintainability and type safety.

Suggested change
// @ts-expect-error
paths[path][method] = mergeSpecs(
route,
...pathContext,
paths[path]?.[method],
specs,
);
(paths[path] as OpenAPIV3_1.PathItemObject)[method] = mergeSpecs(
route,
...pathContext,
paths[path]?.[method],
specs,
);

Copilot uses AI. Check for mistakes.
Comment on lines +48 to +88
*/
export function validator<
Schema extends StandardSchemaV1,
Target extends keyof ValidationTargets,
E extends Env,
P extends string,
In = StandardSchemaV1.InferInput<Schema>,
Out = StandardSchemaV1.InferOutput<Schema>,
I extends Input = {
in: HasUndefined<In> extends true
? {
[K in Target]?: In extends ValidationTargets[K]
? In
: { [K2 in keyof In]?: ValidationTargets[K][K2] };
}
: {
[K in Target]: In extends ValidationTargets[K]
? In
: { [K2 in keyof In]: ValidationTargets[K][K2] };
};
out: { [K in Target]: Out };
},
V extends I = I,
>(
target: Target,
schema: Schema,
hook?: Hook<StandardSchemaV1.InferOutput<Schema>, E, P, Target>,
options?: ResolverReturnType["options"],
): MiddlewareHandler<E, P, V> {
const middleware = sValidator(target, schema, hook);

// @ts-expect-error not typed well
return Object.assign(middleware, {
[uniqueSymbol]: {
target,
...resolver(schema, options),
options,
},
});
}

Copy link

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

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

The @ts-expect-error comment suggests incomplete typing. Consider properly typing the middleware return value or the Object.assign operation to improve type safety.

Suggested change
*/
export function validator<
Schema extends StandardSchemaV1,
Target extends keyof ValidationTargets,
E extends Env,
P extends string,
In = StandardSchemaV1.InferInput<Schema>,
Out = StandardSchemaV1.InferOutput<Schema>,
I extends Input = {
in: HasUndefined<In> extends true
? {
[K in Target]?: In extends ValidationTargets[K]
? In
: { [K2 in keyof In]?: ValidationTargets[K][K2] };
}
: {
[K in Target]: In extends ValidationTargets[K]
? In
: { [K2 in keyof In]: ValidationTargets[K][K2] };
};
out: { [K in Target]: Out };
},
V extends I = I,
>(
target: Target,
schema: Schema,
hook?: Hook<StandardSchemaV1.InferOutput<Schema>, E, P, Target>,
options?: ResolverReturnType["options"],
): MiddlewareHandler<E, P, V> {
const middleware = sValidator(target, schema, hook);
// @ts-expect-error not typed well
return Object.assign(middleware, {
[uniqueSymbol]: {
target,
...resolver(schema, options),
options,
},
});
}
*/
// Augmented middleware type with uniqueSymbol property
type AugmentedMiddlewareHandler<
E extends Env,
P extends string,
V extends Input,
Target extends keyof ValidationTargets,
Schema extends StandardSchemaV1
> = MiddlewareHandler<E, P, V> & {
[uniqueSymbol]: {
target: Target;
vendor: Schema["~standard"]["vendor"];
validate: Schema["~standard"]["validate"];
toJSONSchema: () => ReturnType<typeof toJsonSchema>;
toOpenAPISchema: () => ReturnType<typeof toOpenAPISchema>;
options?: ResolverReturnType["options"];
};
};
export function validator<
Schema extends StandardSchemaV1,
Target extends keyof ValidationTargets,
E extends Env,
P extends string,
In = StandardSchemaV1.InferInput<Schema>,
Out = StandardSchemaV1.InferOutput<Schema>,
I extends Input = {
in: HasUndefined<In> extends true
? {
[K in Target]?: In extends ValidationTargets[K]
? In
: { [K2 in keyof In]?: ValidationTargets[K][K2] };
}
: {
[K in Target]: In extends ValidationTargets[K]
? In
: { [K2 in keyof In]: ValidationTargets[K][K2] };
};
out: { [K in Target]: Out };
},
V extends I = I,
>(
target: Target,
schema: Schema,
hook?: Hook<StandardSchemaV1.InferOutput<Schema>, E, P, Target>,
options?: ResolverReturnType["options"],
): AugmentedMiddlewareHandler<E, P, V, Target, Schema> {
const middleware = sValidator(target, schema, hook);
return Object.assign(middleware, {
[uniqueSymbol]: {
target,
...resolver(schema, options),
options,
},
}) as AugmentedMiddlewareHandler<E, P, V, Target, Schema>;
}

Copilot uses AI. Check for mistakes.
Comment on lines +75 to +79
// @ts-expect-error
options: {
...DEFAULT_OPTIONS,
...options,
},
Copy link

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

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

The @ts-expect-error comment suggests a type issue with the options object. Consider properly typing the DEFAULT_OPTIONS or the SpecContext options property.

Suggested change
// @ts-expect-error
options: {
...DEFAULT_OPTIONS,
...options,
},
options: {
...DEFAULT_OPTIONS,
...options,
} as Partial<GenerateSpecOptions>,

Copilot uses AI. Check for mistakes.
Comment on lines +328 to +330
// @ts-expect-error
schema: value,
required: schema.required?.includes(key),
Copy link

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

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

The @ts-expect-error comment suggests a type mismatch when assigning the schema value. Consider properly typing the parameter definition or using appropriate type assertions.

Suggested change
// @ts-expect-error
schema: value,
required: schema.required?.includes(key),
schema: value as OpenAPIV3_1.SchemaObject | OpenAPIV3_1.ReferenceObject,
required: schema.required?.includes(key),

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@MathurAditya724 MathurAditya724 merged commit ed1827c into main Sep 4, 2025
2 checks passed
@MathurAditya724 MathurAditya724 deleted the next branch September 4, 2025 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment