Skip to content

Commit

Permalink
feat : Restdocs 관련 설정을 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
bombo-dev committed Oct 26, 2023
1 parent d36b688 commit 450e8a4
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 0 deletions.
41 changes: 41 additions & 0 deletions onedayhero-api/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,50 @@
plugins {
id 'org.asciidoctor.jvm.convert' version '3.3.2'
}

configurations {
asciidoctorExt
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation project(':onedayhero-application')

// RESTDOCS
asciidoctorExt 'org.springframework.restdocs:spring-restdocs-asciidoctor'
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
}

tasks.named('test') {
useJUnitPlatform()
}

// 전역 변수 설정
ext {
snippetsDir = file('build/generated-snippets')
}

test {
outputs.dir snippetsDir
}

asciidoctor {
inputs.dir snippetsDir
configurations 'asciidoctorExt'

// 특정 파일만 html로 생성
sources {
include("**/index.adoc")
}

baseDirFollowsSourceFile() // 다른 adoc 파일 include 시 경로를 baseDir로 맞춘다.
dependsOn test
}

bootJar {
dependsOn asciidoctor
from("${asciidoctor.outputDir}") {
into 'static/docs'
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.sixheroes.onedayheroapi.docs;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.sixheroes.onedayheroapi.global.handler.GlobalExceptionHandler;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.restdocs.RestDocumentationContextProvider;
import org.springframework.restdocs.RestDocumentationExtension;
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.filter.CharacterEncodingFilter;

import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint;

@ExtendWith(RestDocumentationExtension.class)
public abstract class RestDocsSupport {

protected MockMvc mockMvc;
protected ObjectMapper objectMapper = new ObjectMapper();

@BeforeEach
void setup(RestDocumentationContextProvider provider) {
this.mockMvc = MockMvcBuilders.standaloneSetup(setController())
.setControllerAdvice(new GlobalExceptionHandler())
.addFilter(new CharacterEncodingFilter("UTF-8", true))
.apply(MockMvcRestDocumentation.documentationConfiguration(provider)
.operationPreprocessors()
.withRequestDefaults(prettyPrint())
.withResponseDefaults(prettyPrint()))
.build();
}

protected abstract Object setController();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
==== Request Fields
|===
|path|type|Optional|Description

{{#fields}}

|{{#tableCellContent}}`+{{path}}+`{{/tableCellContent}}
|{{#tableCellContent}}`+{{type}}+`{{/tableCellContent}}
|{{#tableCellContent}}{{#optional}}O{{/optional}}{{/tableCellContent}}
|{{#tableCellContent}}{{description}}{{/tableCellContent}}

{{/fields}}

|===
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
==== Response Fields
|===
|path|type|Optional|Description

{{#fields}}

|{{#tableCellContent}}`+{{path}}+`{{/tableCellContent}}
|{{#tableCellContent}}`+{{type}}+`{{/tableCellContent}}
|{{#tableCellContent}}{{#optional}}O{{/optional}}{{/tableCellContent}}
|{{#tableCellContent}}{{description}}{{/tableCellContent}}

{{/fields}}

|===

0 comments on commit 450e8a4

Please sign in to comment.