Jayesh
Jayesh

Reputation: 4893

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.

Swagger

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": "[email protected]",
            "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.

Upvotes: 2

Views: 15967

Answers (2)

Md Samrat Akbor
Md Samrat Akbor

Reputation: 75

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());
       

Upvotes: 0

yenpu
yenpu

Reputation: 96

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

Upvotes: 4

Related Questions