-
-
Notifications
You must be signed in to change notification settings - Fork 289
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
feat: add swagger ui API explorer #5970
Conversation
): void { | ||
server.route({ | ||
url: route.url, | ||
method: route.method, | ||
handler: route.handler, | ||
schema: route.schema, | ||
// append the namespace as a tag for downstream consumption of our API schema, eg: for swagger UI | ||
schema: {...route.schema, ...(namespace ? {tags: [namespace]} : undefined)}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was required in order to group paths by namespace.
It would be nice to be able to reuse more of the beacon API schema but 🤷 that seems like a larger refactor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enriched schema would definitely be nice to have, especially for POST requests. I think we would have to pull a pinned version of the beacon-API schema from github and then override each route based on operationId
. This will become especially important if we want to generate a API docs page with redoc (or similar tooling).
opts: BeaconRestApiServerOpts, | ||
version = "" | ||
): Promise<void> { | ||
await server.register(await import("@fastify/swagger"), { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tags: opts.api.map((namespace) => ({name: namespace})), | ||
}, | ||
}); | ||
await server.register(await import("@fastify/swagger-ui"), { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Performance Report✔️ no performance regression detected Full benchmark results
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pretty cool! Left a few suggestions
): void { | ||
server.route({ | ||
url: route.url, | ||
method: route.method, | ||
handler: route.handler, | ||
schema: route.schema, | ||
// append the namespace as a tag for downstream consumption of our API schema, eg: for swagger UI | ||
schema: {...route.schema, ...(namespace ? {tags: [namespace]} : undefined)}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enriched schema would definitely be nice to have, especially for POST requests. I think we would have to pull a pinned version of the beacon-API schema from github and then override each route based on operationId
. This will become especially important if we want to generate a API docs page with redoc (or similar tooling).
@@ -89,4 +91,12 @@ export const options: CliCommandOptions<ApiArgs> = { | |||
type: "number", | |||
description: "Defines the maximum payload, in bytes, the server is allowed to accept", | |||
}, | |||
|
|||
"rest.swaggerUI": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we also support this for the validator keymanager API?
"keymanager.bodyLimit"?: number; |
For keymanager would also be nice to support bearer auth through the explorer but again might not be worth the effort.
"Enable Swagger UI for API exploration at http://{address}:{port}/documentation. This should not be used in production.", | ||
default: Boolean(defaultOptions.api.rest.swaggerUI), | ||
group: "api", | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential other config options
- path
- server url (would be required if node runs behind proxy)
Depending on what use cases we see for this, might not be worth to add those now.
Co-authored-by: Nico Flaig <nflaig@protonmail.com>
const url = await import("node:url"); | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); | ||
return await fs.readFile(path.join(__dirname, "../../../../../assets/", name)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticed we don't copy assets
in our docker build
Line 8 in 4fd3d4d
assets |
I think we can just include them, size impact is relatively low
1.2M assets
288.1M node_modules
🎉 This PR is included in v1.12.0 🎉 |
Motivation
Description
--rest.swaggerUI
cli option (default to false)/documentation