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

@RequestBody from Swagger v3 conflict with @RequestBody from the Spring Library #3628

Closed
debargharoy opened this issue Jul 13, 2020 · 8 comments

Comments

@debargharoy
Copy link

Consider the below piece of code

    public User createUser(@io.swagger.v3.oas.annotations.parameters.RequestBody(description = "Create the User") @RequestBody User user) {
        return userService.createUser(user);
    }

Isn't it a bad idea to have the same name @RequestBody for the annotation that belongs to Spring library as well? Because in the end, the Swagger's @RequestBody doesn't server the same purpose as that of the one from the Spring (the object is initialized to empty with all it's field set to null when using the annotation from Swagger alone), and we end up having fully qualified names for either of them which is discouraged.

@debargharoy debargharoy changed the title @RequestBody conflict with @RequestBody from the Spring Library @RequestBody from Swagger v3 conflict with @RequestBody from the Spring Library Jul 13, 2020
@mariem-89
Copy link

These are two different annotations. You can combine them if needed.
Your issue seems just irrelevant.

@debargharoy
Copy link
Author

I'm well aware that they both are different. Can you assist me on how we can combine them?

@Sarthak8696
Copy link

Sarthak8696 commented Dec 23, 2020

If you want to use both the annotations with the same name then you can write the swagger requestBody annotation like this - @io.swagger.v3.oas.annotations.parameters.RequestBody()
and write the spring requestBody annotation normally like @requestbody()

@debargharoy
Copy link
Author

If you want to use both the annotations with the same name then you can write the swagger requestBody annotation like this - @io.swagger.v3.oas.annotations.parameters.RequestBody()
and write the spring requestBody annotation normally like @requestbody()

I was asking if it is possible to combine both of them, rather than using two of them. And maybe these conflicts should be avoided in the next major of swagger-core release

@frantuma
Copy link
Member

I am not sure what you mean by "combine both of them", also please notice that swagger-core targets JAX-RS REST endpoints/code, and doesn't e.g. resolve Spring MVC endpoints (there are other projects providing this). Generally while trying to avoid duplicating annotation names, and because of the above, there are no plans to rename such annotation. I would close this ticket if this answers your question

@gcwiak
Copy link

gcwiak commented May 10, 2021

@debargharoy I have ran into similar consideration and found out that alternative to annotating the method parameter might be doing so on requestBody field of @io.swagger.v3.oas.annotations.Operation annotation, e.g.

@Operation(
            summary = "Crearte user operation",
            requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
                    description = "Create the User"
            )
    )

Though it still does not avoid using full qualified name.

@debargharoy
Copy link
Author

@gcwiak, it's nice to put it that way. Unfortunately, as you already said we'll still have to use both the annotations. As already highlighted by @frantuma, the issue stems from the fact that Swagger-Core is built around JAX-RS (which does not have it's own RequestBody), and Springdoc is built around Swagger-Core while also Spring having its own RequestBody annotation.

@frantuma, by the below phrase

I was asking if it is possible to combine both of them, rather than using two of them. And maybe these conflicts should be avoided in the next major of swagger-core release

what I meant to ask was, if there's a way to create a single annotation in our project that'll do the task of both the annotations together. But having explored that, it doesn't look like it's a feasible solution. So we'll have to continue using both the annotations together.

@marosivanco
Copy link

Could swagger at least use the type information from param marked with @org.springframework.web.bind.annotation.RequestBody when no explicit @io.swagger.v3.oas.annotations.parameters.RequestBody is provided?
That would lower code pollution by swagger annotations...

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

6 participants