Node.js 如何在nodejs中的Swagger UI(Swagger.json)头部表示自定义令牌
我正在用ExpressJs创建一个Restful服务器。我集成了swagger jsdoc。以下是相关文件。下面(header.png)是我希望我的头在swagger UI中的样子。但是,当我打开我的swagger UI()时,我无法在头中看到令牌标记(令牌和身份验证) swagger.jsonNode.js 如何在nodejs中的Swagger UI(Swagger.json)头部表示自定义令牌,node.js,express,swagger,swagger-ui,swagger-2.0,Node.js,Express,Swagger,Swagger Ui,Swagger 2.0,我正在用ExpressJs创建一个Restful服务器。我集成了swagger jsdoc。以下是相关文件。下面(header.png)是我希望我的头在swagger UI中的样子。但是,当我打开我的swagger UI()时,我无法在头中看到令牌标记(令牌和身份验证) swagger.json { "swagger": "2.0", "info": { "version": "1.0.0", "title": "Viswa API" }
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Viswa API"
},
"host": "localhost:3000",
"basePath": "/api",
"tags": [{
"name": "Customers",
"description": "API for customers in the system"
}],
"schemes": [
"http"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"securityDefinitions": {
"Bearer": {
"type": "apiKey",
"name": "Authorization",
"in": "header"
},
"JWT": {
"type": "apiKey",
"name": "token",
"in": "header"
}
},
"paths": {
"/customer": {
"post": {
"tags": [
"Customers"
],
"description": "Create new customer in system",
"parameters": [{
"name": "customer",
"in": "body",
"description": "Customer that we want to create",
"schema": {
"$ref": "#/definitions/Customer"
}
}],
"produces": [
"application/json"
],
"responses": {
"201": {
"description": "New customer is created",
"schema": {
"$ref": "#/definitions/Customer"
}
}
}
}
}
},
"definitions": {
"Customer": {
"required": [
"email"
],
"properties": {
"customer_name": {
"type": "string"
},
"customer_email": {
"type": "string"
}
}
}
}
}
app.route
var apiRoutes = express.Router();
app.use('/api', apiRoutes);
// swagger definition
var swaggerUi = require('swagger-ui-express'),
swaggerDocument = require('../swagger.json');
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.use('/api/v1', apiRoutes);
当前招摇过市用户界面:您缺少安全标签。您可以在securityDefinitions标记下方全局定义它,也可以为每个API端点定义一个 看看这个问题