Created
January 1, 2021 22:21
-
-
Save sabljakovich/19e4c4ea7f27aff00b8119eca5d9edeb to your computer and use it in GitHub Desktop.
Adds basic auth authorization option to a specific endpoint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
@SecurityScheme( | |
name = "basicAuth", // can be set to anything | |
type = SecuritySchemeType.HTTP, | |
scheme = "basic" | |
) | |
@OpenAPIDefinition( | |
info = @Info(title = "Sample API", version = "v1") | |
) | |
class DocsConfiguration { | |
} | |
// Controller usage example | |
@Tag(name = "Transactions") | |
@RestController | |
@RequestMapping("/transactions") | |
class TransactionsController { | |
@GetMapping() | |
public String getLogs() { | |
return ""; | |
} | |
// name refereces value defined in the line 3 | |
@Operation(security = @SecurityRequirement(name = "basicAuth")) | |
@GetMapping("/health") | |
public String getHealth() { | |
return "Ok"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment