Skip to content

Commit

Permalink
feat: swagger 구현#9
Browse files Browse the repository at this point in the history
  • Loading branch information
SubiHwang committed Jan 14, 2024
1 parent 6bca9bd commit 2188aca
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ repositories {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.4'
implementation 'org.springframework.boot:spring-boot-starter-security'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.mysql:mysql-connector-j'
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/com/endlesshorses/oot/swagger/SecurityConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.endlesshorses.oot.swagger;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;

@Configuration
@EnableWebSecurity
public class SecurityConfig {
private static final String[] AUTH_WHITELIST = {
"/api/**", "/graphiql", "/graphql",
"/swagger-ui/**", "/api-docs", "/swagger-ui-custom.html",
"/v3/api-docs/**", "/api-docs/**", "/swagger-ui.html"
};

@Bean
public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {
return httpSecurity
.authorizeHttpRequests(
authorize -> authorize
.shouldFilterAllDispatcherTypes(false)
.requestMatchers(AUTH_WHITELIST)
.permitAll()
.anyRequest()
.authenticated()
)
.httpBasic().disable()
.formLogin().disable()
.cors().disable()
.csrf().disable()
.build();
}

}
48 changes: 48 additions & 0 deletions src/main/java/com/endlesshorses/oot/swagger/SwaggerConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.endlesshorses.oot.swagger;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SwaggerConfig {

@Bean
public GroupedOpenApi getItemApi() {

return GroupedOpenApi
.builder()
.group("item")
.pathsToMatch("/api/item/**")
.build();
}

@Bean
public GroupedOpenApi getMemberApi() {

return GroupedOpenApi
.builder()
.group("member")
.pathsToMatch("/api/member/**")
.build();

}

@Bean
public OpenAPI getOpenApi() {

return new OpenAPI().components(new Components())
.info(getInfo());

}

private Info getInfo() {
return new Info()
.version("1.0.0")
.description("COMMERCE REST API DOC")
.title("COMMERCE");
}
}

0 comments on commit 2188aca

Please sign in to comment.