Swagger 招摇过市编辑器:找不到错误服务器或发生错误
我在招摇工具方面比较新。我尝试使用swagger编辑器测试我的Restfull应用程序。我使用基本身份验证来访问web服务 在Swagger UI中,预览看起来是正确的,即内容类型:Swagger 招摇过市编辑器:找不到错误服务器或发生错误,swagger,swagger-ui,swagger-editor,Swagger,Swagger Ui,Swagger Editor,我在招摇工具方面比较新。我尝试使用swagger编辑器测试我的Restfull应用程序。我使用基本身份验证来访问web服务 在Swagger UI中,预览看起来是正确的,即内容类型:application/json,json在正文中。但是当我从Swagger编辑器向服务器发送GET请求时,我收到了一个错误 ERROR Server not found or an error occurred 我的大摇大摆 { "swagger": "2.0", "info": {
application/json
,json在正文中。但是当我从Swagger编辑器向服务器发送GET请求时,我收到了一个错误
ERROR Server not found or an error occurred
我的大摇大摆
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Swagger Petstore (Simple)",
"description": "A sample API that uses a petstore 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://avfg.com"
},
"license": {
"name": "MIT",
"url": "http://opensource.org/licenses/MIT"
}
},
"host": "127.0.0.1:8xxx",
"basePath": "/v1",
"schemes": [
"http"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {
"/facedetect/{username}/{albumname}/{imagename}": {
"get": {
"description": "Returns all pets from the system that the user has access to",
"operationId": "findPets",
"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": "pet response",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/pet"
}
}
},
"default": {
"description": "unexpected error",
"schema": {
"$ref": "#/definitions/errorModel"
}
}
}
}
}
},
"definitions": {
"pet": {
"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"
}
}
}
}
}
请帮帮我
提前感谢。确保您的服务器正在运行 如果您安装了swagger,您可以这样做
swagger project start
我找到了解决办法
它的CORS问题。我的浏览器正在阻止cors请求。我安装了一个Chrome扩展,它将访问控制允许源站添加到传出请求中。我遇到了类似的问题
这是CORS,但是:
在nodeJS中,我设置了:
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization');
res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, UPDATE, DELETE, OPTIONS')
res.header("Content-Type", "application/json");
next();
});
但它只有在请求未经授权(api密钥)时才有用。要使其工作,我必须更改并使用:
const cors = require('cors');
app.use(cors());
如果您的服务器响应您所配置的内容,则希望这是有帮助的:?我已下载,但仍然无法允许该请求。。那之后我还需要做什么?