-
-
Notifications
You must be signed in to change notification settings - Fork 524
Disable security for one operation #259
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
Comments
Hi, Can you please add a sample code to reproduce your issue ? |
application annotations:
annotation on controller method:
|
Hi, First of all, please note that we rely on swagger-core official annotations / jars. You have another option, which is to a add the security annotations for the secured operations only. @RestController
@RequestMapping(path = "/demo2",
produces = MediaType.TEXT_PLAIN_VALUE)
@SecurityScheme(
name = "bearerToken",
type = SecuritySchemeType.HTTP,
scheme = "bearer",
bearerFormat = "JWT"
)
public class DemoController {
@PostMapping(value = "/login1", consumes = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Add a new person to the store", description = "", security = {
@SecurityRequirement(name = "bearerToken")})
public Object createAuthenticationToken(
@RequestBody String authenticationRequest) {
return null;
}
@PostMapping(value = "/login3", consumes = MediaType.APPLICATION_JSON_VALUE)
@Operation(description = "hello, no security")
public Object createAuthenticationToken2(
@RequestBody String authenticationRequest) {
return null;
}
} |
Hi, I came across this issue recently. I found a workaround using OpenApiCustomiser, but I would prefer a proper solution. I think it is doable without changes to the swagger-core annotations (not with the Operation annotation, but with an 'empty' SecurityRequirements). It would look like this: @RestController
public class AuthenticationController {
@PostMapping(value = "/login", consumes = MediaType.APPLICATION_JSON_VALUE)
@SecurityRequirements(value = {}) // <- or without 'value', added for clarity
public JwtAuthenticationResponse createAuthenticationToken(
@RequestBody JwtAuthenticationRequest authenticationRequest) {
}
} It doesn't work out of the box, there are some changes needed in the SecurityParser |
@mafor, your PR is welcome. |
Hi @bnasslahsen. Forget it, I see you've done it yourself already. |
Yeah @mafor, i wasn't sure about your feedback. Anyway, the important is that its now shared with the community. |
Hi,
I have a
@OpenAPIDefinition
with security defined for the whole app, but I want to override and disable security for one method, how can I do that?Using
@Operation(security = {})
on the method doesn't seem to work.Expected output in yaml is
security: []
for that one operation.Thanks
The text was updated successfully, but these errors were encountered: