简体   繁体   中英

Swagger UI returns "no content" in the Response Body, and Response Code 0

I'm newer to Swagger UI . I use swagger with Json . When the response is also Json . When clicking Try it Out , I see a correct Request URL , but the Swagger UI returns "no content" in the Response Body , and Response Code 0 .

昂首阔步

Mentioned that API's URL is not publicly accessible, but the site that hosts the Swagger UI is in the same network as the site that hosts the API.

I see this stack overflow question, but not found the solution.

My Swagger.Json file:

{
    "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"
                }
            }
        }
    }
}

Please can any one help. Thank in Advance.

It should be a CORS issue. You should add Access-Control-Allow-Origin: * into response headers.

Please refer: https://github.com/swagger-api/swagger-ui/blob/master/README.md#cors-support

It should be a CORS issue. You should add Access-Control-Allow-Origin: * into response headers.

Use this code in the startup class

// global cors policy

 app.UseCors(x => x
            .AllowAnyOrigin()
            .AllowAnyMethod()
            .AllowAnyHeader());
       

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM