-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
onedayhero-api/src/test/java/com/sixheroes/onedayheroapi/docs/RestDocsSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
14 changes: 14 additions & 0 deletions
14
...hero-api/src/test/resources/org/springframework/restdocs/templates/request-fields.snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}} | ||
|
||
|=== |
14 changes: 14 additions & 0 deletions
14
...ero-api/src/test/resources/org/springframework/restdocs/templates/response-fields.snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}} | ||
|
||
|=== |