From 1eeb15fddfed6e12ac06cadbea60e59fea86d955 Mon Sep 17 00:00:00 2001 From: kugu98 Date: Fri, 4 Apr 2025 14:19:26 +0900 Subject: [PATCH 1/2] feature: simplify ignored field --- .../io/github/lcomment/korestdocs/spec/FieldsSpec.kt | 12 +++--------- .../lcomment/korestdocs/spec/FieldsSpecBuilder.kt | 9 +++++++++ .../lcomment/korestdocs/spec/FieldsSpecTest.kt | 7 +++---- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/korest-docs-core/src/main/kotlin/io/github/lcomment/korestdocs/spec/FieldsSpec.kt b/korest-docs-core/src/main/kotlin/io/github/lcomment/korestdocs/spec/FieldsSpec.kt index 76baf39..4cdb544 100644 --- a/korest-docs-core/src/main/kotlin/io/github/lcomment/korestdocs/spec/FieldsSpec.kt +++ b/korest-docs-core/src/main/kotlin/io/github/lcomment/korestdocs/spec/FieldsSpec.kt @@ -45,15 +45,6 @@ abstract class FieldsSpec : DocumentSpec { this.field(path, description, example, T::class, attributes) } - inline fun ignoredField( - path: String, - description: String?, - example: T, - attributes: Map = mapOf("optional" to false, "ignored" to true), - ) { - this.field(path, description, example, T::class, attributes) - } - inline fun subsectionField( path: String, description: String?, @@ -71,6 +62,8 @@ abstract class FieldsSpec : DocumentSpec { attributes: Map, ) + abstract fun ignoredField(path: String) + abstract fun subsectionField( path: String, description: String?, @@ -83,3 +76,4 @@ abstract class FieldsSpec : DocumentSpec { abstract fun withPrefix(prefix: String, configure: FieldsSpec.() -> Unit) } + diff --git a/korest-docs-core/src/main/kotlin/io/github/lcomment/korestdocs/spec/FieldsSpecBuilder.kt b/korest-docs-core/src/main/kotlin/io/github/lcomment/korestdocs/spec/FieldsSpecBuilder.kt index 5180012..44fe7ff 100644 --- a/korest-docs-core/src/main/kotlin/io/github/lcomment/korestdocs/spec/FieldsSpecBuilder.kt +++ b/korest-docs-core/src/main/kotlin/io/github/lcomment/korestdocs/spec/FieldsSpecBuilder.kt @@ -49,6 +49,14 @@ class FieldsSpecBuilder( add(descriptor) } + override fun ignoredField( + path: String, + ) { + val descriptor = PayloadDocumentation.fieldWithPath(path).ignored() + + add(descriptor) + } + override fun subsectionField( path: String, description: String?, @@ -136,3 +144,4 @@ class FieldsSpecBuilder( ) } } + diff --git a/korest-docs-core/src/test/kotlin/io/github/lcomment/korestdocs/spec/FieldsSpecTest.kt b/korest-docs-core/src/test/kotlin/io/github/lcomment/korestdocs/spec/FieldsSpecTest.kt index 5552d39..7b47334 100644 --- a/korest-docs-core/src/test/kotlin/io/github/lcomment/korestdocs/spec/FieldsSpecTest.kt +++ b/korest-docs-core/src/test/kotlin/io/github/lcomment/korestdocs/spec/FieldsSpecTest.kt @@ -70,12 +70,10 @@ internal class FieldsSpecTest : DescribeSpec({ it("fieldsSpec should have one field") { fieldsSpec.ignoredField( path = "test", - description = "test", - example = example, ) - fieldsSpec.fields.size shouldBe 1 - fieldsSpec.fields["test"] shouldBe example + fieldsSpec.fields.size shouldBe 0 + fieldsSpec.fields["test"] shouldBe null } } } @@ -98,3 +96,4 @@ internal class FieldsSpecTest : DescribeSpec({ } } }) + From ac5d9d4b4902bf46b4eba8e7f8f8d08550eb679a Mon Sep 17 00:00:00 2001 From: lcomment Date: Fri, 4 Apr 2025 15:33:49 +0900 Subject: [PATCH 2/2] refactor: apply ktlint --- .../kotlin/io/github/lcomment/example/controller/ApiSpec.kt | 3 ++- .../kotlin/io/github/lcomment/korestdocs/spec/FieldsSpec.kt | 1 - .../io/github/lcomment/korestdocs/spec/FieldsSpecBuilder.kt | 1 - .../io/github/lcomment/korestdocs/spec/FieldsSpecTest.kt | 1 - 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/example/src/test/kotlin/io/github/lcomment/example/controller/ApiSpec.kt b/example/src/test/kotlin/io/github/lcomment/example/controller/ApiSpec.kt index 7dd73f8..2d955c2 100644 --- a/example/src/test/kotlin/io/github/lcomment/example/controller/ApiSpec.kt +++ b/example/src/test/kotlin/io/github/lcomment/example/controller/ApiSpec.kt @@ -27,6 +27,7 @@ import io.github.lcomment.example.service.ExampleService import io.github.lcomment.korestdocs.mockmvc.KorestDocumentationExtension import io.github.lcomment.korestdocs.mockmvc.documentation import io.github.lcomment.korestdocs.mockmvc.extensions.andDocument +import io.github.lcomment.korestdocs.mockmvc.extensions.multipartWithDocs import io.github.lcomment.korestdocs.mockmvc.extensions.requestWithDocs import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test @@ -149,7 +150,7 @@ internal class ApiSpec { val image2 = MockMultipartFile("images", "", "image/png", "image2".toByteArray()) val request = ExampleMultipartRequest(listOf(image1, image2)) - mockMvc.multipart(HttpMethod.POST, "/example") { + mockMvc.multipartWithDocs(HttpMethod.POST, "/example") { header(HttpHeaders.AUTHORIZATION, "Bearer access-token") file(image1) file(image2) diff --git a/korest-docs-core/src/main/kotlin/io/github/lcomment/korestdocs/spec/FieldsSpec.kt b/korest-docs-core/src/main/kotlin/io/github/lcomment/korestdocs/spec/FieldsSpec.kt index 4cdb544..b7e6eda 100644 --- a/korest-docs-core/src/main/kotlin/io/github/lcomment/korestdocs/spec/FieldsSpec.kt +++ b/korest-docs-core/src/main/kotlin/io/github/lcomment/korestdocs/spec/FieldsSpec.kt @@ -76,4 +76,3 @@ abstract class FieldsSpec : DocumentSpec { abstract fun withPrefix(prefix: String, configure: FieldsSpec.() -> Unit) } - diff --git a/korest-docs-core/src/main/kotlin/io/github/lcomment/korestdocs/spec/FieldsSpecBuilder.kt b/korest-docs-core/src/main/kotlin/io/github/lcomment/korestdocs/spec/FieldsSpecBuilder.kt index 44fe7ff..715866b 100644 --- a/korest-docs-core/src/main/kotlin/io/github/lcomment/korestdocs/spec/FieldsSpecBuilder.kt +++ b/korest-docs-core/src/main/kotlin/io/github/lcomment/korestdocs/spec/FieldsSpecBuilder.kt @@ -144,4 +144,3 @@ class FieldsSpecBuilder( ) } } - diff --git a/korest-docs-core/src/test/kotlin/io/github/lcomment/korestdocs/spec/FieldsSpecTest.kt b/korest-docs-core/src/test/kotlin/io/github/lcomment/korestdocs/spec/FieldsSpecTest.kt index 7b47334..6fae6ec 100644 --- a/korest-docs-core/src/test/kotlin/io/github/lcomment/korestdocs/spec/FieldsSpecTest.kt +++ b/korest-docs-core/src/test/kotlin/io/github/lcomment/korestdocs/spec/FieldsSpecTest.kt @@ -96,4 +96,3 @@ internal class FieldsSpecTest : DescribeSpec({ } } }) -