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

use-fqn overrides SpringDoc configuration #635

Open
ctasada opened this issue Mar 4, 2024 · 3 comments
Open

use-fqn overrides SpringDoc configuration #635

ctasada opened this issue Mar 4, 2024 · 3 comments
Labels
bug Something isn't working waiting for feedback Waiting for user feedback/response

Comments

@ctasada
Copy link
Collaborator

ctasada commented Mar 4, 2024

Describe the bug
In an application that uses both SpringDoc for OpenApi and Spring-Wolf for AsyncAPI, the usage of spring-wolf.use-fqn overrides the one used by springdoc.use-fqn

I just realized after upgrading an application to spring-wolf:core 1.0.0 since the use-fqn is now defaulting to true the issue may be older.

Code example
Having a SpringBoot application with both dependencies, and the application.yml configured like

springdoc:
    use-fqn: true
    api-docs:
        enabled: true
        
springwolf:
    enabled: true
    use-fqn: false

I would expect the springdoc generated OpenAPI uses the FQN, but it's not the case. The value used for spring-wolf.use-fqn is alway taking precedence.

Stack trace and error logs
None

@ctasada ctasada added the bug Something isn't working label Mar 4, 2024
@timonback
Copy link
Member

timonback commented Mar 4, 2024

Thank you for the report and I agree with your expectation.

As part of the 1.0 release, I also slightly updated the code for handling the fqn setting.
Now, Springwolf always resets the swagger-core setting back to its original value:

We contributed the getter to swagger-core a while back in https://github.com/swagger-api/swagger-core/blame/3fcc473c33c56f306902853a451020926ad691ea/modules/swagger-core/src/main/java/io/swagger/v3/core/jackson/TypeNameResolver.java#L25
Unfortunately, it is a static field. So we set and reset it globally.


I wonder whether we are running into concurrency issues.

Is this also reproducible when the Springwolf init-mode is background?

@sam0r040
Copy link
Collaborator

sam0r040 commented Mar 8, 2024

Hi @ctasada I had another look at it and stumbled on the configuration property springdoc.pre-loading-enabled. If it is set to true then then springdoc will create the spec asynchronously although they are only setting the value at the constructor level: https://github.com/springdoc/springdoc-openapi/blob/0fdfabadf9a51895ada8c432aa521715e971b149/springdoc-openapi-starter-common/src/main/java/org/springdoc/core/service/OpenAPIService.java#L210

If thats the case, there might be issues with multithreading.

We can have a deeper look if you could provide an example that reproduces the issue.

Edit:
After a second look, what you could do is to try and create a ModelResolver for springwolf where we can set the use-fqn flag independently from springdoc, something like:

    @Bean
    public ModelResolver modelResolver(ObjectMapper objectMapper) {
        final TypeNameResolver resolver = new TypeNameResolver() {};
        resolver.setUseFqn(false);
        return new ModelResolver(objectMapper,resolver );
    }

If it works, we could use that as a solution for springwolf.

@sam0r040 sam0r040 added the waiting for feedback Waiting for user feedback/response label Apr 19, 2024
@ctasada
Copy link
Collaborator Author

ctasada commented May 4, 2024

I tried the different approaches and the issue persists.

Applying the @Bean affects also both, SpringDocs and SpringWolf

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

No branches or pull requests

3 participants