【问题标题】:Custom Headers with Express Swagger Generator?带有 Express Swagger 生成器的自定义标头?
【发布时间】:2021-07-14 18:54:05
【问题描述】:

我是swagger新手,使用express swagger generator节点模块制作API文档。

API 使用基于字符串的密钥系统,而不是 APIkey。

我用来生成文档的代码如下所示。

/**
 * Return merged data for a given landingPageId.
 * @route GET /merged/admin/{landingId}
 * @group Admin - Admin oriented operations
 * @param {string} landingId.path - ID of the needed landing page
 * @param {string} auth.header.required - Auth Key
 * @returns {object} 200 - Content of a landing page of the specified id
 * @returns {object} 401 - Unauthorized
 * @returns {Error}  default - error
 */

问题是:我不能使用 swagger 的身份验证,因为我没有使用 APIKey,我想通过 express swagger 在 header 中输入我的自定义身份验证,但是“auth.header”不起作用,有没有办法度过这个难关?还是我需要自己去 Swagger 才能找到合适的解决方案?

非常感谢!

【问题讨论】:

    标签: javascript api express authentication swagger


    【解决方案1】:

    在招摇选项中你必须定义它们

     securityDefinitions: {
       JWT: {
         type: 'apiKey',
         in: 'header',
         name: 'nameOfYourSec',
         description: "Ensure Auth User Token"
       }
     }
    

    然后添加标题:

    @headers {string} 授权 和安全 @security JWT

    为我工作

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-02
      相关资源
      最近更新 更多