From 244ec9033c03326d8d49949b6e63dff3315e2451 Mon Sep 17 00:00:00 2001 From: Chinwat K Date: Sat, 23 Mar 2024 10:06:57 +0700 Subject: [PATCH] swagger - set api scheme --- .../kampus/kbazaar/swagger/SwaggerConfig.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 kbazaar/src/main/java/com/kampus/kbazaar/swagger/SwaggerConfig.java diff --git a/kbazaar/src/main/java/com/kampus/kbazaar/swagger/SwaggerConfig.java b/kbazaar/src/main/java/com/kampus/kbazaar/swagger/SwaggerConfig.java new file mode 100644 index 0000000..e7d3d6e --- /dev/null +++ b/kbazaar/src/main/java/com/kampus/kbazaar/swagger/SwaggerConfig.java @@ -0,0 +1,30 @@ +package com.kampus.kbazaar.swagger; + +import io.swagger.v3.oas.models.Components; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.security.SecurityRequirement; +import io.swagger.v3.oas.models.security.SecurityScheme; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class SwaggerConfig { + + private SecurityScheme createAPIKeyScheme() { + return new SecurityScheme() + .type(SecurityScheme.Type.HTTP) + .bearerFormat("JWT") + .scheme("bearer"); + } + + @Bean + public OpenAPI openAPI() { + return new OpenAPI() + .addSecurityItem(new SecurityRequirement().addList("Bearer Authentication")) + .components( + new Components() + .addSecuritySchemes("Bearer Authentication", createAPIKeyScheme())) + .info(new Info().title("KBazaar")); + } +}