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.
These are two different annotations. You can combine them if needed.
Your issue seems just irrelevant.
I'm well aware that they both are different. Can you assist me on how we can combine them?
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()
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
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
@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.
@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.