Skip to content

Global security parameter should be overriden by local security parameter #348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
nekitk opened this issue Mar 1, 2022 · 0 comments
Open
Labels
bug Something isn't working

Comments

@nekitk
Copy link

nekitk commented Mar 1, 2022

I have schema with globally set security for all paths. But some of the paths override global security with empty value to disable security. When I generate http client for such schema all method calls have security: true, even the methods which overriden value.

Minimum reproduction schema:

openapi: 3.0.1

paths:
  #  Авторизация
  /auth/login:
    post:
      tags: [auth]
      security: []

  /token/revoke:
    post:
      tags: [ token ]

security:
  - bearerAuth: []

Expected result:
auth/login path should have secure: false (because it is overriden) and token/revoke should have secure: true (as in global parameter)

Actual result:
All methods have secure: true:

auth = {
  /**
   * No description
   *
   * @tags auth
   * @name LoginCreate
   * @request POST:/auth/login
   * @secure
   */
  loginCreate: (params: RequestParams = {}) =>
    this.http.request<any, any>({
      path: `/auth/login`,
      method: 'POST',
      secure: true,
      ...params,
    }),
}
token = {
  /**
   * No description
   *
   * @tags token
   * @name RevokeCreate
   * @request POST:/token/revoke
   * @secure
   */
  revokeCreate: (params: RequestParams = {}) =>
    this.http.request<any, any>({
      path: `/token/revoke`,
      method: 'POST',
      secure: true,
      ...params,
    }),
}

Possible solution

Seems like this condition need to be updated:
https://github.com/acacode/swagger-typescript-api/blob/master/src/routes.js#L562-L565

const hasSecurity = security
  ? !!security.length
  : !!(globalSecurity && globalSecurity.length)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants