Skip to content

Commit

Permalink
fix(json-schema-2020-12): fix rendering of exclusiveMin|Max keywords (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
char0n authored Jul 17, 2023
1 parent b0d937e commit 70d7986
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/core/plugins/json-schema-2020-12/fn.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,22 +231,25 @@ const stringifyConstraintNumberRange = (schema) => {
const hasMaximum = typeof maximum === "number"
const hasExclusiveMinimum = typeof exclusiveMinimum === "number"
const hasExclusiveMaximum = typeof exclusiveMaximum === "number"
const isMinExclusive = hasExclusiveMinimum && minimum < exclusiveMinimum
const isMaxExclusive = hasExclusiveMaximum && maximum > exclusiveMaximum
const isMinExclusive = hasExclusiveMinimum && (!hasMinimum || minimum < exclusiveMinimum) // prettier-ignore
const isMaxExclusive = hasExclusiveMaximum && (!hasMaximum || maximum > exclusiveMaximum) // prettier-ignore

if (hasMinimum && hasMaximum) {
if (
(hasMinimum || hasExclusiveMinimum) &&
(hasMaximum || hasExclusiveMaximum)
) {
const minSymbol = isMinExclusive ? "(" : "["
const maxSymbol = isMaxExclusive ? ")" : "]"
const minValue = isMinExclusive ? exclusiveMinimum : minimum
const maxValue = isMaxExclusive ? exclusiveMaximum : maximum
return `${minSymbol}${minValue}, ${maxValue}${maxSymbol}`
}
if (hasMinimum) {
if (hasMinimum || hasExclusiveMinimum) {
const minSymbol = isMinExclusive ? ">" : "≥"
const minValue = isMinExclusive ? exclusiveMinimum : minimum
return `${minSymbol} ${minValue}`
}
if (hasMaximum) {
if (hasMaximum || hasExclusiveMaximum) {
const maxSymbol = isMaxExclusive ? "<" : "≤"
const maxValue = isMaxExclusive ? exclusiveMaximum : maximum
return `${maxSymbol} ${maxValue}`
Expand Down

0 comments on commit 70d7986

Please sign in to comment.