java - Spring boot 上的 Swagger 2 - 我可以为 API 下显示的所需参数设置句号吗?
问题描述
我有这个 api 叫做/predict
.
所需的参数有时可以是score1
和score2
或
info.score1
并info.score2
取决于我们得到的数据集。
现在它在我的 localhost:8080/swagger-ui.html 上的样子是
以下是我如何实现它:
@ApiOperation(value="", response=RequestInput.class)
@RequestMapping(value="/predict", method= RequestMethod.POST, produces="application/json", consumes="application/json")
public ResponseEntity predict(Map<String, Object> inputs, @RequestBody RequestInput requestInput) {
...
}
RequestInput.class
看起来像这样
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
public class RequestInput {
@ApiModelProperty(notes = "", required = true)
@Getter private Double score1;
@ApiModelProperty(notes = "", required = true)
@Getter private Double score2;
}
我有两个问题:
- 有没有可能
{
"info.score1":0,
"info.score2":0
}
- 如何设置
Responses
零件的示例值?现在它反映了正在发生的事情requestInput
。我希望它是
{
"finalScore":0
}
解决方案
要处理请求中的动态属性值,您可以添加设置器setInfoScore1
&setInfoScore2
并用@JsonProperty
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
public class RequestInput {
@ApiModelProperty(notes = "", required = true)
@Getter private Double score1;
@ApiModelProperty(notes = "", required = true)
@Getter private Double score2;
@JsonProperty("info.score1")
public void setInfoScore1(Double score) {
this.score = score;
}
@JsonProperty("info.score2")
public void setInfoScore2(Double score) {
this.score = score;
}
}
推荐阅读
- python - Sqlalchemy 覆盖关联表中的字段
- python - 如何使用硬盘驱动器上的本地文件实现?
- python - 如何从 Coinmarketcap 解析历史 BTC 数据?
- arrays - 如何创建可循环的已分配但长度为零的数组?
- reactjs - 反应.js。有没有办法实现通用的“onChange”事件处理程序
- scala - 从 Spark DataFrame 中列出的所有列的不同之处
- javascript - 在 Safari 中扩展本机(es6)类的问题
- java - 从 ServerSOAPFaultException 读取 CXF 异常消息详细信息
- apache - ErrorDocument 不能作为 httpd-vhosts.conf 中的本地路径工作
- java - Android:AsyncTask 中的 execute() 方法是如何工作的?