Current look of Swagger request
Is it possible to change the body
{
"config": {
"additionalProp1": {},
"additionalProp2": {},
"additionalProp3": {}
},
"class": "string"
}
to look like
{
"class": "my.class.com",
"config": {
"myParam": "",
"datacenter": "USA",
}
Currently the method looks like this
@POST
@Path("/run")
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Runs a specified job asynchronously",
notes = "Doesn't work for full tasks.")
public Response createTask(TaskConfig taskConfig) {
TaskConfig is a basic class with two member variables
public class TaskConfig {
@JsonProperty("class")
@NotNull
private String clazz;
private Map<String, Object> config;
We are using Swagger 1.5 from this Dropwizard Swagger bundle library. I know that 2.0 has the @RequestBody annotation and I just want to make sure that is my only option before I go down the path of upgrading.
Even by using @RequestBody we need to add additional annotation within TaskConfig class.
We are using Swagger 2.0.x. The TaskConfig class would have fields something like this :
@Schema(
description = " My descriptions",
type = "array",
example = " {\"myParam\" :\"value\" ,"
+ "\"datacenter\": \"USA\"}")
private Map<String, Object> config;
Similarly clazz can also be annotated like :
@Schema(description = "The field descrition", example = "true")
And RequestBody annotation will look like :
@RequestBody(
description = "Description of TaskConfig ",
content = @Content(schema = @Schema(implementation = TaskConfig .class)))
I got the result as shown in the image:

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With