简体   繁体   English

swagger-ui-express 不显示响应

[英]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.

相关问题 swagger-ui-express未在浏览器中呈现,但在Postma中具有响应正文 - swagger-ui-express is not rendering in browser but has response body in Postma Swagger-ui-express模块​​仅实例化最后定义的文档 - Swagger-ui-express module, instantiates only the last defined document 在swagger-ui-express中如何解决CORS问题 - How to solve CORS issue in swagger-ui-express swagger-ui-express 不同 API 文档的多个路由 - swagger-ui-express Multiple Routes for Different API Documentation Swagger-UI-Express 未在 Azure 应用服务中加载:404 Not Found - Swagger-UI-Express not loading in Azure App Service: 404 Not Found 如何使用 swagger-ui-express 加载 YAML 文件? - How to load a YAML file with swagger-ui-express? Swagger - 正文中没有发送数据(swagger-jsdocs,swagger-ui-express) - Swagger - No data sent in body (swagger-jsdocs, swagger-ui-express) 如何在使用 swagger-ui-express 和 swagger-jsdoc 时正确使用 swagger 文件中的 $ref - How to use $ref in swagger file properly while working with swagger-ui-express and swagger-jsdoc 如何(自动)列出 Swagger UI 的所有路由(swagger-ui-express) - How to (auto) list all route to Swagger UI (swagger-ui-express) 托管在 aws beanstalk 上的 Nodejs express api swagger-ui-express API 文档上的 Cors 问题 - Cors issues on Nodejs express api swagger-ui-express API documentation hosted on aws beanstalk
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM