Reputation: 21
For the following code, only Parameter id
is getting generated and its completely missing the "Request body" section.
I added type="object"
based on https://swagger.io/docs/specification/data-models/dictionaries/ .
public Item addProperties(
@Parameter(description = "identifier of the item")
@PathVariable("id") String id,
@Parameter(
description = "map of property names and values ",
content = @Content(
schema = @Schema(
type = "object",
implementation = Map.class)))
@RequestBody Map<String, Object> properties)
Upvotes: 2
Views: 4483
Reputation: 48610
The Map
type appears to be ignored by Open API (although I do not have a solid reference for this claim).
Refer to: GitHub ~ Issues ~ #597 ~ Request Body for Maps not available in Swagger-UI
Here is the workaround that is described from the GitHub issue above.
static {
SpringDocUtils.getConfig().removeRequestWrapperToIgnore(java.util.Map.class);
}
Place that static block inside your @SpringBootApplication
class. That should fix the issue.
@RequestBody Map<String, Object> properties // Should now generate correctly
Upvotes: 2
Reputation: 41
The @RequestBody
type has to be a class. So any of Map
's implementations would work (i.e. HashMap
).
@RequestBody HashMap<String, Object> properties
Upvotes: 4