Camel REST DSL set Example Value for Swagger UI

Viewed 410

Is it possible and if yes, how to set the Example Value for Swagger UI using Camel REST DSL in Java?

I'm running Swagger UI from org.webjars dependency in Spring Boot.

rest("/test").description("Some description").consumes("application/json").produces("application/json")
                .post("/trigger").id("trigger")
                .description("Another description")
                .type(Map.class).param().name("body").type(body).description("More description"))
                .required(true).example(readJson.getJson("json_example.txt")).endParam()
                .route().bean(new Service(), "Trigger");

This readJson get JSON as String. It looks like .example() is ignored and nothing appears in Swagger UI.

It always shows the "string" value inside Example Value like on the picture below.

enter image description here

2 Answers

As a solution, I've created Java POJO class with next code:

public class User{
    public String user_id;
    public String user_name;
}

Then I linked that class to the Camel REST DSL inside SpringBootRouter class:

...
rest("/test").description("Some description").consumes("application/json").produces("application/json")
                .post("/trigger").id("trigger")
                .description("Another description")
                .type(User.class).param().name("body").type(body).description("More description"))
                .required(true).endParam()
                .route().bean(new Service(), "Trigger");
...

And this is the result:

enter image description here

If there is a better solution, please tell.

UPDATE:

To replace default value "string" for String or 0 for int or true for Boolean, I've used ApiModelProperty like this:

import io.swagger.annotations.ApiModelProperty;
    
public class User{
    @ApiModelProperty(example = "1165")
    public String user_id;
    @ApiModelProperty(example = "Bob")
    public String user_name;
}

And this is the final result:

enter image description here

In swagger v3 you use

@Model(description = "The user name", example = "Bob")
public String user_name;
Related