Swagger UI在响应正文中返回“无内容”,响应代码0

时间:2016-10-20 07:19:55

标签: json swagger swagger-ui

我是 Swagger UI 的新手。我使用 Json 的招摇。当响应也 Json 时。点击试用后,我会看到正确的请求URL,但 Swagger UI 会在响应正文中返回"no content" 响应代码 0

Swagger

提到 API的网址不是公开可访问,但托管 Swagger UI 的网站与网站位于同一网络中托管API。

我看到this堆栈溢出问题,但找不到解决方案。

我的Swagger.Json文件:

{
    "swagger": "2.0",
    "info": {
        "version": "1.0.0",
        "title": "Swagger for Rest API",
        "description": "A sample API that uses a application as an example to demonstrate features in the swagger-2.0 specification",
        "termsOfService": "http://helloreverb.com/terms/",
        "contact": {
            "name": "Swagger API team",
            "email": "abc@gmail.com",
            "url": "http://xxxx.com"
        },
        "license": {
            "name": "MIT",
            "url": "http://opensource.org/licenses/MIT"
        }
    },
    "host": "localhost:85xx",
    "basePath": "/v1",
    "schemes": [
        "http"
    ],
    "consumes": [
        "application/json"
    ],
    "produces": [
        "application/json"
    ],
    "paths": {
        "/test/{username}/{albumname}/{imagename}": {
            "get": {
                "description": "Returns all images from the system that the user has access to",
                "operationId": "findface",
                "produces": [
                    "application/json",
                    "application/xml"
                ],
                "parameters": [
                    {
                        "name": "username",
                        "in": "path",
                        "description": "tags to filter by",
                        "required": true,
                        "type": "string"
                    },
                    {
                        "name": "albumname",
                        "in": "path",
                        "description": "maximum number of results to return",
                        "required": true,
                        "type": "string"
                    },
                    {
                        "name": "imagename",
                        "in": "path",
                        "description": "maximum number of results to return",
                        "required": true,
                        "type": "string"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/test1"
                            }
                        }
                    },
                    "default": {
                        "description": "unexpected error",
                        "schema": {
                            "$ref": "#/definitions/errorModel"
                        }
                    }
                }
            }
        }
    },
    "definitions": {
        "test1": {
            "type": "object",
            "required": [
                "id",
                "name"
            ],
            "properties": {
                "id": {
                    "type": "integer",
                    "format": "int64"
                },
                "name": {
                    "type": "string"
                },
                "tag": {
                    "type": "string"
                }
            }
        },
        "errorModel": {
            "type": "object",
            "required": [
                "code",
                "message"
            ],
            "properties": {
                "code": {
                    "type": "integer",
                    "format": "int32"
                },
                "message": {
                    "type": "string"
                }
            }
        }
    }
}

请任何人帮忙。 提前谢谢。

1 个答案:

答案 0 :(得分:3)

这应该是一个CORS问题。您应该将Access-Control-Allow-Origin: *添加到响应标头中。

请参阅:https://github.com/swagger-api/swagger-ui/blob/master/README.md#cors-support