Skip to content
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

SwaggerUI shows error: Unable to render this definition #6339

Closed
pauljura opened this issue Apr 30, 2024 · 3 comments
Closed

SwaggerUI shows error: Unable to render this definition #6339

pauljura opened this issue Apr 30, 2024 · 3 comments

Comments

@pauljura
Copy link

I posted this in api-platform/api-platform but got no response so I think it might belong here instead...

API Platform version(s) affected: since 3.2.20 up to 3.3.0

Description
I recently upgraded a project that was using API Platform 3.1.17 to the latest release 3.2.20 (and later up to 3.3.0) and when I try to view the Swagger docs I get 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).

I can view the docs using ReDoc and download the swagger file, which I can see now has the following key; "openapi": "3.1.0" while my previous version had: "openapi": "3.0.0"

How to reproduce

Update to 3.2.20 or 3.3.0 and look at Swagger docs.

Possible Solution

I already have a decorator in my project to override the spec so it was easy for me to override the version from "3.1.0" to "3.0.0" and that makes the Swagger UI work with no further changes.

I also found the OpenApi class in ApiPlatform\OpenApi and if I change the VERSION constant to be "3.0.0" that also makes it work.

In fact, if I look at the code in version 3.1.17 the OpenApi class had the following code:

    // We're actually supporting 3.1 but swagger ui has a version constraint
    // public const VERSION = '3.1.0';
    public const VERSION = '3.0.0';

Looks like someone removed that and set the version to "3.1.0" and now it's broken. Was there some other change that should have been done to make all this work?

It seems that the SwaggerUI really needs the version to be in the form "3.0.n" and will not accept "3.1.0"

I'm actually surprised nobody else has reported this. Is it just me? Am I missing something?

Additional Context

image

@soyuka
Copy link
Member

soyuka commented Apr 30, 2024

update your swagger ui ?

@pauljura
Copy link
Author

How might I do that?

This is a Symfony project, I never installed Swagger UI, it came bundled with this package. When I do a composer update, I expected it to update everything.

What am I missing?

@pauljura
Copy link
Author

So after struggling to figure out why a brand new project was working fine but my existing project wasn't, I finally managed to figure it out.

The existing project was written for Symfony 5 and API Platform 2.5 and I've been doing version updates ever since. When I first installed API Platform it created files in the public/bundles directory, and apparently the latest version doesn't do this anymore, also this project is not using asset-mapper. So I found and copied the files from vendor/api-platform/core/src/Symfony/Bundle/Resources/public to public/bundles/apiplatform, overwriting the old files, and now everything works.

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

No branches or pull requests

2 participants