- SpringDoc 1.5.3 (latest)
- SwaggerUI 3.41.0 (latest)
Swagger UI shows nice fields for @RequestParam
.
I have a POST endpoint, so I used @RequestBody
.
I can send a JSON and it parses into my body object. So far so good.
But Swagger UI shows only a textarea, where I am supposed to put the whole JSON. Which is not too convenient.
I would like Swagger UI to show individual fields for each property of the request class; and have that without the YAMLs - just with annotations. Although, YAML solution is ok if no other option.
The closest I found is @ParameterObject
support for POST, discussed here:
class MyParam (
val a: String,
val b: SomeEnum,
@field:Parameter(required = false)
val someId: String?,
)
@PostMapping("/...", consumes = [ MediaType.APPLICATION_JSON_VALUE ])
fun addMyEntity(
@ParameterObject param: MyParam
)
However, this seems to build the object from the query parameters.
In SpringFox, there used to be @ApiModel
and @ApiModelParameter
, which I suppose would do this. SpringDoc migration page suggests to replace that with @Schema
, but I couldn't figure out how.
Is there something that would make Swagger UI to display fields from a class in the same way, but assemble a JSON body from it? And Spring would still parse it from body?
Perhaps something like:
fun addInsisPaymentRequest(
@BodyObject param: MyParam
)