Java-Dropwizard Swagger示例问题

时间:2018-09-30 10:35:17

标签: java swagger dropwizard

我正在将dropwizard 1.3.5与com.smoketurner.dropwizard-swagger软件包一起使用。看来请求的配置有问题。

我有以下PoJo:

@JsonIgnoreProperties(ignoreUnknown = true)
@ApiModel
public class PageCreation {

    @NotEmpty
    @JsonProperty("page_default_title")
    @ApiParam(value = "super awesome page", defaultValue = "super awesome page", required = true)
    private String pageDefaultTitle;

    @NotEmpty
    @ApiParam(value = "page-slug", defaultValue = "page-slug", required = true)
    @JsonProperty("page_default_slug")
    private String pageDefaultSlug;

    @NotEmpty
    @ApiParam(value = "Amazing Website Title", defaultValue = "Amazing Website Title", required = true)
    @JsonProperty("default_seo_title")
    private String pageDefaultSeoTitle;

    @JsonProperty("default_seo_keywords")
    @ApiParam(value = "Amazing, Great, Awesome", defaultValue = "Amazing, Great, Awesome", required = false)
    private String defaultSeoKeywords;

    @JsonProperty("default_seo_description")
    @ApiParam(value = "This site is the best site in the world", defaultValue = "This site is the best site in the world", required = false)
    private String defaultSeoDescription;

    public PageCreation() {}

在我的资源中,我有以下路线:

@Path("/pages")
@Api(value = "/pages", description = "Create, Edit, Get and Filter Pages")
@Produces(MediaType.APPLICATION_JSON)
public class PageResource {

    private static Logger log = LoggerFactory.getLogger(PageResource.class);
    private final PageDAO pageDAO;

    public PageResource(PageDAO pageDAO) {
        this.pageDAO = pageDAO;
    }

    @POST
    @Timed
    @ExceptionMetered
    @Path("/create")
    @ApiOperation(
            value = "Create a new Page",
            notes = "This route allows you to create a new page.",
            response = BasicResponse.class
    )
    public Response createNewPage(@NotNull @Valid PageCreation page,
                                  @Context HttpHeaders httpHeaders) {

        String requestId = httpHeaders.getHeaderString("x-transactionid");

        if (requestId == null) {
            requestId = UUID.randomUUID().toString();
        }

        log.info(requestId + ": got new request to create a page");

        return Response.status(200).build();
    }

这在Swagger注释中可以很好地工作,但是在Swagger配置中,它不会在主体中设置默认值:

enter image description here

在swagger配置中,它会加载正确的对象/模型:

PageCreation{
page_default_title  string
readOnly: true
page_default_slug   string
readOnly: true
default_seo_title   string
readOnly: true
default_seo_keywords    string
readOnly: true
default_seo_description string
readOnly: true
}

但是为什么不设置示例值,所以实际上您可以在其中包含演示数据的情况下执行请求?

谢谢

0 个答案:

没有答案