Skip to content

Commit

Permalink
fix: apply json schema format
Browse files Browse the repository at this point in the history
  • Loading branch information
iwaltgen committed Feb 28, 2022
1 parent 4732f33 commit 85c4447
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ internal object JsonSchemaConstraints {
internal fun StringSchema.Builder.applyFormat(descriptor: AbstractDescriptor) = apply {
formatValidator(
descriptor.attributes.format?.let {
when (it) {
when (val format = it.lowercase()) {
DataFormat.DATETIME.lowercase() -> FormatValidator.forFormat("date-time")
else -> FormatValidator.forFormat(it.lowercase())
else -> FormatValidator.forFormat(format)
}
} ?: FormatValidator.NONE
)
}

internal fun NumberSchema.Builder.applyFormat(descriptor: AbstractDescriptor) = apply {
when (descriptor.attributes.format) {
when (descriptor.attributes.format?.lowercase()) {
DataFormat.INT32.lowercase(), DataFormat.INT64.lowercase() -> requiresInteger(true)
else -> Unit
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import java.math.BigDecimal
internal object SchemaExtensions {

internal fun Schema<*>.applyProperties(descriptor: AbstractDescriptor) = apply {
when (descriptor.attributes.format) {
when (val format = descriptor.attributes.format?.lowercase()) {
DataFormat.DATETIME.lowercase() -> format("date-time")
is String -> format(descriptor.attributes.format)
is String -> format(format)
else -> Unit
}
}
Expand Down

0 comments on commit 85c4447

Please sign in to comment.