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

[REQ][Spring] Enable scopes for all security scheme types #17085

Closed
kota65535 opened this issue Nov 15, 2023 · 0 comments · Fixed by #17083
Closed

[REQ][Spring] Enable scopes for all security scheme types #17085

kota65535 opened this issue Nov 15, 2023 · 0 comments · Fixed by #17083

Comments

@kota65535
Copy link
Contributor

kota65535 commented Nov 15, 2023

Is your feature request related to a problem? Please describe.

In OpenAPI Specification 3.0.x, the list of scope names of Security Requirement Object MUST be empty if the security scheme type is other than oauth2 or openIdConnect. But in 3.1.0, now it MAY contain role names which are required for the execution.

For other security scheme types, the array MUST be empty.

For other security scheme types, the array MAY contain a list of role names which are required for the execution, but are not otherwise defined or exchanged in-band.

For instance, if we have a operation definition like this:

get:
  operationId: getGreetings
  security:
    - bearer: [ "greetings:read" ]
...

We have the following generated code for each controller now:

    @Operation(
        operationId = "getGreetings",
        security = {
            @SecurityRequirement(name = "bearer")
        }
    ...

But according to OAS 3.1.0, we can have the following generated code:

    @Operation(
        operationId = "getGreetings",
        security = {
            @SecurityRequirement(name = "bearer", scopes={ "greetings:read" })
        }
    ...

Describe the solution you'd like

I've tried custom templates first, but it does not work because the codegen model does not have scope values when security scheme type is other than oauth2 or openIdConnect. So we have to change the generator class to respect the scope values for all security scheme types.

Describe alternatives you've considered

Additional context

I've also made PR swagger-api/swagger-core#4550 to modify the documentation of @SecurityRequirement annotation class to allow the scopes field to have values for all security scheme types.

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

Successfully merging a pull request may close this issue.

1 participant