我有一个名为/predict的api。
所需的参数有时可以是score1和score2或
info.score1和info.score2取决于我们得到的数据集。
现在,它在我的本地主机上的样子: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
}发布于 2020-01-13 09:51:53
关于您的第一个问题: ApiModelProperty有“名称”,可以设置为显示您想要的属性名。第二步:检查io.swagger.annotations.ApiResponses和io.swagger.annotations.ApiResponse。ApiResponse有一个示例属性,也可以设置该属性。关于您问题的一部分,您的api有时可以是一个值,有时也可以是另一个值:老实说,我认为这是不可能得到默认的昂首阔步的行为。
发布于 2020-01-13 10:07:15
要处理请求中的动态属性值,可以添加setter 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;
}
}https://stackoverflow.com/questions/59713985
复制相似问题