unjs / nitro

Next Generation Server Toolkit. Create web servers with everything you need and deploy them wherever you prefer.
https://nitro.unjs.io
MIT License
5.89k stars 496 forks source link

Swagger Version not defined and unable to render #2361

Open SelfhostedPro opened 5 months ago

SelfhostedPro commented 5 months ago

Environment

latest everything (node latest LTS)

Reproduction

https://stackblitz.com/edit/github-ujxcqv?file=nitro.config.ts

Describe the bug

Swagger docs aren't visible when going to /_nitro/swagger and pops up the following error:

Unable to render this definition
The provided definition does not specify a valid version field.

Please indicate a valid Swagger or OpenAPI version field. Supported version fields are swagger: "2.0" and those that match openapi: 3.0.n (for example, openapi: 3.0.0).
image

Additional context

No response

Logs

No response

Kasparas-G55 commented 5 months ago

Came across the same issue, stable channel of nitro is currently using swagger-ui-dist v4 CDN, which doesn't support OpenAPI 3.1.0 which is what it is set to.

Switching to nightly channel should fix your problem.

SelfhostedPro commented 5 months ago

Ah, I thought I also ran into this on nightly. Is there a way to manually specify the OpenAPI version in the nuxt config?

Kasparas-G55 commented 5 months ago

Sadly it isn't possible since the value is hardcoded. https://github.com/unjs/nitro/blob/3a69dd70bae87d12a6d9a86691fad48b2ebb044e/src/runtime/routes/openapi.ts#L25-L28 Though you could propose to use the upcoming meta object (https://github.com/unjs/nitro/pull/2299) to allow setting OpenAPI's version and use the latest if it isn't set, but I don't really see much purpose in that, would require more discussion.

What I did as a temporary workaround: I copied the generated routes from /_nitro/openapi.json and imported them into Postman. Do note that you will need to change the info version that is currently set to null, which is a invalid schema if you're going to use this approach.

kspace-trk commented 5 months ago

Hi, I expect this issue will be resolved when the version containing this Pull Request is released. https://github.com/unjs/nitro/pull/2343

pi0 commented 5 months ago

You can try with https://nitro.unjs.io/guide/nightly