From 9ed83d2aff5a76fc9c9f5f8d84e54328c25664af Mon Sep 17 00:00:00 2001 From: belljun3395 <195850@jnu.ac.kr> Date: Thu, 12 Dec 2024 15:19:33 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20FieldDescription=EC=97=90=20optiona?= =?UTF-8?q?l=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/web/helper/FieldDescription.kt | 1 + .../helper/PayloadDocumentationExtension.kt | 36 +++++++++++++++---- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/web/src/testFixtures/kotlin/web/helper/FieldDescription.kt b/web/src/testFixtures/kotlin/web/helper/FieldDescription.kt index e46669102..06e4066da 100644 --- a/web/src/testFixtures/kotlin/web/helper/FieldDescription.kt +++ b/web/src/testFixtures/kotlin/web/helper/FieldDescription.kt @@ -3,4 +3,5 @@ package web.helper class FieldDescription( val path: String, val description: String, + val optional: Boolean = false, ) \ No newline at end of file diff --git a/web/src/testFixtures/kotlin/web/helper/PayloadDocumentationExtension.kt b/web/src/testFixtures/kotlin/web/helper/PayloadDocumentationExtension.kt index 4e45c4a6e..873b3f415 100644 --- a/web/src/testFixtures/kotlin/web/helper/PayloadDocumentationExtension.kt +++ b/web/src/testFixtures/kotlin/web/helper/PayloadDocumentationExtension.kt @@ -29,26 +29,50 @@ fun FieldDescriptor.fieldWithNull(description: String): FieldDescriptor { } fun FieldDescription.asObject(): FieldDescriptor { - return PayloadDocumentation.fieldWithPath(this.path).fieldWithObject(this.description) + val descriptor = PayloadDocumentation.fieldWithPath(this.path).fieldWithObject(this.description) + if (this.optional) { + return descriptor.optional() + } + return descriptor } fun FieldDescription.asArray(): FieldDescriptor { - return PayloadDocumentation.fieldWithPath(this.path).fieldWithArray(this.description) + val descriptor = PayloadDocumentation.fieldWithPath(this.path).fieldWithArray(this.description) + if (this.optional) { + return descriptor.optional() + } + return descriptor } fun FieldDescription.asString(): FieldDescriptor { - return PayloadDocumentation.fieldWithPath(this.path).fieldWithString(this.description) + val descriptor = PayloadDocumentation.fieldWithPath(this.path).fieldWithString(this.description) + if (this.optional) { + return descriptor.optional() + } + return descriptor } fun FieldDescription.asNumber(): FieldDescriptor { - return PayloadDocumentation.fieldWithPath(this.path).fieldWithNumber(this.description) + val descriptor = PayloadDocumentation.fieldWithPath(this.path).fieldWithNumber(this.description) + if (this.optional) { + return descriptor.optional() + } + return descriptor } fun FieldDescription.asBoolean(): FieldDescriptor { - return PayloadDocumentation.fieldWithPath(this.path).fieldWithBoolean(this.description) + val descriptor = PayloadDocumentation.fieldWithPath(this.path).fieldWithBoolean(this.description) + if (this.optional) { + return descriptor.optional() + } + return descriptor } fun FieldDescription.asNull(): FieldDescriptor { - return PayloadDocumentation.fieldWithPath(this.path).fieldWithNull(this.description) + val descriptor = PayloadDocumentation.fieldWithPath(this.path).fieldWithNull(this.description) + if (this.optional) { + return descriptor.optional() + } + return descriptor } class PayloadDocumentationExtension \ No newline at end of file