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

OpenAPI Extensions no longer work #2104

Closed
kjc14f opened this issue Mar 3, 2023 · 3 comments
Closed

OpenAPI Extensions no longer work #2104

kjc14f opened this issue Mar 3, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@kjc14f
Copy link

kjc14f commented Mar 3, 2023

Describe the bug
It seems that the ability to add Extesntions to the OpenAPI object no longer works.
Previously you could provide .extensions() a Map<String, Object> which would reflect in the OpenAPI JSON.
Our application relied heavily on these custom extensions which is how I noticed the issue initially.

After trying several different versions, this functionality appears to have broken starting version 1.6.2 and still appears to be presnt in the latest version 2.0.2.

To Reproduce
Steps to reproduce the behavior:

Spring Boot : 2.7.9 (has to be 2.x.x so you can switch between Springdoc 1.6.1 and 1.6.2 easily)
JDK: 17.0.4
OS: Tested on Window 11 + RHEL8
Gradle 7.6.1

Example project to reproduce the bug: https://github.com/kjc14f/springdoc-test

Create a very simple Config class that sets an extremely simple extension(s):

@Configuration
public class SwaggerConfig {

  @Bean
  public OpenAPI customOpenAPI() {
    return new OpenAPI()
        .extensions(Map.of("TEST", "HELLO"));
  }

}

In build.gradle add implementation 'org.springdoc:springdoc-openapi-ui:1.6.1' as a dependency.

Run the app and view http://localhost:8080/v3/api-docs, you will notice "TEST": "HELLO" which is correct.

Version 1.6.1 working:

{
    "openapi": "3.0.1",
    "info": {
        "title": "OpenAPI definition",
        "version": "v0"
    },
    "servers": [
        {
            "url": "http://localhost:8080",
            "description": "Generated server url"
        }
    ],
    "paths": {},
    "components": {},
    "TEST": "HELLO"
}

Stop the app, switch the import to org.springdoc:springdoc-openapi-ui:1.6.2 and restart the app.
You will now see the extension "TEST": "HELLO" disappear.

Version >= 1.6.2 broken:

{
    "openapi": "3.0.1",
    "info": {
        "title": "OpenAPI definition",
        "version": "v0"
    },
    "servers": [
        {
            "url": "http://localhost:8080",
            "description": "Generated server url"
        }
    ],
    "paths": {},
    "components": {}
}

Expected behavior

OpenAPI JSON should show the extensions set on the OpenAPI object on all versions of Springdoc.
In the above example "TEST": "HELLO"

@kjc14f kjc14f changed the title OpenAPI Extension no longer work OpenAPI Extensions no longer work Mar 3, 2023
@kjc14f
Copy link
Author

kjc14f commented Mar 4, 2023

I did some more investigating and it looks like the breaking change was introduced here: https://github.com/springdoc/springdoc-openapi/blob/master/springdoc-openapi-common/src/main/java/org/springdoc/core/OpenAPIService.java#L251
calculatedOpenAPI = objectMapper.readValue(objectMapper.writeValueAsString(openAPI), OpenAPI.class);

Previously it was simply doing calculatedOpenAPI = openAPI which worked fine.
I guess this was changed to the above as a deep copy of the openAPI object was required.
Serializing to/from JSON does not work properly for this class though as the extensions are of type Map<String, Object> so they don't desrialize to a field as the deserializer is looking for the literal word extensions in the JSON at the moment.

It looks like bit of an awkward one as the OpenAPI class comes from another library and it is not Serializable which limits options!

@bnasslahsen bnasslahsen added the bug Something isn't working label Mar 9, 2023
@ezoerner
Copy link

ezoerner commented Dec 5, 2023

Unfortunately extensions are broken in deeper components inside OpenAPI as well. Extensions added to info are also lost. This fix only fixed extensions at the top level on OpenAPI.

@ezoerner
Copy link

ezoerner commented Dec 6, 2023

Using v1.6.15, but I don't see any issue open for this that would have been addressed for a more recent version of SpringDoc. Please re-open this issue or create a new one to address the fact that extensions also don't work for the Info that is in the OpenAPI object (and possible other subobjects of OpenAPI).

UPDATE: I opened a new issue for this #2449

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants