Skip to content

Commit

Permalink
SB-261 (Feat) : 통합 Swagger API 구현
Browse files Browse the repository at this point in the history
SB-261 (Feat) : 통합 Swagger API 구현
  • Loading branch information
Jyuung committed Aug 18, 2024
1 parent 68caa54 commit c49bb07
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Make docker-compose.yml
run: echo "${{ secrets.DOCKER_COMPOSE }}" > docker-compose.yml

- name: Make Warehouse application.yml
- name: Make Gateway application.yml
run: |
cd ./gateway/src/main/resources
echo "${{ secrets.GATEWAY_APPLICATION }}" > application.yml
Expand Down
4 changes: 3 additions & 1 deletion delivery/src/main/java/delivery/DeliveryApplication.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package delivery;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.servers.Server;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

//@OpenAPIDefinition(servers = {@Server(url = "https://baobab.run", description = "fx server 연습용 도메인")})
@OpenAPIDefinition(servers = {@Server(url = "https://baobab.run/delivery/", description = "Baobab Dev Server API")})
@SpringBootApplication
public class DeliveryApplication {

Expand Down
37 changes: 37 additions & 0 deletions delivery/src/main/java/delivery/common/config/web/WebConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package delivery.common.config.web;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import java.util.Collections;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

@Value("${file.upload-dir}")
private String uploadDir;

@Bean
public OpenAPI swaggerAuthorization() {
SecurityScheme securityScheme = new SecurityScheme()
.type(SecurityScheme.Type.HTTP).scheme("bearer").bearerFormat("JWT")
.in(SecurityScheme.In.HEADER).name("Authorization");
SecurityRequirement securityRequirement = new SecurityRequirement().addList("bearerAuth");

return new OpenAPI()
.components(new Components().addSecuritySchemes("bearerAuth", securityScheme))
.security(Collections.singletonList(securityRequirement));
}

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/images/**")
.addResourceLocations("file:" + uploadDir);
}
}
2 changes: 2 additions & 0 deletions gateway/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ ext {

dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
implementation 'org.springdoc:springdoc-openapi-starter-webflux-ui:2.0.2'
implementation 'org.springdoc:springdoc-openapi-ui:1.7.0'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import warehouse.domain.image.properties.FileStorageProperties;

@OpenAPIDefinition(servers = {@Server(url = "https://baobab.run", description = "fx server 연습용 도메인")})
@OpenAPIDefinition(servers = {@Server(url = "https://baobab.run/warehouse/", description = "Baobab Dev Server API")})
@SpringBootApplication
@EnableConfigurationProperties({
FileStorageProperties.class
Expand Down
17 changes: 17 additions & 0 deletions warehouse/src/main/java/warehouse/common/config/web/WebConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package warehouse.common.config.web;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import java.util.Collections;
import java.util.List;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
Expand Down Expand Up @@ -30,6 +35,18 @@ CorsConfigurationSource corsConfigurationSource() {
return source;
}

@Bean
public OpenAPI swaggerAuthorization() {
SecurityScheme securityScheme = new SecurityScheme()
.type(SecurityScheme.Type.HTTP).scheme("bearer").bearerFormat("JWT")
.in(SecurityScheme.In.HEADER).name("Authorization");
SecurityRequirement securityRequirement = new SecurityRequirement().addList("bearerAuth");

return new OpenAPI()
.components(new Components().addSecuritySchemes("bearerAuth", securityScheme))
.security(Collections.singletonList(securityRequirement));
}

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/images/**")
Expand Down

0 comments on commit c49bb07

Please sign in to comment.