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

unable to overwrite springdoc.model-converters.polymorphic-converter.enabled in JUnit test #2921

Open
mischa-n opened this issue Feb 26, 2025 · 4 comments

Comments

@mischa-n
Copy link

Describe the bug

If you have multiple @SpringBootTests that start a web environment, the property springdoc.model-converters.polymorphic-converter.enabled is evaluated when starting the first test and the result / the io.swagger.v3.core.converter.ModelConverters to be used are apparently cached somewhere outside the Spring application context.

If you then try to set the property to a different value in subsequent unit tests (e.g. via org.springframework.boot.test.context.SpringBootTest.properties()), this has no effect.

(@DirtiesContext and other approaches also do not work as a workaround).

To Reproduce
Steps to reproduce the behavior:

  • JUnit 5.11.3
  • Spring Boot 3.3.9
  • springdoc 2.6.0
  • Swagger 2.2.27
  • Apache Maven 3.9.9
  • Java 21.0.3

Expected behavior

The property springdoc.model-converters.polymorphic-converter.enabled may be overwritten in any test.

@Mattias-Sehlstedt
Copy link

Hi,

I am interpreting that your setup is trying to achieve the same thing as this test. When I run that test in conjunction with other tests (while also removing the static definition) I get different behavior between having the property defined as false and true. Which would indicate that the property is properly being disabled between separated tests.

@mischa-n
Copy link
Author

mischa-n commented Mar 3, 2025

It is not clear to me what exactly the linked test is trying to “achieve”.
But: yes, I can see that the activated ModelConverters are cached statically.
Unfortunately outside of springdoc - unless there are developers involved in both projects, there is probably little chance of changing this.

@Mattias-Sehlstedt
Copy link

I would suggest that you clone the repository so that you could see what the abstract test class defines.

To summarize it parses a controller and generates a specification for it, and it is then matched against an expected specification definition.

Thus the linked test verifies that the generated specification does not contain any structure that the polymorphic converter would generate. Since this test is ran together with tests that verify that the structure that the polymorphic converter would generate is present, then this would mean that the tests are achieving the case which you are looking for (some tests can have a converter disabled).

Hence cloning the repo and looking at how the tests are realized might guide you in how to realize what you are looking for.

@mischa-n
Copy link
Author

mischa-n commented Mar 3, 2025

Ahh, thanks for the explanation.

I'm not looking for a workaround (I already have one), but wanted to report a faulty implementation here.

As already recognizable from the first answer, the responsibility for static caching does not seem to lie with Springdoc, but in Swagger.

Accordingly, I don't see any specific need for action here for the time being, except that the problems with unit tests could possibly be noted on https://springdoc.org/properties.html.

Translated with DeepL.com (free version)

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