-
Notifications
You must be signed in to change notification settings - Fork 533
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: experimental /_nitro/openapi.json
and /_nitro/swagger
endpoints for dev mode
#1162
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1162 +/- ##
==========================================
- Coverage 77.09% 67.99% -9.10%
==========================================
Files 67 66 -1
Lines 6613 6512 -101
Branches 727 728 +1
==========================================
- Hits 5098 4428 -670
- Misses 1514 2069 +555
- Partials 1 15 +14
... and 29 files with indirect coverage changes Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
That would be great! π₯ |
/_nitro/openapi.json
and /_nitro/swagger
endpoints for dev mode
Hot damn, I forgot I even commented on that issue but it has just become relevant again for a project. Will definitely check it out ASAP (which might sadly not be too soon as I'm quite busy :/)! |
// Served as /_nitro/swagger | ||
export default eventHandler((event) => { | ||
const title = "Nitro Swagger UI"; | ||
const CDN_BASE = "https://cdn.jsdelivr.net/npm/swagger-ui-dist@^4"; |
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.
It would be great if this were configurable or bundled for offline usage - though I guess that could be archived by manually recreating this route?
Great feature! It seems that the port 3000 in swagger is hardcoded, and the the port used in Nuxt. I am using port 3001 for this application, and the try out calls, won't work that way. Is this a bug, or just wrong configuration of nitro on my part? |
I guess https://github.com/unjs/nitro/blob/4111798a09fde7bf5916500637e27d6acc0189d1/src/runtime/routes/openapi.ts#L20 should reuse the host+port(+path+protocol) where the application is exposed |
I have found some problems using this. Generating the json works, although with some errors. When opening the swagger page I get a json syntax error. I believe this comes from swagger itself. When copying the generated schema into the online swagger editor it has errors. The versioning and parameters are missing an option. https://github.com/unjs/nitro/blob/2ad43894a6039207fd535d7fdc30ba92d4847ee6/src/runtime/routes/openapi.ts#L16 Regarding the parameters openapi states this:
See here When generating the paths, these properties are not set It would be great if there would an option we can define openapi properties for ourself. Maybe directly in the routes via a openapi config object that gets automatically picked up by the feature? |
I still don't understand how to use it, can you give me a sample code? |
Just update your Nitro config:
|
Also are there plans to enable configuring which If I understand correctly, it's generated via Nitro. I checked the discussions tab and only found this. My use case is I generating/build routes programmatically and would prefer to generate/build the |
It is still an experimental feature and to my knowledge there is no easy mechanism to hook into the generation, yet.
If you do not want to use the autogenerated one you could just serve a static file and register the UI endpoint manually.
I assume that once #938 gets merged these features could be combined to infer the types of the OpenAPI spec automatically. |
I tried defining My thought here is that although the module can't yet auto generate route params it can be used to build the doc serving UI/endpoint. I tinkered with it a bit and kept getting complaints from Nuxt regardless of if I used a |
In the v2.4.0 release notes it states |
I would also like to be updated on the status of adding the route level meta definitions. |
I don't know if this is a good place to report this but, I am using this feature in a Nuxt project and it works as long as I'm using npm. When I run an identical project in Bun, I get the "Unable to render this definition. The provided definition does not specify a valid version field." Though openapi.json is requested and looks the same. |
This comment was marked as off-topic.
This comment was marked as off-topic.
I'm nearly driven to despair by @scalar/scalar, a persistent hardcoded bug that's remained unresolved for months. If this resolves it, I'll be immensely pleased. |
π Linked issue
Resolves #3
Resolved #4
β Type of change
π Description
This PR exposes available routes and an initial meta using Open API 3 standard.
It exposes two endpoints for development:
/_nitro/openapi.json
: JSON response that can be integrated with external tools and setups such as Postman and Nuxt devtools to access available routes meta (/cc @antfu)/_nitro/swagger
: A basic UI that makes local debugging easierThis feature opens the next steps in supporting generic and extendable route meta via a well-defined standard.
π Checklist