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

securityDefinitions are not parsed #95

Open
adrian-sturm opened this issue Nov 22, 2022 · 1 comment
Open

securityDefinitions are not parsed #95

adrian-sturm opened this issue Nov 22, 2022 · 1 comment

Comments

@adrian-sturm
Copy link

I have added securityDefinitions.apikey to my api doc annotations and used the security definition on a route.

What I expected: The route will have the lock-symbol-button rendered on its right side, where I can click on to fill out auth data for the protected route. Additionally, a green "Authorize" Button is rendered at the top of the swaggerUI page where I can configure auth methods as well.

What I got: The little lock-symbol is rendered on my route, but there is no action when I click on it. There is no "Authorize" Button neither.
When I check the generated swagger.json, I can see that there is an empty security entry on my route:

"security": [
                    {
                        "ApiKeyAuth": []
                    }
                ],

But no security config whatsoever at the root level (where host, info etc are defined).
My guess is therefore that swaggo did not parse my securityDefinition annotation at all.

You can see a minimum setup to reproduce this issue in this repository: https://github.com/adrian-sturm/swaggo-test

@adrian-sturm
Copy link
Author

Update:
I was able to resolve the problem by running swag fmt and then swag init again to rebuild the docs.
So in the end it was an error on my side - but I think more people might run into this because the issue was just me having too much whitespace in the annotations: see this commit in my sample repo.
To prevent this it would be good to:

a) Make the swaggo parser more resilient to additional whitespaces
b) Clearly document that swag fmt is mandatory before generating the docs
c) Make swag fmt automatically run on swag init (maybe with a flag to disable it)

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