Skip to content

Commit 71d1354

Browse files
authored
Merge pull request #26 from BGMSound/develop
[Refactor] Unify default emitter to WebTestClient and upgrade to Java 21
2 parents ea3700b + 1d3e65c commit 71d1354

45 files changed

Lines changed: 184 additions & 638 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/deploy-to-mavencentral.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ jobs:
1616
steps:
1717
- name: GitHub 리포지토리 체크아웃
1818
uses: actions/checkout@v6
19-
- name: JDK 17 설치
19+
- name: JDK 21 설치
2020
uses: actions/setup-java@v5
2121
with:
2222
distribution: 'adopt'
23-
java-version: '17'
23+
java-version: '21'
2424
- name: Gradle 애드온 준비하기
2525
uses: gradle/gradle-build-action@v3
2626
- name: 프로젝트 빌드

.github/workflows/pull-request-coverage-report.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ jobs:
1616
steps:
1717
- name: GitHub 리포지토리 체크아웃
1818
uses: actions/checkout@v6
19-
- name: JDK 17 설치
19+
- name: JDK 21 설치
2020
uses: actions/setup-java@v5
2121
with:
2222
distribution: 'adopt'
23-
java-version: '17'
23+
java-version: '21'
2424
- name: Gradle 애드온 준비하기
2525
uses: gradle/gradle-build-action@v3
2626
- name: 커버리지 측정 및 리포트 생성

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ It combines the advantages of both Swagger and RestDocs for efficient and intuit
88

99
## Installation and Getting Started
1010
### Installation
11+
12+
This library requires `spring-restdocs-webtestclient` to be declared explicitly
13+
in your project, as it is no longer transitively provided.
14+
15+
```kotlin
16+
dependencies {
17+
testImplementation("org.springframework.restdocs:spring-restdocs-webtestclient")
18+
}
19+
```
20+
1121
Add the following dependency to your `build.gradle.kts` file:
1222
<br><br>
1323
`MVC`
@@ -92,7 +102,7 @@ fun documentationGetApi() {
92102
responseBody {
93103
field("testField", "test", "test")
94104
}
95-
}.expect(jsonPath("$testField").value("test"))
105+
}.jsonPath("$testField").value("test")
96106
}
97107
```
98108

build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ subprojects {
4242
}
4343
tasks {
4444
java {
45-
sourceCompatibility = JavaVersion.VERSION_17
46-
targetCompatibility = JavaVersion.VERSION_17
45+
sourceCompatibility = JavaVersion.VERSION_21
46+
targetCompatibility = JavaVersion.VERSION_21
4747
}
4848
withType<KotlinCompile> {
4949
compilerOptions {
5050
freeCompilerArgs.add("-Xjsr305=strict")
51-
jvmTarget.set(JvmTarget.JVM_17)
51+
jvmTarget.set(JvmTarget.JVM_21)
5252
}
5353
}
5454
test {
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
dependencies {
2-
implementation(libs.spring.boot.starter.test)
32
implementation(libs.restdocs.api.spec)
43
implementation(libs.jackson.databind)
54
implementation(libs.jackson.datatype.jsr310)
6-
compileOnly(libs.spring.restdocs.mockmvc)
5+
compileOnly(libs.spring.boot.starter.test)
6+
compileOnly(libs.spring.restdocs.webtestclient)
77
compileOnly(libs.spring.boot.starter.web)
8-
compileOnly(libs.spring.boot.starter.webflux)
98
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package io.github.bgmsound.documentify.core
2+
3+
import io.github.bgmsound.documentify.core.emitter.DocumentEmitter
4+
import io.github.bgmsound.documentify.core.emitter.EmitterFactory
5+
import io.github.bgmsound.documentify.core.environment.ApplicationContextEnvironment.Companion.applicationContextEnvironment
6+
import io.github.bgmsound.documentify.core.environment.DocumentContextEnvironment
7+
import io.github.bgmsound.documentify.core.environment.WebTestClientContextEnvironment.Companion.webTestClientEnvironment
8+
import io.github.bgmsound.documentify.core.specification.schema.document.DocumentSpec
9+
import org.springframework.context.ApplicationContext
10+
import org.springframework.restdocs.RestDocumentationContextProvider
11+
import org.springframework.test.web.reactive.server.WebTestClient
12+
import org.springframework.web.context.WebApplicationContext
13+
14+
abstract class AbstractDocumentify {
15+
protected lateinit var provider: RestDocumentationContextProvider
16+
protected lateinit var environment: DocumentContextEnvironment
17+
protected var customEmitter: DocumentEmitter? = null
18+
19+
fun documentation(
20+
name: String,
21+
specCustomizer: DocumentSpec.() -> Unit
22+
): WebTestClient.BodyContentSpec {
23+
val documentSpec = DocumentSpec(name).also { specCustomizer(it) }
24+
val emitter = customEmitter ?: EmitterFactory.of(provider, documentSpec, environment)
25+
26+
return emitter.emit()
27+
}
28+
29+
fun emitter(
30+
customEmitter: DocumentEmitter
31+
) {
32+
this.customEmitter = customEmitter
33+
}
34+
35+
fun webTestClient(
36+
provider: RestDocumentationContextProvider,
37+
webTestClient: WebTestClient
38+
) {
39+
this.provider = provider
40+
environment = webTestClientEnvironment(provider, webTestClient)
41+
}
42+
43+
fun applicationContext(
44+
provider: RestDocumentationContextProvider,
45+
applicationContext: ApplicationContext
46+
) {
47+
this.provider = provider
48+
environment = applicationContextEnvironment(provider, applicationContext)
49+
}
50+
51+
fun webApplicationContext(
52+
provider: RestDocumentationContextProvider,
53+
context: WebApplicationContext
54+
) {
55+
environment = applicationContextEnvironment(provider, context)
56+
this.provider = provider
57+
}
58+
}

documentify-project/documentify-core/src/main/kotlin/io/github/bgmsound/documentify/core/emitter/AbstractDocumentEmitter.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ package io.github.bgmsound.documentify.core.emitter
33
import com.epages.restdocs.apispec.ResourceDocumentation
44
import com.epages.restdocs.apispec.ResourceSnippetParameters
55
import com.epages.restdocs.apispec.Schema
6+
import io.github.bgmsound.documentify.core.emitter.WebTestClientDocumentResult.Companion.validateWith
67
import io.github.bgmsound.documentify.core.specification.schema.document.DocumentSpec
78
import io.github.bgmsound.documentify.core.specification.schema.response.ResponseSpec
89
import org.springframework.restdocs.RestDocumentationContextProvider
910
import org.springframework.restdocs.snippet.Snippet
11+
import org.springframework.test.web.reactive.server.WebTestClient.BodyContentSpec
1012

1113
abstract class AbstractDocumentEmitter(
1214
protected val provider: RestDocumentationContextProvider,
@@ -27,4 +29,16 @@ abstract class AbstractDocumentEmitter(
2729
}
2830
return ResourceDocumentation.resource(resourceBuilder.build())
2931
}
32+
33+
override fun emit(): BodyContentSpec {
34+
val validatableDocumentResponse = emitDocument()
35+
emitAlternativeResponseDocument()
36+
validatableDocumentResponse.validateWith(documentSpec.response)
37+
38+
return validatableDocumentResponse
39+
}
40+
41+
abstract fun emitDocument(): BodyContentSpec
42+
43+
abstract fun emitAlternativeResponseDocument()
3044
}

documentify-project/documentify-mvc/src/main/kotlin/io/github/bgmsound/documentify/mvc/emitter/AlternativeMvcResponseDocumentController.kt renamed to documentify-project/documentify-core/src/main/kotlin/io/github/bgmsound/documentify/core/emitter/AlternativeResponseDocumentController.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
package io.github.bgmsound.documentify.mvc.emitter
1+
package io.github.bgmsound.documentify.core.emitter
22

33
import org.springframework.http.ResponseEntity
4-
import org.springframework.web.bind.annotation.*
4+
import org.springframework.web.bind.annotation.DeleteMapping
5+
import org.springframework.web.bind.annotation.GetMapping
6+
import org.springframework.web.bind.annotation.PatchMapping
7+
import org.springframework.web.bind.annotation.PostMapping
8+
import org.springframework.web.bind.annotation.PutMapping
9+
import org.springframework.web.bind.annotation.RequestMapping
10+
import org.springframework.web.bind.annotation.RestController
511

612
@RestController
713
@RequestMapping("/**")
8-
class AlternativeMvcResponseDocumentController private constructor(
14+
class AlternativeResponseDocumentController private constructor(
915
status: Int,
1016
response: Any
1117
) {
@@ -40,8 +46,8 @@ class AlternativeMvcResponseDocumentController private constructor(
4046
fun new(
4147
status: Int,
4248
response: Any
43-
): AlternativeMvcResponseDocumentController {
44-
return AlternativeMvcResponseDocumentController(status, response)
49+
): AlternativeResponseDocumentController {
50+
return AlternativeResponseDocumentController(status, response)
4551
}
4652
}
4753
}
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
package io.github.bgmsound.documentify.core.emitter
22

3-
interface DocumentEmitter
3+
import org.springframework.test.web.reactive.server.WebTestClient.BodyContentSpec
4+
5+
interface DocumentEmitter {
6+
7+
fun emit(): BodyContentSpec
8+
9+
}

documentify-project/documentify-reactive/src/main/kotlin/io/github/bgmsound/documentify/reactive/emitter/EmitterFactory.kt renamed to documentify-project/documentify-core/src/main/kotlin/io/github/bgmsound/documentify/core/emitter/EmitterFactory.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
package io.github.bgmsound.documentify.reactive.emitter
1+
package io.github.bgmsound.documentify.core.emitter
22

3+
import io.github.bgmsound.documentify.core.environment.DocumentContextEnvironment
34
import io.github.bgmsound.documentify.core.specification.schema.document.DocumentSpec
4-
import io.github.bgmsound.documentify.reactive.ReactiveDocumentContextEnvironment
55
import org.springframework.restdocs.RestDocumentationContextProvider
66

77
object EmitterFactory {
88
fun of(
99
provider: RestDocumentationContextProvider,
1010
documentSpec: DocumentSpec,
11-
environment: ReactiveDocumentContextEnvironment
12-
): ReactiveDocumentEmitter {
13-
return WebTestClientReactiveDocumentEmitter(provider, documentSpec, environment)
11+
environment: DocumentContextEnvironment
12+
): DocumentEmitter {
13+
return WebTestClientDocumentEmitter(provider, documentSpec, environment)
1414
}
1515
}

0 commit comments

Comments
 (0)