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

AdditionalModelsConverter Schema params rewriting #1957

Closed
apervushin opened this issue Nov 25, 2022 · 2 comments
Closed

AdditionalModelsConverter Schema params rewriting #1957

apervushin opened this issue Nov 25, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@apervushin
Copy link

Hi,

While using AdditionalModelsConverter we've faced with a problem that many BigDecimal fields wrongly marked as deprecated in swagger json.

We return BigDecimal as String in json {"val": "12.34"} and use configuration:
SpringDocUtils.getConfig().replaceWithSchema(BigDecimal.class, new Schema<BigDecimal>().type("string").format("decimal"));

It seems that the problem is in AdditionalModelsConverter resolve method:
https://github.com/springdoc/springdoc-openapi/blob/master/springdoc-openapi-common/src/main/java/org/springdoc/core/converters/AdditionalModelsConverter.java#L134

It returns the object from modelToSchemaMap instead of clone of this object. In SchemaPropertyDeprecatingConverter resolve method this object marked as deprecated.
https://github.com/springdoc/springdoc-openapi/blob/master/springdoc-openapi-common/src/main/java/org/springdoc/core/converters/SchemaPropertyDeprecatingConverter.java#L92

After that we have deprecated object in modelToSchemaMap.

@bnasslahsen
Copy link
Contributor

@apervushin,

Can provide a Minimal, Reproducible Example - with HelloController that reproduces the problem?

@apervushin
Copy link
Author

@bnasslahsen

Controller example:

@RestController("/")
public class HelloController {

    public record Response(@Schema(deprecated = true) @Deprecated BigDecimal val1,
                           BigDecimal val2, // also marked as deprecated in swagger json
                           BigDecimal val3  // also marked as deprecated in swagger json
    ) {}

    @GetMapping
    public Response test() {
        return new Response(BigDecimal.ONE, BigDecimal.ONE, BigDecimal.ONE);
    }
}

And the main class:

@SpringBootApplication
public class Application {

    public static void main(String[] args) {

        SpringDocUtils.getConfig().replaceWithSchema(
                BigDecimal.class,
                new Schema<BigDecimal>().type("string").format("decimal")
        );

        SpringApplication.run(Application.class, args);
    }
}

@bnasslahsen bnasslahsen added the bug Something isn't working label Nov 25, 2022
bnasslahsen added a commit that referenced this issue Nov 29, 2022
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

2 participants