diff --git a/build.gradle.kts b/build.gradle.kts index 4890b13e..bd4d9ae8 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,6 +2,7 @@ plugins { java id("org.springframework.boot") version "3.5.9" id("io.spring.dependency-management") version "1.1.7" + id("org.asciidoctor.jvm.convert") version "4.0.5" } group = "com.umc" @@ -19,6 +20,7 @@ configurations { compileOnly { extendsFrom(configurations.annotationProcessor.get()) } + create("asciidoctorExt") } repositories { @@ -54,9 +56,6 @@ dependencies { annotationProcessor("com.querydsl:querydsl-apt:${queryDslVersion}:jakarta") annotationProcessor("jakarta.annotation:jakarta.annotation-api") - // APT가 jakarta 클래스를 로딩할 수 있게 명시 - annotationProcessor("jakarta.persistence:jakarta.persistence-api") - // --- Database --- implementation("org.flywaydb:flyway-core") implementation("org.flywaydb:flyway-database-postgresql") @@ -95,8 +94,39 @@ dependencies { testImplementation("org.testcontainers:testcontainers") testImplementation("org.testcontainers:junit-jupiter") testImplementation("org.testcontainers:postgresql") + + // --- Spring REST Docs --- + "asciidoctorExt"("org.springframework.restdocs:spring-restdocs-asciidoctor") + testImplementation("org.springframework.restdocs:spring-restdocs-mockmvc") } tasks.withType { useJUnitPlatform() } + + +val snippetsDir = file("build/generated-snippets") + +tasks.test { + outputs.dir(snippetsDir) + +} + +tasks.asciidoctor { + inputs.dir(snippetsDir) + configurations("asciidoctorExt") + + sources { + include("**/index.adoc") + } + + baseDirFollowsSourceDir() + dependsOn(tasks.test) +} + +tasks.bootJar { + dependsOn(tasks.asciidoctor) + from(tasks.asciidoctor.get().outputDir) { + into("static/docs") + } +} \ No newline at end of file diff --git a/src/docs/asciidoc/index.adoc b/src/docs/asciidoc/index.adoc new file mode 100644 index 00000000..6a3f207c --- /dev/null +++ b/src/docs/asciidoc/index.adoc @@ -0,0 +1,11 @@ +ifndef::snippets[] +:snippets: ../../build/generated-snippets +endif::[] += UMC Product REST API 문서 +:doctype: book +:icons: font +:source-highlighter: highlightjs +:toc: left +:toclevels: 2 +:sectlinks: + diff --git a/src/test/java/com/umc/product/support/DocumentationTest.java b/src/test/java/com/umc/product/support/DocumentationTest.java new file mode 100644 index 00000000..05f430e5 --- /dev/null +++ b/src/test/java/com/umc/product/support/DocumentationTest.java @@ -0,0 +1,31 @@ +package com.umc.product.support; + + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.context.annotation.Import; +import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler; +import org.springframework.test.web.servlet.MockMvc; + +@WebMvcTest( +) +@Import({ + RestDocsConfig.class, +}) +@AutoConfigureMockMvc(addFilters = false) +@AutoConfigureRestDocs +public class DocumentationTest { + + @Autowired + protected MockMvc mockMvc; + + @Autowired + protected RestDocumentationResultHandler restDocsHandler; + + @Autowired + protected ObjectMapper objectMapper; + +} diff --git a/src/test/java/com/umc/product/support/RestDocsConfig.java b/src/test/java/com/umc/product/support/RestDocsConfig.java new file mode 100644 index 00000000..b7c0289a --- /dev/null +++ b/src/test/java/com/umc/product/support/RestDocsConfig.java @@ -0,0 +1,22 @@ +package com.umc.product.support; + +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; +import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler; + +import static org.springframework.restdocs.operation.preprocess.Preprocessors.*; + +@TestConfiguration +public class RestDocsConfig { + + @Bean + public RestDocumentationResultHandler restDocsMockMvcConfigurationCustomizer() { + return MockMvcRestDocumentation.document( + "{class-name}/{method-name}", + preprocessRequest(prettyPrint()), + preprocessResponse(prettyPrint()) + ); + } +} + diff --git a/src/test/java/com/umc/product/support/UseCaseTestSupport.java b/src/test/java/com/umc/product/support/UseCaseTestSupport.java new file mode 100644 index 00000000..32a2d229 --- /dev/null +++ b/src/test/java/com/umc/product/support/UseCaseTestSupport.java @@ -0,0 +1,10 @@ +package com.umc.product.support; + + +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +public abstract class UseCaseTestSupport { + + +} diff --git a/src/test/resources/org/springframework/restdocs/templates/request-fields.snippet b/src/test/resources/org/springframework/restdocs/templates/request-fields.snippet new file mode 100644 index 00000000..91911b24 --- /dev/null +++ b/src/test/resources/org/springframework/restdocs/templates/request-fields.snippet @@ -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}} + +|=== \ No newline at end of file diff --git a/src/test/resources/org/springframework/restdocs/templates/response-fields.snippet b/src/test/resources/org/springframework/restdocs/templates/response-fields.snippet new file mode 100644 index 00000000..457e34d4 --- /dev/null +++ b/src/test/resources/org/springframework/restdocs/templates/response-fields.snippet @@ -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}} + +|=== \ No newline at end of file