简体   繁体   中英

How to hide datatypes displaying as json values of @RequestBody example value in swagger-ui?

My Spring Boot app has a model class ReqGetActive used as request model in a @PostMapping request body.

Controller:

@PostMapping(value = "/api/getActive",
        consumes = "application/JSON",
        produces = "application/JSON")
public ResponseEntity<String> getActive(
        @ApiParam(value = "Consumer's request body", required = true)
        @RequestBody ReqGetActive jsonPojo) throws Exception {
    return null;
}

ReqGetActive:

import lombok.*;
import com.fasterxml.jackson.annotation.*;

public class ReqGetActive {
    @JsonProperty("RequestData")
    @JsonFormat(with = JsonFormat.Feature.ACCEPT_CASE_INSENSITIVE_PROPERTIES)
    private RequestData RequestData;

    @Getter @Setter @ToString
    @JsonIgnoreProperties(ignoreUnknown = true)
    private static class RequestData{
        @JsonProperty("ReportTitle")
        @JsonFormat(with = JsonFormat.Feature.ACCEPT_CASE_INSENSITIVE_PROPERTIES)
        private String ReportTitle;
    }
}

It displays the request model in swagger-ui like: swagger-ui-screenshot.png

Now my doubt is, as you see in the above picture the datatypes of class ReqGetActive fields are displayed as values of json fields.

Is it possible to display only the keys and the values as "" in the json model?

Ps: I use just swagger annotations to display in swagger-ui

I have manged to set required value using @ApiModelProperty to change it to my desired value. @ApiModelProperty(example = "[ExampleTitle]") private String ReportTitle;

ie., I can set any values except " " or null

Refer here: https://github.com/springfox/springfox/issues/1473

Ans Screenshot here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM