Skip to content

Commit

Permalink
✨ feat: Swagger curl 도메인 설정
Browse files Browse the repository at this point in the history
Swagger에서 API 요청 시 사용할 도메인을 선택하는 옵션을 추가했습니다.
  • Loading branch information
dlrjs2360 committed Dec 28, 2023
1 parent 0e847d7 commit 2434754
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

@EnableSwagger2
@Configuration
@OpenAPIDefinition(servers = {@Server(url = "/", description = "HowBaChu API Server")})
public class SwaggerConfig {

@Bean
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/com/HowBaChu/howbachu/config/Workaround.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.HowBaChu.howbachu.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.servers.Server;
import org.springframework.stereotype.Component;
import springfox.documentation.oas.web.OpenApiTransformationContext;
import springfox.documentation.oas.web.WebMvcOpenApiTransformationFilter;
import springfox.documentation.spi.DocumentationType;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;

@Component
public class Workaround implements WebMvcOpenApiTransformationFilter {
@Override
public OpenAPI transform(OpenApiTransformationContext<HttpServletRequest> context) {
OpenAPI openAPI = context.getSpecification();
Server localServer = new Server();
localServer.setDescription("local server");
localServer.setUrl("http://localhost:8080");

Server prodHttpsServer = new Server();
prodHttpsServer.setDescription("prod Https Server");
prodHttpsServer.setUrl("https://howbachu.kro.kr");

Server prodHttpServer = new Server();
prodHttpServer.setDescription("prod Http Server");
prodHttpServer.setUrl("http://54.180.26.251:8080");

openAPI.setServers(Arrays.asList(localServer, prodHttpsServer, prodHttpServer));
return openAPI;
}

@Override
public boolean supports(DocumentationType documentationType) {
return documentationType.equals(DocumentationType.OAS_30);
}
}

0 comments on commit 2434754

Please sign in to comment.