Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16] swagger 추가 #19

Merged
merged 3 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,31 @@ repositories {
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
// Project Common Dependency Start --------------------------------------
// Spring Boot Web
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'

// Spring JPA
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'

// Spring Security
implementation 'org.springframework.boot:spring-boot-starter-security'

// Xml bind
implementation 'jakarta.xml.bind:jakarta.xml.bind-api:4.0.0'
implementation 'org.glassfish.jaxb:jaxb-runtime:4.0.0'

// openapi 3.0
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.6.0'

// lombok
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'
// Project Common Dependency End ----------------------------------------

// test dependency
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
Expand Down
59 changes: 59 additions & 0 deletions src/main/java/org/example/commerce_site/config/OpenApiConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.example.commerce_site.config;

import java.util.ArrayList;
import java.util.List;

import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.servers.Server;

@Configuration
public class OpenApiConfig {

@Value("${springdoc.server-url}")
private String serverUrl;

@Bean
public OpenAPI openAPI() {
List<Server> serverList = new ArrayList<>();
serverList.add(new Server().url(serverUrl));

Info info = new Info()
.title("Commerce Site")
.version("1.0")
.description("Commerce Site API Documentation");

return new OpenAPI()
.info(info)
.servers(serverList);
}

@Bean
public GroupedOpenApi userOpenApi() {
String[] paths = {"/user/**"};
return GroupedOpenApi.builder().group("USER API").pathsToMatch(paths).build();
}

@Bean
public GroupedOpenApi partnerOpenApi() {
String[] paths = {"/partner/**"};
return GroupedOpenApi.builder().group("PARTNER API").pathsToMatch(paths).build();
}

@Bean
public GroupedOpenApi productOpenApi() {
String[] paths = {"/product/**"};
return GroupedOpenApi.builder().group("PRODUCT API").pathsToMatch(paths).build();
}

@Bean
public GroupedOpenApi categoryOpenApi() {
String[] paths = {"/category/**"};
return GroupedOpenApi.builder().group("CATEGORY API").pathsToMatch(paths).build();
}
}
11 changes: 0 additions & 11 deletions src/main/resources/application-dev.yml

This file was deleted.

11 changes: 0 additions & 11 deletions src/main/resources/application-local.yml

This file was deleted.

16 changes: 16 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ spring:
application:
name: commerce_site
instance-id: 0
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/ecommerce_site
username: root
password: 8cfv67b67af12zxc
jpa:
show-sql: true
properties:
hibernate:
format_sql: true
hibernate:
naming:
physical-strategy: org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy
Expand All @@ -14,3 +23,10 @@ spring:
server:
port: 8080
forward-headers-strategy: framework
springdoc:
version: v1.0.0
api-docs:
path: /api-docs/json
default-produces-media-type: application/json;charset=UTF-8
default-consumes-media-type: application/json;charset=UTF-8
server-url: http://localhost:8080
Loading