Skip to content

Commit

Permalink
refactor: FieldDescription에 optional 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
belljun3395 committed Dec 12, 2024
1 parent e29f921 commit 9ed83d2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
1 change: 1 addition & 0 deletions web/src/testFixtures/kotlin/web/helper/FieldDescription.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ package web.helper
class FieldDescription(
val path: String,
val description: String,
val optional: Boolean = false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9ed83d2

Please sign in to comment.