Swagger UI returns "no content" 在 Response Body 中,Response Code 为 0
Swagger UI returns "no content" in the Response Body, and Response Code 0
我是 Swagger UI 的新手。我将 swagger 与 Json 结合使用。当响应也是Json。当单击 Try it Out 时,我看到一个正确的请求 URL
,但是 Swagger UI returns "no content"
在 Response Body 和 Response Code 0
.
提到API的URL无法公开访问,但托管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"
}
}
}
}
}
请任何人帮忙。
提前致谢。
应该是CORS问题。您应该将 Access-Control-Allow-Origin: *
添加到响应 headers.
请参考:https://github.com/swagger-api/swagger-ui/blob/master/README.md#cors-support
应该是CORS问题。您应该添加 Access-Control-Allow-Origin: * 到响应 headers.
在启动时使用此代码class
// 全局 cors 策略
app.UseCors(x => x
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());
我是 Swagger UI 的新手。我将 swagger 与 Json 结合使用。当响应也是Json。当单击 Try it Out 时,我看到一个正确的请求 URL
,但是 Swagger UI returns "no content"
在 Response Body 和 Response Code 0
.
提到API的URL无法公开访问,但托管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"
}
}
}
}
}
请任何人帮忙。 提前致谢。
应该是CORS问题。您应该将 Access-Control-Allow-Origin: *
添加到响应 headers.
请参考:https://github.com/swagger-api/swagger-ui/blob/master/README.md#cors-support
应该是CORS问题。您应该添加 Access-Control-Allow-Origin: * 到响应 headers.
在启动时使用此代码class
// 全局 cors 策略
app.UseCors(x => x
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());