-
Notifications
You must be signed in to change notification settings - Fork 16
Improve openapi generation #1808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
7034572
initial rearrange
sevenzing 2026b78
rename amirealtime to realtime
sevenzing b9f5a42
specify needed middleware types
sevenzing 6f9b37c
add runtime check
sevenzing 7454e4d
Merge branch 'main' into ll/ensapi/improve-types
sevenzing 33124a2
pnpm lint
sevenzing 3e9a3c8
override fast-xml-parser version
sevenzing 7e0d032
add ProducingMiddleware
sevenzing 00a235e
make middleware to be keyvalue arg
sevenzing 18124d7
Merge branch 'main' into ll/ensapi/improve-types
sevenzing 56ac789
generate openapi spec from existing app
sevenzing 5e036d4
fix error during merge conflict
sevenzing c046ee1
fix lint issues
sevenzing 75dc815
fix lazy
sevenzing 6f86ba7
Merge branch 'main' into ll/ensapi/openapi-generation
sevenzing e1111c6
fix PR comments
sevenzing 00c6800
add lazyProxy
sevenzing 32128ea
Merge branch 'main' into ll/ensapi/openapi-generation
sevenzing df11f6d
remove trailing slash
sevenzing bddb22a
use lazyCache instead of lazy
sevenzing bc62a1a
Merge branch 'main' into ll/ensapi/openapi-generation
sevenzing 3e010c0
fix tests and lint
sevenzing File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import packageJson from "@/../package.json" with { type: "json" }; | ||
|
|
||
| import { otel } from "@hono/otel"; | ||
| import { cors } from "hono/cors"; | ||
| import { html } from "hono/html"; | ||
|
|
||
| import { errorResponse } from "@/lib/handlers/error-response"; | ||
| import { createApp } from "@/lib/hono-factory"; | ||
| import logger from "@/lib/logger"; | ||
| import { generateOpenApi31Document } from "@/openapi-document"; | ||
|
|
||
| import realtimeApi from "./handlers/api/meta/realtime-api"; | ||
| import apiRouter from "./handlers/api/router"; | ||
| import ensanalyticsApi from "./handlers/ensanalytics/ensanalytics-api"; | ||
| import ensanalyticsApiV1 from "./handlers/ensanalytics/ensanalytics-api-v1"; | ||
| import subgraphApi from "./handlers/subgraph/subgraph-api"; | ||
|
|
||
| const app = createApp(); | ||
|
|
||
| // set the X-ENSNode-Version response header to the current version | ||
| app.use(async (ctx, next) => { | ||
| ctx.header("x-ensnode-version", packageJson.version); | ||
| return next(); | ||
| }); | ||
|
|
||
| // use CORS middleware | ||
| app.use(cors({ origin: "*" })); | ||
|
|
||
| // include automatic OpenTelemetry instrumentation for incoming requests | ||
| app.use(otel()); | ||
|
|
||
| // host welcome page | ||
| app.get("/", (c) => | ||
| c.html(html` | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>ENSApi</title> | ||
| </head> | ||
| <body> | ||
| <h1>Hello, World!</h1> | ||
| <p>You've reached the root of an ENSApi instance. You might be looking for the <a href="https://ensnode.io/docs">ENSNode documentation</a>.</p> | ||
| </body> | ||
| </html> | ||
| `), | ||
| ); | ||
|
|
||
| // use ENSNode HTTP API at /api | ||
| app.route("/api", apiRouter); | ||
|
|
||
| // use Subgraph GraphQL API at /subgraph | ||
| app.route("/subgraph", subgraphApi); | ||
|
|
||
| // use ENSAnalytics API at /ensanalytics (v0, implicit) | ||
| app.route("/ensanalytics", ensanalyticsApi); | ||
|
|
||
| // use ENSAnalytics API v1 at /v1/ensanalytics | ||
| app.route("/v1/ensanalytics", ensanalyticsApiV1); | ||
|
|
||
| // use Am I Realtime API at /amirealtime | ||
| // NOTE: this is legacy endpoint and will be deleted in future. one should use /api/realtime instead | ||
| app.route("/amirealtime", realtimeApi); | ||
sevenzing marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // generate and return OpenAPI 3.1 document | ||
| app.get("/openapi.json", (c) => { | ||
| return c.json(generateOpenApi31Document(app)); | ||
| }); | ||
|
|
||
| app.get("/health", async (c) => { | ||
| return c.json({ message: "fallback ok" }); | ||
| }); | ||
|
|
||
| // log hono errors to console | ||
| app.onError((error, ctx) => { | ||
| logger.error(error); | ||
| return errorResponse(ctx, "Internal Server Error"); | ||
| }); | ||
sevenzing marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export default app; | ||
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.