Skip to content

Commit 7e6d678

Browse files
committed
Chore : Spring Rest Docs
Spring Rest Docs와 관련된 의존성 및 gradle 설정을 완료 테스트를 위한 샘플 api 코드를 생성 api-dcs.html을 생성하기 위한 api-dcs.adoc을 생성 ** mockMvc를 이용해 테스트하는 과정에서 DecribeSpec을 사용하면 Autowired가 불가능한 이슈가 있어 해결 필요**
1 parent ef70cfc commit 7e6d678

File tree

11 files changed

+728
-6
lines changed

11 files changed

+728
-6
lines changed

.gitignore

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
HELP.md
22
.gradle
3-
build/*
4-
!build/reports/
5-
build/reports/*
6-
!build/reports/jacoco
3+
gradle
4+
build
75
!gradle/wrapper/gradle-wrapper.jar
86
!**/src/main/**/build/
97
!**/src/test/**/build/

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SpringKotlinTemplate
22
[![codecov](https://codecov.io/gh/BEOKS/SpringKotlinTemplate/branch/main/graph/badge.svg?token=75JRE4VYJ1)](https://codecov.io/gh/BEOKS/SpringKotlinTemplate)
3+
[api page](https://htmlpreview.github.io/?https://github.com/BEOKS/SpringKotlinTemplate/tree/main/src/main/resources/static/api-dcs.html)
34

45
새로운 Kotlin 기반의 Spring 프로젝트를 시작할 때 사용할 템플릿 레포지토리입니다.
56
# Contents

build.gradle.kts

+54-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2-
32
plugins {
43
id("org.springframework.boot") version "2.7.4"
54
id("io.spring.dependency-management") version "1.0.14.RELEASE"
65
id("jacoco")
6+
id("org.asciidoctor.jvm.convert") version "3.3.2"
77
kotlin("jvm") version "1.6.21"
88
kotlin("plugin.spring") version "1.6.21"
99
}
@@ -15,10 +15,14 @@ repositories {
1515
mavenCentral()
1616
}
1717

18+
1819
dependencies {
1920
implementation("org.springframework.boot:spring-boot-starter")
2021
implementation("org.jetbrains.kotlin:kotlin-reflect")
2122
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
23+
implementation("org.springframework.boot:spring-boot-starter-web:2.7.5")
24+
testImplementation("org.springframework.restdocs:spring-restdocs-asciidoctor:2.0.6.RELEASE")
25+
testImplementation("org.springframework.restdocs:spring-restdocs-mockmvc:2.0.6.RELEASE")
2226
testImplementation("org.springframework.boot:spring-boot-starter-test")
2327
testImplementation("io.kotest:kotest-runner-junit5:5.5.2")
2428
testImplementation("io.kotest:kotest-assertions-core:5.5.2")
@@ -53,7 +57,7 @@ fun ConfigurableFileCollection.excludeSpringBootApplicationClass(){
5357
tasks.jacocoTestReport {
5458
reports {
5559
html.required.set(true)
56-
xml.required.set(true) //For CodeCoverage
60+
xml.required.set(false)
5761
csv.required.set(false)
5862
}
5963
classDirectories.excludeSpringBootApplicationClass()
@@ -85,4 +89,52 @@ tasks.jacocoTestCoverageVerification {
8589
}
8690
}
8791
}
92+
}
93+
//Spring Rest Docs
94+
tasks {
95+
val snippetsDir = file("$buildDir/generated-snippets")
96+
97+
clean {
98+
delete("src/main/resources/static/docs")
99+
}
100+
101+
test {
102+
useJUnitPlatform()
103+
systemProperty("org.springframework.restdocs.outputDir", snippetsDir)
104+
outputs.dir(snippetsDir)
105+
}
106+
107+
build {
108+
dependsOn("copyDocument")
109+
}
110+
111+
asciidoctor {
112+
dependsOn(test)
113+
114+
attributes(
115+
mapOf("snippets" to snippetsDir)
116+
)
117+
inputs.dir(snippetsDir)
118+
119+
doFirst {
120+
delete("src/main/resources/static/docs")
121+
}
122+
}
123+
124+
register<Copy>("copyDocument") {
125+
dependsOn(asciidoctor)
126+
127+
destinationDir = file(".")
128+
from(asciidoctor.get().outputDir) {
129+
into("src/main/resources/static/docs")
130+
}
131+
}
132+
133+
bootJar {
134+
dependsOn(asciidoctor)
135+
136+
from(asciidoctor.get().outputDir) {
137+
into("BOOT-INF/classes/static/docs")
138+
}
139+
}
88140
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="ko"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>TestArithmeticOperator</title><script type="text/javascript" src="../jacoco-resources/sort.js"></script></head><body onload="initialSort(['breadcrumb'])"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">SpringKotlinTemplate</a> &gt; <a href="index.html" class="el_package">com.example.springkotlintemplate.Sample.CoverageTestCode</a> &gt; <span class="el_class">TestArithmeticOperator</span></div><h1>TestArithmeticOperator</h1><table class="coverage" cellspacing="0" id="coveragetable"><thead><tr><td class="sortable" id="a" onclick="toggleSort(this)">Element</td><td class="down sortable bar" id="b" onclick="toggleSort(this)">Missed Instructions</td><td class="sortable ctr2" id="c" onclick="toggleSort(this)">Cov.</td><td class="sortable bar" id="d" onclick="toggleSort(this)">Missed Branches</td><td class="sortable ctr2" id="e" onclick="toggleSort(this)">Cov.</td><td class="sortable ctr1" id="f" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="g" onclick="toggleSort(this)">Cxty</td><td class="sortable ctr1" id="h" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="i" onclick="toggleSort(this)">Lines</td><td class="sortable ctr1" id="j" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="k" onclick="toggleSort(this)">Methods</td></tr></thead><tfoot><tr><td>Total</td><td class="bar">0 of 19</td><td class="ctr2">100%</td><td class="bar">0 of 0</td><td class="ctr2">n/a</td><td class="ctr1">0</td><td class="ctr2">5</td><td class="ctr1">0</td><td class="ctr2">5</td><td class="ctr1">0</td><td class="ctr2">5</td></tr></tfoot><tbody><tr><td id="a3"><a href="TestArithmeticOperator.kt.html#L7" class="el_method">plus(int, int)</a></td><td class="bar" id="b0"><img src="../jacoco-resources/greenbar.gif" width="120" height="10" title="4" alt="4"/></td><td class="ctr2" id="c0">100%</td><td class="bar" id="d0"/><td class="ctr2" id="e0">n/a</td><td class="ctr1" id="f0">0</td><td class="ctr2" id="g0">1</td><td class="ctr1" id="h0">0</td><td class="ctr2" id="i0">1</td><td class="ctr1" id="j0">0</td><td class="ctr2" id="k0">1</td></tr><tr><td id="a1"><a href="TestArithmeticOperator.kt.html#L10" class="el_method">minus(int, int)</a></td><td class="bar" id="b1"><img src="../jacoco-resources/greenbar.gif" width="120" height="10" title="4" alt="4"/></td><td class="ctr2" id="c1">100%</td><td class="bar" id="d1"/><td class="ctr2" id="e1">n/a</td><td class="ctr1" id="f1">0</td><td class="ctr2" id="g1">1</td><td class="ctr1" id="h1">0</td><td class="ctr2" id="i1">1</td><td class="ctr1" id="j1">0</td><td class="ctr2" id="k1">1</td></tr><tr><td id="a2"><a href="TestArithmeticOperator.kt.html#L13" class="el_method">multiply(int, int)</a></td><td class="bar" id="b2"><img src="../jacoco-resources/greenbar.gif" width="120" height="10" title="4" alt="4"/></td><td class="ctr2" id="c2">100%</td><td class="bar" id="d2"/><td class="ctr2" id="e2">n/a</td><td class="ctr1" id="f2">0</td><td class="ctr2" id="g2">1</td><td class="ctr1" id="h2">0</td><td class="ctr2" id="i2">1</td><td class="ctr1" id="j2">0</td><td class="ctr2" id="k2">1</td></tr><tr><td id="a0"><a href="TestArithmeticOperator.kt.html#L16" class="el_method">divide(int, int)</a></td><td class="bar" id="b3"><img src="../jacoco-resources/greenbar.gif" width="120" height="10" title="4" alt="4"/></td><td class="ctr2" id="c3">100%</td><td class="bar" id="d3"/><td class="ctr2" id="e3">n/a</td><td class="ctr1" id="f3">0</td><td class="ctr2" id="g3">1</td><td class="ctr1" id="h3">0</td><td class="ctr2" id="i3">1</td><td class="ctr1" id="j3">0</td><td class="ctr2" id="k3">1</td></tr><tr><td id="a4"><a href="TestArithmeticOperator.kt.html#L5" class="el_method">TestArithmeticOperator()</a></td><td class="bar" id="b4"><img src="../jacoco-resources/greenbar.gif" width="90" height="10" title="3" alt="3"/></td><td class="ctr2" id="c4">100%</td><td class="bar" id="d4"/><td class="ctr2" id="e4">n/a</td><td class="ctr1" id="f4">0</td><td class="ctr2" id="g4">1</td><td class="ctr1" id="h4">0</td><td class="ctr2" id="i4">1</td><td class="ctr1" id="j4">0</td><td class="ctr2" id="k4">1</td></tr></tbody></table><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.8.202204050719</span></div></body></html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="ko"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>TestArithmeticOperator.kt</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">SpringKotlinTemplate</a> &gt; <a href="index.source.html" class="el_package">com.example.springkotlintemplate.Sample.CoverageTestCode</a> &gt; <span class="el_source">TestArithmeticOperator.kt</span></div><h1>TestArithmeticOperator.kt</h1><pre class="source lang-java linenums">package com.example.springkotlintemplate.Sample.CoverageTestCode
2+
3+
import com.example.springkotlintemplate.Sample.CoverageTestCode.ArithmeticOperator
4+
5+
<span class="fc" id="L5">class TestArithmeticOperator : ArithmeticOperator {</span>
6+
override fun plus(a:Int, b:Int): Int{
7+
<span class="fc" id="L7"> return a+b;</span>
8+
}
9+
override fun minus(a:Int, b:Int): Int {
10+
<span class="fc" id="L10"> return a-b</span>
11+
}
12+
override fun multiply(a:Int, b:Int): Int {
13+
<span class="fc" id="L13"> return a*b</span>
14+
}
15+
override fun divide(a:Int, b:Int): Int {
16+
<span class="fc" id="L16"> return a/b</span>
17+
}
18+
}
19+
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.8.202204050719</span></div></body></html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="ko"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>com.example.springkotlintemplate.Sample.CoverageTestCode</title><script type="text/javascript" src="../jacoco-resources/sort.js"></script></head><body onload="initialSort(['breadcrumb', 'coveragetable'])"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="index.source.html" class="el_source">Source Files</a><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">SpringKotlinTemplate</a> &gt; <span class="el_package">com.example.springkotlintemplate.Sample.CoverageTestCode</span></div><h1>com.example.springkotlintemplate.Sample.CoverageTestCode</h1><table class="coverage" cellspacing="0" id="coveragetable"><thead><tr><td class="sortable" id="a" onclick="toggleSort(this)">Element</td><td class="down sortable bar" id="b" onclick="toggleSort(this)">Missed Instructions</td><td class="sortable ctr2" id="c" onclick="toggleSort(this)">Cov.</td><td class="sortable bar" id="d" onclick="toggleSort(this)">Missed Branches</td><td class="sortable ctr2" id="e" onclick="toggleSort(this)">Cov.</td><td class="sortable ctr1" id="f" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="g" onclick="toggleSort(this)">Cxty</td><td class="sortable ctr1" id="h" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="i" onclick="toggleSort(this)">Lines</td><td class="sortable ctr1" id="j" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="k" onclick="toggleSort(this)">Methods</td><td class="sortable ctr1" id="l" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="m" onclick="toggleSort(this)">Classes</td></tr></thead><tfoot><tr><td>Total</td><td class="bar">0 of 19</td><td class="ctr2">100%</td><td class="bar">0 of 0</td><td class="ctr2">n/a</td><td class="ctr1">0</td><td class="ctr2">5</td><td class="ctr1">0</td><td class="ctr2">5</td><td class="ctr1">0</td><td class="ctr2">5</td><td class="ctr1">0</td><td class="ctr2">1</td></tr></tfoot><tbody><tr><td id="a0"><a href="TestArithmeticOperator.html" class="el_class">TestArithmeticOperator</a></td><td class="bar" id="b0"><img src="../jacoco-resources/greenbar.gif" width="120" height="10" title="19" alt="19"/></td><td class="ctr2" id="c0">100%</td><td class="bar" id="d0"/><td class="ctr2" id="e0">n/a</td><td class="ctr1" id="f0">0</td><td class="ctr2" id="g0">5</td><td class="ctr1" id="h0">0</td><td class="ctr2" id="i0">5</td><td class="ctr1" id="j0">0</td><td class="ctr2" id="k0">5</td><td class="ctr1" id="l0">0</td><td class="ctr2" id="m0">1</td></tr></tbody></table><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.8.202204050719</span></div></body></html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="ko"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>com.example.springkotlintemplate.Sample.CoverageTestCode</title><script type="text/javascript" src="../jacoco-resources/sort.js"></script></head><body onload="initialSort(['breadcrumb', 'coveragetable'])"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="index.html" class="el_class">Classes</a><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">SpringKotlinTemplate</a> &gt; <span class="el_package">com.example.springkotlintemplate.Sample.CoverageTestCode</span></div><h1>com.example.springkotlintemplate.Sample.CoverageTestCode</h1><table class="coverage" cellspacing="0" id="coveragetable"><thead><tr><td class="sortable" id="a" onclick="toggleSort(this)">Element</td><td class="down sortable bar" id="b" onclick="toggleSort(this)">Missed Instructions</td><td class="sortable ctr2" id="c" onclick="toggleSort(this)">Cov.</td><td class="sortable bar" id="d" onclick="toggleSort(this)">Missed Branches</td><td class="sortable ctr2" id="e" onclick="toggleSort(this)">Cov.</td><td class="sortable ctr1" id="f" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="g" onclick="toggleSort(this)">Cxty</td><td class="sortable ctr1" id="h" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="i" onclick="toggleSort(this)">Lines</td><td class="sortable ctr1" id="j" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="k" onclick="toggleSort(this)">Methods</td><td class="sortable ctr1" id="l" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="m" onclick="toggleSort(this)">Classes</td></tr></thead><tfoot><tr><td>Total</td><td class="bar">0 of 19</td><td class="ctr2">100%</td><td class="bar">0 of 0</td><td class="ctr2">n/a</td><td class="ctr1">0</td><td class="ctr2">5</td><td class="ctr1">0</td><td class="ctr2">5</td><td class="ctr1">0</td><td class="ctr2">5</td><td class="ctr1">0</td><td class="ctr2">1</td></tr></tfoot><tbody><tr><td id="a0"><a href="TestArithmeticOperator.kt.html" class="el_source">TestArithmeticOperator.kt</a></td><td class="bar" id="b0"><img src="../jacoco-resources/greenbar.gif" width="120" height="10" title="19" alt="19"/></td><td class="ctr2" id="c0">100%</td><td class="bar" id="d0"/><td class="ctr2" id="e0">n/a</td><td class="ctr1" id="f0">0</td><td class="ctr2" id="g0">5</td><td class="ctr1" id="h0">0</td><td class="ctr2" id="i0">5</td><td class="ctr1" id="j0">0</td><td class="ctr2" id="k0">5</td><td class="ctr1" id="l0">0</td><td class="ctr2" id="m0">1</td></tr></tbody></table><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.8.202204050719</span></div></body></html>

src/docs/asciidoc/api-dcs.adoc

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
ifndef::snippets[]
2+
:snippets: ../../../build/generated-snippets
3+
endif::[]
4+
= Application Name
5+
:toc: left
6+
:toclevels: 2
7+
:sectlinks:
8+
9+
10+
[[resources-developer-find]]
11+
=== 조회 API
12+
13+
==== HTTP request
14+
include::{snippets}/find-developer/path-parameters.adoc[]
15+
include::{snippets}/find-developer/http-request.adoc[]
16+
17+
==== HTTP response
18+
include::{snippets}/find-developer/response-fields.adoc[]
19+
include::{snippets}/find-developer/response-body.adoc[]
20+
include::{snippets}/find-developer/http-response.adoc[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.example.springkotlintemplate.Sample.RestDocsTest
2+
3+
import org.springframework.http.ResponseEntity
4+
import org.springframework.stereotype.Controller
5+
import org.springframework.web.bind.annotation.GetMapping
6+
import org.springframework.web.bind.annotation.PathVariable
7+
8+
data class SampleResponse(
9+
val email: String="이메일",
10+
val name: String="이름",
11+
val introduction:String="소개",
12+
val pictureUrl:String="사진경로",
13+
val point:String="점수",
14+
val popularity:String="인기도")
15+
@Controller
16+
class RestDocsSampleController {
17+
@GetMapping("api/{email}")
18+
fun sample(@PathVariable email: String): ResponseEntity<SampleResponse> {
19+
return ResponseEntity.ok(SampleResponse(email = email))
20+
}
21+
}

0 commit comments

Comments
 (0)