Skip to content

Commit

Permalink
feat: apply field optional (#244)
Browse files Browse the repository at this point in the history
* feat: apply field optional

* fix lint
  • Loading branch information
xeromank authored Aug 25, 2023
1 parent de0c1ab commit 4c735ca
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ internal object ConstraintResolver {
.minOrNull()
}

internal fun isRequired(fieldDescriptor: FieldDescriptor): Boolean =
findConstraints(fieldDescriptor)
.any { constraint -> REQUIRED_CONSTRAINTS.contains(constraint.name) }
internal fun isRequired(fieldDescriptor: FieldDescriptor): Boolean = findConstraints(fieldDescriptor)
.any { constraint ->
REQUIRED_CONSTRAINTS.contains(constraint.name)
} || !fieldDescriptor.optional

private fun findConstraints(fieldDescriptor: FieldDescriptor): List<Constraint> =
fieldDescriptor.attributes.validationConstraints
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ class JsonSchemaFromFieldDescriptorsGeneratorTest {
),

FieldDescriptor("lineItems[*].quantity.unit", "some", "STRING"),
FieldDescriptor("shippingAddress", "some", "OBJECT"),
FieldDescriptor("shippingAddress", "some", "OBJECT", true),
FieldDescriptor("billingAddress", "some", "OBJECT"),
FieldDescriptor(
"billingAddress.firstName", "some", "STRING",
Expand Down Expand Up @@ -732,6 +732,7 @@ class JsonSchemaFromFieldDescriptorsGeneratorTest {
"pagePositive",
"some",
"NUMBER",
true,
attributes = Attributes(
listOf(
Constraint(
Expand Down

0 comments on commit 4c735ca

Please sign in to comment.