Skip to content

feat(zod-openapi): add defineOpenAPIRoute and openapiRoutes for batch route registration#1752

Open
destroSunRay wants to merge 8 commits intohonojs:mainfrom
destroSunRay:zod-openapi-with-better-compatability-for-rpc-2
Open

feat(zod-openapi): add defineOpenAPIRoute and openapiRoutes for batch route registration#1752
destroSunRay wants to merge 8 commits intohonojs:mainfrom
destroSunRay:zod-openapi-with-better-compatability-for-rpc-2

Conversation

@destroSunRay
Copy link

Note
This is my first time contributing to open-source, if I made mistakes I'm sorry. Any feedback is welcome.

Description

This PR adds two new utilities to improve route definition and registration in @hono/zod-openapi:

  • defineOpenAPIRoute: Provides explicit type safety for route definitions
  • openapiRoutes: Enables batch registration of multiple routes with full type safety

Problem

  • Registering many routes individually was repetitive and verbose
  • Type inference for complex route configurations was challenging
  • Organizing routes across multiple files was difficult
  • No built-in support for conditional route registration
  • RPC type safety was hard to maintain across scattered route registrations

Solution

  • defineOpenAPIRoute: Wraps route definitions with explicit types for better IDE support and type checking
  • openapiRoutes: Accepts an array of route definitions and registers them all at once
  • Supports addRoute flag for conditional registration
  • Maintains full type safety and RPC support through recursive type merging
  • Enables clean modular organization of routes

Benefits

  • ✅ Reduced boilerplate code
  • ✅ Better type inference and IDE autocomplete
  • ✅ Easier code organization and maintainability
  • ✅ Declarative conditional routes
  • ✅ Full backward compatibility

Examples

See the updated README for usage examples.

Testing

  • All existing tests pass (102/102)
  • Added tests for new functionality
  • Verified type inference works correctly

Documentation

  • Updated package README with usage examples

@changeset-bot
Copy link

changeset-bot bot commented Feb 16, 2026

🦋 Changeset detected

Latest commit: ae04edc

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

This PR includes changesets to release 1 package
Name Type
@hono/zod-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

@destroSunRay
Copy link
Author

This pull request is the implementation for the proposed feature 1751.

@codecov
Copy link

codecov bot commented Mar 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.73%. Comparing base (031f805) to head (4c846b3).
⚠️ Report is 32 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1752      +/-   ##
==========================================
+ Coverage   92.68%   92.73%   +0.04%     
==========================================
  Files         112      112              
  Lines        3733     3744      +11     
  Branches      946      946              
==========================================
+ Hits         3460     3472      +12     
+ Misses        245      244       -1     
  Partials       28       28              
Flag Coverage Δ
zod-openapi 94.90% <100.00%> (+1.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@destroSunRay
Copy link
Author

I pushed fixes for the previous CI errors. Could a maintainer please rerun the failing workflow checks (or “Re-run all jobs”) when you have a moment? Thanks!

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