在生成的swagger API文件

时间:2017-06-20 14:43:53

标签: angular oauth oauth-2.0 swagger-editor swagger-codegen

我正在使用angular-oauth2-oidc(https://www.npmjs.com/package/angular-oauth2-oidc)来获取OAuth授权的令牌。我也使用swagger来生成客户端API文件,我必须说这很好。我使用旧版本的在线编辑器生成我的客户端文件。我非常简短的摇摇欲坠的yaml:

  /fetchData:
    x-swagger-router-controller: controllerName
    post:
      operationId: oId
      tags:
        - tag
      security:
        - OauthSecurity: []
      parameters:
        - name: searchParameters
          in: body
          required: true
          schema:
            $ref: "#/definitions/definitionName"
      responses:
        200:
          description: Success
          schema:
            $ref: "#/definitions/responseName"

  securityDefinitions:
    OauthSecurity:
      type: oauth2
      flow: password
      tokenUrl: 'http://url/token'

为了在我的请求中添加Authorization标头,我需要为生成的文件提供配置。从其中一个生成的文件中复制粘贴:

if (this.configuration.accessToken) {
    let accessToken = typeof this.configuration.accessToken === 'function'
        ? this.configuration.accessToken()
        : this.configuration.accessToken;
    headers.set('Authorization', 'Bearer ' + accessToken);
}

我的问题是我将我的access_token存储在SessionStorage中,我希望生成的文件使用该存储中的值,而不是像解决方案在Configuring OAuth2 access token to typescript-angular2 client建议的那样提供它。

有没有办法实现这一点,而无需从swagger编辑器编辑生成的文件?是否有更简单的方法为我的不同生成文件提供配置?

感谢您的回答!

0 个答案:

没有答案