Swagger 大摇大摆的用户界面不';t显示400的响应模型
这是我生成的招摇过市文档的摘录Swagger 大摇大摆的用户界面不';t显示400的响应模型,swagger,swagger-ui,Swagger,Swagger Ui,这是我生成的招摇过市文档的摘录 "responses": { "200": { "description": "successful operation", "schema": { "$ref": "#/definitions/ActionJsValue" } }, "400": { "description": "list of validation errors",
"responses": {
"200": {
"description": "successful operation",
"schema": {
"$ref": "#/definitions/ActionJsValue"
}
},
"400": {
"description": "list of validation errors",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Error"
}
}
}
}
在定义部分:
"Error": {
"type": "object",
"properties": {
"path": {
"type": "string"
},
"messages": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
而swagger ui不显示响应模型
有人遇到过这个问题吗?
有人知道怎么解决吗
无论您用于生成swagger文档的url是什么,都是您需要在swagger ui index.html页面中使用的相同url。 例如:如果对生成的swagger文档使用“http://{servername}:{port}/{App Context}/{url pattern}/swagger.json”,则必须在index.html中使用相同的内容,如下所示
<script type="text/javascript">
$(function () {
var url = window.location.search.match(/url=([^&]+)/);
if (url && url.length > 1) {
url = decodeURIComponent(url[1]);
} else {
url = "http://petstore.swagger.io/v2/swagger.json";// you need to change this url to your's url http://{servername}:{port}/{App-Context}/{url-pattern}/swagger.json
}
$(函数(){
var url=window.location.search.match(/url=([^&]+)/);
如果(url&&url.length>1){
url=decodeURIComponent(url[1]);
}否则{
url=”http://petstore.swagger.io/v2/swagger.json“;//您需要将此url更改为您的url http://{servername}:{port}/{App Context}/{url pattern}/swagger.json
}
请告诉我这是否能帮助您,谢谢。我遇到了完全相同的问题,并找到了下一个解决方法 方法说明:
"responses": {
"200": {
"description": "successful operation",
"schema": {
"$ref": "#/definitions/ActionJsValue"
}
},
"400": {
"description": "list of validation errors",
"schema": {
"$ref": "#/definitions/ErrorsArray"
}
}
}
定义部分:
"ErrorsArray": {
"type": "array",
"items": {
"type": "object",
"properties": {
"path": {
"type": "string"
},
"messages": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
因此,只需将数组定义为单独的类型
swagger ui有效。我的问题是为什么响应模型列为空(cf屏幕截图),我希望看到
错误
确保在rest资源类和模型类的swagger注释中使用@ApiOperation(value=“…”,notes=“…”,Response=ResponseObj.class)@ApiModel(value=“Leaf LicenseInfoResponse”)公共类ResponseObj{private String code;@ApiModelProperty(value=“code”,notes=“…}关于生成的文档的摘录,注释似乎很好。您可以看到生成的文档摘录中的定义吗?如下“定义”:{“ResponseObj”:{“类型”:“object”,“properties”:{“code”:{“type”:“string”,“description”:“code”}},我用定义部分编辑了我的问题。对我来说似乎很好。