fix(hono): properly handle basePath() for route matching and schema generation#306
Merged
fix(hono): properly handle basePath() for route matching and schema generation#306
Conversation
…eration Hono's basePath() method was not being utilized correctly, causing the base option to only affect schema generation but not actual route matching. Changes: - Apply chanfana base option via Hono's basePath() method for proper routing - Read effective base from Hono's _basePath to include any pre-existing basePath - Remove redundant base prefix from doc routes (now handled by basePath) - Expose options via proxy for runtime access This ensures routes, OpenAPI schema paths, and documentation URLs all use the correct combined base path when using basePath on Hono directly or via chanfana's base option.
…eration - Auto-detect Hono's basePath() for schema generation and doc routes - Apply Hono's basePath() internally when chanfana base option is used - Throw error when both Hono basePath() and chanfana base are combined - Validate base format: must start with '/' and not end with '/' - Add routerHandlesBasePrefix flag so Hono skips base prefix on doc routes - Fix stale router reference in nested route handling - Expose options via proxy for runtime access - Update docs and migration guide with new basePath behavior
commit: |
b29c65f to
946c084
Compare
Merged
This was referenced Feb 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Builds on #303 by @hambergerpls — takes the original PR's approach of supporting Hono's
basePath()and reworks it with defensive runtime guards, better error handling, and additional bug fixes.basePath()so that route matching, OpenAPI schema generation, and doc UI routes all use the correct prefix automaticallybasePath()on Hono instances via_basePath(with runtime type guards and trailing-slash normalization)basePath()and chanfana'sbaseoption are combinedbaseformat (must start with/, must not end with/) in both adaptersbaseprefixschemaproperty toOpenAPIRouterTypetypeChanges
Source
src/adapters/hono.ts—getHonoBasePath()helper, rewrotefromHono()with detection/validation/error-handling, fixed stale router reference,routerHandlesBasePrefixgettersrc/openapi.ts—routerHandlesBasePrefixgetter,routeBaseincreateDocsRoutes(),schemaonOpenAPIRouterType,validateBasePath()usage, fixedregisterNestedRouterbase prependsrc/utils.ts—validateBasePath()helperTests
tests/integration/router-options.test.ts— 28 tests covering basePath detection,baseoption, combined error, format validation, openapi.yaml, nested routers with baseDocs
Related
Supersedes #303