我有一个springdoc应用程序,它使用支持Swagger。对于我来说,我无法让生成的Swagger实际发布JSON。相反,前端将args作为请求参数传递。如何让Swagger真正提交JSON?
@Data
public static class SampleData {
private String info;
}
@PostMapping(value = "/test", consumes = "application/json")
public void postData(@ParameterObject @RequestBody SampleData data) {
// do something
}在Swagger UI中单击“尝试它”和“执行”之后,请求将失败:
{
"status": 415,
"error": "Unsupported Media Type",
...
}因为UI试图发布以下内容:
http://localhost:8080/myapp/v1/test?info=test生成的curl命令也不正确(不是POSTing JSON):
curl -X 'POST' \
'http://localhost:8080/myapp/v1/test?info=test' \
-H 'accept: */*' \
-d ''注意,如果删除@ParameterObject注释,Swagger将发布JSON。但是,UI不提供对用户友好的表单(在完整的示例中包含该bean中字段的文档注释)。
我遗漏了什么?
springdoc: 2.6.3,springdoc ui: 1.6.5
发布于 2022-01-31 16:07:41
springdoc github的解决方案是删除@ParameterObject注释并切换到UI中的"Schema“视图,以查看POJO字段的文档。不完全是我所期望的解决方案,但它奏效了。github.com/springdoc/springdoc-openapi/issues/1482
https://stackoverflow.com/questions/70898701
复制相似问题