Skip to content
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

V2 Security definitions issues while parsing white spaces #1941

Open
s1moe2 opened this issue Dec 10, 2024 · 0 comments
Open

V2 Security definitions issues while parsing white spaces #1941

s1moe2 opened this issue Dec 10, 2024 · 0 comments

Comments

@s1moe2
Copy link

s1moe2 commented Dec 10, 2024

Describe the bug
Ran into the bug after trying out v2 on the latest rc.
When generating the docs, my security scheme was missing a key:

  securitySchemes:
    "":
      description: some description
      in: header
      name: Authorization
      type: apiKey

I found that this was caused by some incomplete white space parsing on getSecurityDefinitionKey:

  • parseGeneralAPIInfoV3 iterates over comments and does strings.TrimSpace but then passes the raw comments to parseSecAttributesV3.
  • getSecurityDefinitionKey then receives the same slice (named lines), which will check for a prefix, split by a space, etc.
  • The problem is that fmt will add a tab at before the annotation (and the space between key and value may also contain spaces/tabs if the user or fmt decide to do so):
    // @securityDefinitions.apikey cookieAuth
    // @in header
    // @name Authorization
    // @description some description

To Reproduce
Steps to reproduce the behavior:

  1. Create security definitions with a tab prefixing the annotation and/or between key and value, ex: // @securityDefinitions
  2. swag fmt
  3. swag init --v3.1

Expected behavior
Expected security schemes to have a key.

Your swag version
v2.0.0-rc4

Your go version
1.22.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant