Swagger:当dto隐式覆盖到实体时,如何记录REST输入参数? [英] Swagger: How to document REST imput param, when dtois implicitly coverted to entity?

查看:343
本文介绍了Swagger:当dto隐式覆盖到实体时,如何记录REST输入参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们使用泽西岛2资源隐式使用dto时出现问题.

There isa problem, when we use Jersey2 resource with implicitly dto usage.

示例:

@POST
@ApiOperation(value = "Create pet", response = PetDTO.class)
public Pet create(Pet pet) throws IOException {
    return this.petService.save(pet);
}

在此示例中,我们隐式获取petDto作为参数,然后将其映射到实体.

In this example we implicitly get petDto as param, and than map it to entity.

问题是,如何配置swagger以将PetDTO记录为api参数而不是Pet的方法?

The question is, is the way to how to configure swagger to document PetDTO as api param, not Pet?

推荐答案

可以通过以下方式完成:

It can be done next way:

@POST
@ApiOperation(value = "Create pet", response = PetDTO.class)
@ApiImplicitParams({
        @ApiImplicitParam(name = "Pet dto",
        value = "pet", required = true,
        dataType = "com.example.PetDTO", paramType = "body")
})

public Pet create(@ApiParam(hidden = true) Pet pet) throws IOException {
}

这篇关于Swagger:当dto隐式覆盖到实体时,如何记录REST输入参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆