Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sabljakovich/19e4c4ea7f27aff00b8119eca5d9edeb to your computer and use it in GitHub Desktop.
Save sabljakovich/19e4c4ea7f27aff00b8119eca5d9edeb to your computer and use it in GitHub Desktop.
Adds basic auth authorization option to a specific endpoint
@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