Skip to content

Commit

Permalink
Merge pull request #7 from UMC-7-Time-Lapse/docs/#6
Browse files Browse the repository at this point in the history
docs: 스웨거 설정 완료
  • Loading branch information
oxdjww authored Jul 4, 2024
2 parents e5651a3 + 060b698 commit 3f8536d
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,24 @@ repositories {
}

dependencies {
// core
implementation 'org.springframework.boot:spring-boot-starter-web'

// jpa
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'com.mysql:mysql-connector-j'

// lombok
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

// test
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

// swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.4'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-api:2.0.4'
}

tasks.named('test') {
Expand Down
52 changes: 52 additions & 0 deletions src/main/java/com/hackathon/TimeLapse/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.hackathon.TimeLapse.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

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.info.License;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.servers.Server;

@Configuration
public class SwaggerConfig {
// url : http://localhost:8080/swagger-ui/index.html#/
private static final String SECURITY_SCHEME_NAME = "bearerAuth";

@Bean
public OpenAPI api() {
Server server = new Server().url("/");

return new OpenAPI()
.addSecurityItem(new SecurityRequirement().addList(SECURITY_SCHEME_NAME))
.components(authSetting())
.info(getSwaggerInfo())
.addServersItem(server);
}

private Info getSwaggerInfo() {
License license = new License();
license.setName("{Application}");

return new Info()
.title("TimeLapse API Document")
.description("TimeLapse의 API 문서 입니다.")
.version("v1.0")
.license(license);
}

private Components authSetting() {

return new Components()
.addSecuritySchemes(SECURITY_SCHEME_NAME,
new SecurityScheme()
.name(SECURITY_SCHEME_NAME)
.type(SecurityScheme.Type.HTTP)
.scheme("bearer")
.bearerFormat("JWT"));
}
}

Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package com.hackathon.TimeLapse.test;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.tags.Tag;

@Tag(name = "API", description = "Test API 입니다.")
@RequestMapping("/test")
@RestController
public class TestController {

Expand Down

0 comments on commit 3f8536d

Please sign in to comment.