[英]swagger-ui-express not displaying response
Chrome gets a 200 response with the expect data. Chrome 收到 200 响应,其中包含预期数据。 But swagger is not displaying the result.
但是 swagger 没有显示结果。
Swagger Options: Swagger 选项:
swaggerOptions = {
openapi: '3.0.0',
swaggerDefinition : {
info: {
title: 'Admin API',
description: 'Admin API integration',
version: "1.0",
contact: {
name: 'Vinicius A. Da Silva'
},
servers: [
'http://localhost:3000'
]
},
produces: ["application/json"],
securityDefinitions: {
bearerAuth: {
type: 'apiKey',
name: 'Authorization',
scheme: 'bearer',
in: 'header',
bearerFormat: 'JWT',
},
},
security: [ { bearerAuth: [] } ],
},
apis: [__dirname+'/controller/*.js']
}
Jsdoc comment: jsdoc评论:
/**
* @swagger
* /api/list?mdl={mdl}:
* security:
* - Bearer: []
* get:
* description: Returns all users
* responses:
* '200':
* description: Successfully returned paginated records
* '403':
* description: Not enough permissions read_modelName
* parameters:
* - name: mdl
* in: query
* description: Model name
* required: true
* schema:
* type: string
* format: string
* responses:
* '200':
* description: Successfully inserted a user
* content:
* 'application/json':
* schema:
* type: object
* description: test response
* '403':
* description: Not enough permissions
*/
Image:图片:
The response ui part of it, is not displaying.它的响应 ui 部分未显示。 Even though Chrome is getting 200 http response and the response data.
即使 Chrome 获得 200 http 响应和响应数据。
SOLUTION:解决方案:
The responses property must be within the http related method.响应属性必须在 http 相关方法内。
/**
* @swagger
* /api/list?mdl={mdl}:
* security:
* - Bearer: []
* get:
* description: Returns all users
* responses:
* '200':
* description: Successfully returned paginated records
* '403':
* description: Not enough permissions read_modelName
* parameters:
* - name: mdl
* in: query
* description: Model name
* required: true
* schema:
* type: string
* format: string
*/
That is happening because the format of your JSdoc comment is wrong.发生这种情况是因为您的 JSdoc 注释的格式错误。 There should be a tab space in the next line after
responses
key that you declared first so it should be like this.在您首先声明的
responses
键之后的下一行应该有一个制表符空间,所以它应该是这样的。
/**
* @swagger
* /api/list?mdl={mdl}:
* security:
* - Bearer: []
* get:
* description: Returns all users
* responses:
* '200':
* description: Successfully returned paginated records
* '403':
* description: Not enough permissions read_modelName
* parameters:
* - name: mdl
* in: query
* description: Model name
* required: true
* schema:
* type: string
* format: string
* responses:
* '200':
* description: Successfully inserted a user
* content:
* 'application/json':
* schema:
* type: object
* description: test response
* '403':
* description: Not enough permissions
*/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.