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

Update path transform to make the security key optional #179

Merged
merged 7 commits into from
Sep 1, 2021

Conversation

gandazgul
Copy link
Contributor

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Test
  • Docs
  • Refactor
  • Build-related changes
  • Other, please describe:

Description:

If the security key is present in a path, Swagger will take that definition over the global security one. Without this change we are always adding this key and disabling security for all paths that don't have the @security tag.

Modified the transform for a path to only set the security key when values are found in the @security tag.

If the security key is present in a path swagger will take that definition over the global security one. By always adding this key we are disabling security globally. Modified the transform for a path to only set the key when values are found.
feat(security): Added the ability to disable security

By adding an empty @security tag to the jsdoc block for a path
@gandazgul
Copy link
Contributor Author

Hold on reviewing this, your tests are failing because of nothing I did. So I will submit a different PR to fix those so that this one is clean.

These tests broke. I'm not sure why only making a change in
transforms/paths/index.js under the parsePath response
triggers the failures.
@gandazgul
Copy link
Contributor Author

Merge this first: #180

Copy link
Member

@kevinccbsg kevinccbsg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR

@kevinccbsg kevinccbsg merged commit 62de8aa into BRIKEV:master Sep 1, 2021
@kevinccbsg
Copy link
Member

Thanks, @gandazgul we will try to do a new release asap with your changes 🚀

@gandazgul gandazgul deleted the patch-1 branch September 2, 2021 12:43
@gandazgul
Copy link
Contributor Author

Awesome thank you!

@paulish
Copy link
Contributor

paulish commented Sep 9, 2021

Seems this MR introduces a breaking change: now all methods have security (with explicit @security ... declaration and without it) definition if server security set. Now you need to explicitly add empty @security declaration to remove method security.

@kevinccbsg
Copy link
Member

🤔 Thanks @paulish, we will have a look today and we revert or fix the problem.

@kevinccbsg
Copy link
Member

@gandazgul we have to revert this as we cannot allow adding security without setting explicitly on each endpoint as OpenAPI does. The only way I would say this would work is by adding a config option to enable this behavior. In that case, this won't affect old versions.

@gandazgul
Copy link
Contributor Author

gandazgul commented Sep 11, 2021 via email

@gandazgul
Copy link
Contributor Author

gandazgul commented Sep 18, 2021

Seems this MR introduces a breaking change: now all methods have security (with explicit @security ... declaration and without it) definition if server security set. Now you need to explicitly add empty @security declaration to remove method security.

It might be breaking but it aligns with Swagger

When used on the root level, security applies the specified security schemes globally to all API operations, unless overridden on the operation level.

Global security can be overridden in individual operations to use a different authentication type, different OAuth/OpenID scopes, or no authentication at all and if you see the example disabling global security for a path requires to add security: []

This library before my fix was adding the empty security array to all endpoints which in turn disabled security. Now it doesn't it takes the global one and it can be override locally including disabling by adding an empty @security tag which aligns with how Swagger works.

Edit: adding Swagger docs link on security: https://swagger.io/docs/specification/authentication/

@paulish
Copy link
Contributor

paulish commented Sep 19, 2021

@gandazgul the problem is that before your changes library had another behavior and projects which used this library relied on that old behavior. As a solution (I did not look at the MR core) I would suggest to add a new option to use new behavior which is disabled by default. With a new major release change the default behavior if needed and deprecate the option. In the next major release remove the option at all.

Also such breaking changes must be well documented.

@richiksc
Copy link

Specifying @security annotation on each route can become convoluted on large APIs. The change (which has now been reverted, it seems) brought the behavior of the generator in line with the Swagger/OpenAPI spec and how most new users of the library would expect it to behave. This change should be merged back in and either disabled by an option, or better yet a new major version should be released with this breaking change. It is the "proper" behavior for an OpenAPI tool.

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

Successfully merging this pull request may close these issues.

None yet

4 participants