Skip to content

refactor: use zod-openapi to serve openapi.json route#1687

Merged
notrab merged 11 commits intomainfrom
zod-openapi-json-endpoint
Feb 26, 2026
Merged

refactor: use zod-openapi to serve openapi.json route#1687
notrab merged 11 commits intomainfrom
zod-openapi-json-endpoint

Conversation

@notrab
Copy link
Member

@notrab notrab commented Feb 26, 2026

Lite PR

Tip: Review docs on the ENSNode PR process

Summary

  • Replaced hono-openapi's openAPIRouteHandler with @hono/zod-openapi's getOpenAPI31Document() for serving the /openapi.json route, using the existing stub routes and openapiMeta.
  • Removed unused hono-openapi and @hono/standard-validator dependencies
  • Removed dead validate.ts file (was the only consumer of hono-openapi, not imported anywhere).

Why

  • Completes the migration to zod-openapi for the ensapi app. All API routes have already been migrated to use @hono/zod-openapi's createRoute, so the spec endpoint should use the same system rather than relying on a separate hono-openapi library.

Testing

  • Type-checked with tsc --noEmit — passes cleanly.
  • Verified hono-openapi and @hono/standard-validator have no remaining imports in the source.

Notes for Reviewer (Optional)

  • openapi-meta.ts was updated to use the dynamic packageJson.version instead of the previously hardcoded "0.0.0".
  • The localhost development server is appended to the metadata at request time in index.ts since it depends on config (which openapi-meta.ts intentionally avoids importing to keep stub route generation config-free).

Pre-Review Checklist (Blocking)

  • This PR does not introduce significant changes and is low-risk to review quickly.
  • Relevant changesets are included (or are not required)

@notrab notrab requested a review from a team as a code owner February 26, 2026 08:45
Copilot AI review requested due to automatic review settings February 26, 2026 08:45
@changeset-bot
Copy link

changeset-bot bot commented Feb 26, 2026

⚠️ No Changeset found

Latest commit: c6f77af

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link
Contributor

vercel bot commented Feb 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

3 Skipped Deployments
Project Deployment Actions Updated (UTC)
admin.ensnode.io Skipped Skipped Feb 26, 2026 8:18pm
ensnode.io Skipped Skipped Feb 26, 2026 8:18pm
ensrainbow.io Skipped Skipped Feb 26, 2026 8:18pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7249a91 and c6f77af.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (9)
  • apps/ensapi/src/handlers/amirealtime-api.routes.ts
  • apps/ensapi/src/handlers/ensanalytics-api-v1.routes.ts
  • apps/ensapi/src/handlers/ensanalytics-api.routes.ts
  • apps/ensapi/src/handlers/ensnode-api.routes.ts
  • apps/ensapi/src/handlers/name-tokens-api.routes.ts
  • apps/ensapi/src/handlers/registrar-actions-api.routes.ts
  • apps/ensapi/src/handlers/resolution-api.routes.ts
  • apps/ensapi/src/index.ts
  • apps/ensapi/src/openapi-document.ts

📝 Walkthrough

Walkthrough

This PR transitions the ENS API from runtime-generated OpenAPI schemas to pre-generated static documents. It removes OpenAPI validation dependencies, adds operationId metadata and response schemas across route handlers, deletes the custom validation middleware, and introduces a new document generation function while maintaining existing route functionality.

Changes

Cohort / File(s) Summary
Dependency Management
apps/ensapi/package.json
Removed @hono/standard-validator and hono-openapi dependencies used for runtime OpenAPI validation.
Core OpenAPI Infrastructure
apps/ensapi/src/index.ts, apps/ensapi/src/openapi-meta.ts, apps/ensapi/src/openapi-document.ts
Replaced runtime OpenAPI schema generation with pre-generated static document via new generateOpenApi31Document function; dynamicized OpenAPI version from package.json.
Validation Layer
apps/ensapi/src/lib/handlers/validate.ts
Deleted entire validate middleware module exporting generic Hono validation using removed @hono/standard-validator.
Route Handlers — Resolution API
apps/ensapi/src/handlers/resolution-api.routes.ts
Added operationIds and 200 response content with imported JSON schemas; changed basePath from "/resolve" to "/api/resolve".
Route Handlers — operationId Metadata
apps/ensapi/src/handlers/amirealtime-api.routes.ts, apps/ensapi/src/handlers/ensanalytics-api-v1.routes.ts, apps/ensapi/src/handlers/ensanalytics-api.routes.ts, apps/ensapi/src/handlers/ensnode-api.routes.ts, apps/ensapi/src/handlers/name-tokens-api.routes.ts, apps/ensapi/src/handlers/registrar-actions-api.routes.ts
Added OpenAPI operationId metadata fields to route definitions for spec generation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

ensanalytics, ensnode-sdk

Poem

🐰 With whiskers twitching, I hop through the specs,
Pre-generated schemas, no runtime wrecks,
Dependencies shed like spring's fuzzy coat,
operationIds dance on each routed note,
The OpenAPI meadow now pristine and neat,
Static documents make validation complete! 📋✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: replacing hono-openapi with zod-openapi for the /openapi.json endpoint.
Description check ✅ Passed The PR description follows the template structure with all required sections: Summary, Why, Testing, Notes for Reviewer, and Pre-Review Checklist all completed with clear and relevant information.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch zod-openapi-json-endpoint

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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

Refactors ENSApi’s OpenAPI spec endpoint to generate and serve openapi.json directly from the existing @hono/zod-openapi route definitions, completing the migration away from hono-openapi and removing now-dead validation glue.

Changes:

  • Serve /openapi.json via OpenAPIHono#getOpenAPI31Document() using existing stub route registration plus shared openapiMeta.
  • Centralize OpenAPI metadata in openapi-meta.ts, including the dynamic package.json version.
  • Remove hono-openapi, @hono/standard-validator, and the unused validate.ts handler.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pnpm-lock.yaml Drops hono-openapi and related dependency graph from the lockfile.
apps/ensapi/src/openapi-meta.ts Adds packageJson.version to OpenAPI metadata (and keeps servers/tags in one place).
apps/ensapi/src/lib/handlers/validate.ts Removes unused validation middleware that depended on hono-openapi.
apps/ensapi/src/index.ts Replaces openAPIRouteHandler with getOpenAPI31Document() generated from stub-registered zod-openapi routes; appends localhost server dynamically.
apps/ensapi/package.json Removes unused hono-openapi and @hono/standard-validator dependencies.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 26, 2026

Greptile Summary

Completed the migration from hono-openapi to @hono/zod-openapi for generating the OpenAPI specification. The /openapi.json endpoint now uses getOpenAPI31Document() on a stub app with registered routes, replacing the previous openAPIRouteHandler approach.

  • Refactored /openapi.json route to use stub routes with @hono/zod-openapi's getOpenAPI31Document() method
  • Removed unused dependencies: hono-openapi and @hono/standard-validator
  • Deleted dead validate.ts file (no remaining imports found)
  • Updated openapi-meta.ts to use dynamic version from package.json instead of hardcoded "0.0.0"
  • Localhost server is now appended dynamically at request time

All changes are consistent with the established migration pattern from recent PRs (#1673, #1686, #1685, #1684, #1672, #1661). The refactoring is clean, well-tested (type-checks pass), and maintains the same functionality while consolidating on a single OpenAPI generation system.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • Clean refactoring that completes a well-established migration pattern. All dependencies verified as unused before removal, type checking passes, and the implementation follows the same approach as previous successful migrations. No breaking changes or edge cases identified.
  • No files require special attention

Important Files Changed

Filename Overview
apps/ensapi/package.json Removed unused hono-openapi and @hono/standard-validator dependencies after migration to @hono/zod-openapi
apps/ensapi/src/index.ts Replaced hono-openapi's openAPIRouteHandler with @hono/zod-openapi's getOpenAPI31Document() for serving /openapi.json route
apps/ensapi/src/lib/handlers/validate.ts Deleted unused validation helper that depended on hono-openapi - no imports found in codebase
apps/ensapi/src/openapi-meta.ts Updated version from hardcoded "0.0.0" to dynamic packageJson.version for accurate API versioning

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[GET /openapi.json Request] --> B[createStubRoutesForSpec]
    B --> C[Create OpenAPIHono App]
    C --> D[Register All Routes with Stub Handlers]
    D --> E[amIRealtimeRoutes]
    D --> F[ensnodeRoutes]
    D --> G[ensanalyticsRoutes]
    D --> H[nameTokensRoutes]
    D --> I[registrarActionsRoutes]
    D --> J[resolutionRoutes]
    E & F & G & H & I & J --> K[stubApp.getOpenAPI31Document]
    K --> L[Merge openapiMeta + localhost server]
    L --> M[Return OpenAPI 3.1 JSON]
Loading

Last reviewed commit: e3f8a94

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

5 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@vercel vercel bot temporarily deployed to Preview – ensnode.io February 26, 2026 09:09 Inactive
@vercel vercel bot temporarily deployed to Preview – admin.ensnode.io February 26, 2026 09:09 Inactive
@vercel vercel bot temporarily deployed to Preview – ensrainbow.io February 26, 2026 09:09 Inactive
Copilot AI review requested due to automatic review settings February 26, 2026 09:58
@vercel vercel bot temporarily deployed to Preview – ensnode.io February 26, 2026 09:58 Inactive
@vercel vercel bot temporarily deployed to Preview – admin.ensnode.io February 26, 2026 09:58 Inactive
@vercel vercel bot temporarily deployed to Preview – ensrainbow.io February 26, 2026 09:58 Inactive
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

Copilot reviewed 11 out of 12 changed files in this pull request and generated 5 comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/ensapi/src/handlers/name-tokens-api.routes.ts`:
- Line 34: The operationId "getApiName-tokens" in name-tokens-api.routes.ts
should follow the project's canonical operationId convention rather than being
changed in isolation; pick the standard pattern (either the existing
hyphen/colon style or an alphanumeric-only style) and apply it consistently
across all route handler files (update the operationId strings in this file and
the other route handlers), then regenerate any codegen/artifacts and update
tests/docs to match the chosen convention; specifically ensure the operationId
value "getApiName-tokens" is aligned with the decided pattern across the
codebase.

ℹ️ Review info

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0594277 and 69bb301.

📒 Files selected for processing (7)
  • apps/ensapi/src/handlers/amirealtime-api.routes.ts
  • apps/ensapi/src/handlers/ensanalytics-api-v1.routes.ts
  • apps/ensapi/src/handlers/ensanalytics-api.routes.ts
  • apps/ensapi/src/handlers/ensnode-api.routes.ts
  • apps/ensapi/src/handlers/name-tokens-api.routes.ts
  • apps/ensapi/src/handlers/registrar-actions-api.routes.ts
  • apps/ensapi/src/handlers/resolution-api.routes.ts

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/ensapi/src/handlers/resolution-api.routes.ts`:
- Line 17: The operationId values use inconsistent punctuation and casing which
can break code generators; update the operationIds to a consistent camelCase
pattern (no hyphens or colons). Replace getApiResolveRecords:name with something
like getApiResolveRecordsByName, getApiResolvePrimary-name:address:chainId with
getApiResolvePrimaryByNameAddressChainId, and getApiResolvePrimary-names:address
with getApiResolvePrimaryByNamesAddress (apply same convention at the other
occurrences referenced in the comment).

In `@packages/ensnode-sdk/src/ensapi/api/resolution/zod-schemas.ts`:
- Around line 47-49: The JSON Schema for the names field is invalid because
propertyNames: { type: "number" } is incorrect; update the withOpenApi call for
the names schema (the names variable using withOpenApi and z.record) to replace
propertyNames: { type: "number" } with a pattern-based constraint that matches
numeric-looking keys (for example propertyNames: { pattern: "^[0-9]+$" } or
another regex you need) so propertyNames validates the string property names
correctly instead of using type:"number".

ℹ️ Review info

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 69bb301 and 4b5129f.

📒 Files selected for processing (4)
  • apps/ensapi/src/handlers/resolution-api.routes.ts
  • packages/ensnode-sdk/src/ensapi/api/resolution/zod-schemas.ts
  • packages/ensnode-sdk/src/indexing-status/zod-schema/omnichain-indexing-status-snapshot.ts
  • packages/ensnode-sdk/src/shared/zod-types.ts

Copilot AI review requested due to automatic review settings February 26, 2026 11:31
@vercel vercel bot temporarily deployed to Preview – ensnode.io February 26, 2026 11:31 Inactive
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

Copilot reviewed 12 out of 13 changed files in this pull request and generated no new comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 26, 2026 13:30
@vercel vercel bot temporarily deployed to Preview – ensnode.io February 26, 2026 13:30 Inactive
@vercel vercel bot temporarily deployed to Preview – admin.ensnode.io February 26, 2026 13:30 Inactive
@vercel vercel bot temporarily deployed to Preview – ensrainbow.io February 26, 2026 13:30 Inactive
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

Copilot reviewed 12 out of 13 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@vercel vercel bot temporarily deployed to Preview – ensnode.io February 26, 2026 13:44 Inactive
@vercel vercel bot temporarily deployed to Preview – admin.ensnode.io February 26, 2026 13:44 Inactive
@vercel vercel bot temporarily deployed to Preview – ensrainbow.io February 26, 2026 13:44 Inactive
Copy link
Contributor

@tk-o tk-o left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@lightwalker-eth lightwalker-eth left a comment

Choose a reason for hiding this comment

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

@notrab Really happy how this is advancing 😄 Looks good!

@vercel vercel bot temporarily deployed to Preview – admin.ensnode.io February 26, 2026 20:18 Inactive
@vercel vercel bot temporarily deployed to Preview – ensnode.io February 26, 2026 20:18 Inactive
@vercel vercel bot temporarily deployed to Preview – ensrainbow.io February 26, 2026 20:18 Inactive
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

Copilot reviewed 12 out of 13 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 27 to 31
"@ensnode/ponder-subgraph": "workspace:*",
"@hono/node-server": "^1.19.5",
"@hono/otel": "^0.2.2",
"@hono/standard-validator": "^0.2.2",
"@hono/zod-openapi": "^1.2.2",
"@namehash/ens-referrals": "workspace:*",
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

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

pnpm-lock.yaml still lists @hono/standard-validator and hono-openapi under the apps/ensapi importer (so a CI run with --frozen-lockfile will fail). Please regenerate and commit the lockfile after removing these deps from apps/ensapi/package.json.

Copilot uses AI. Check for mistakes.
@notrab notrab merged commit 8025915 into main Feb 26, 2026
16 checks passed
@notrab notrab deleted the zod-openapi-json-endpoint branch February 26, 2026 20:27
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.

4 participants