feat(json-schema-2020-12): add support for validation keywords for arrays (#8626)
Includes following keywords: - maxItems - maxItems - uniqueItems - maxContains - minContains Refs #8513
This commit is contained in:
@@ -9,17 +9,18 @@ import { useFn, useComponent } from "../../hooks"
|
|||||||
const Contains = ({ schema }) => {
|
const Contains = ({ schema }) => {
|
||||||
const fn = useFn()
|
const fn = useFn()
|
||||||
const JSONSchema = useComponent("JSONSchema")
|
const JSONSchema = useComponent("JSONSchema")
|
||||||
const name = (
|
|
||||||
<span className="json-schema-2020-12-keyword__name json-schema-2020-12-keyword__name--primary">
|
|
||||||
Contains
|
|
||||||
</span>
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rendering.
|
* Rendering.
|
||||||
*/
|
*/
|
||||||
if (!fn.hasKeyword(schema, "contains")) return null
|
if (!fn.hasKeyword(schema, "contains")) return null
|
||||||
|
|
||||||
|
const name = (
|
||||||
|
<span className="json-schema-2020-12-keyword__name json-schema-2020-12-keyword__name--primary">
|
||||||
|
Contains
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="json-schema-2020-12-keyword json-schema-2020-12-keyword--contains">
|
<div className="json-schema-2020-12-keyword json-schema-2020-12-keyword--contains">
|
||||||
<JSONSchema name={name} schema={schema.contains} />
|
<JSONSchema name={name} schema={schema.contains} />
|
||||||
|
|||||||
@@ -256,19 +256,33 @@ export const stringifyConstraints = (schema) => {
|
|||||||
const constraints = []
|
const constraints = []
|
||||||
|
|
||||||
// validation Keywords for Numeric Instances (number and integer)
|
// validation Keywords for Numeric Instances (number and integer)
|
||||||
const constraintMultipleOf = stringifyConstraintMultipleOf(schema)
|
const multipleOf = stringifyConstraintMultipleOf(schema)
|
||||||
if (constraintMultipleOf !== null) constraints.push(constraintMultipleOf)
|
if (multipleOf !== null) constraints.push(multipleOf)
|
||||||
const constraintNumberRange = stringifyConstraintNumberRange(schema)
|
const numberRange = stringifyConstraintNumberRange(schema)
|
||||||
if (constraintNumberRange !== null) constraints.push(constraintNumberRange)
|
if (numberRange !== null) constraints.push(numberRange)
|
||||||
|
|
||||||
// validation Keywords for Strings
|
// validation Keywords for Strings
|
||||||
const constraintStringRange = stringifyConstraintRange(
|
const stringRange = stringifyConstraintRange(
|
||||||
"characters",
|
"characters",
|
||||||
schema?.minLength,
|
schema?.minLength,
|
||||||
schema?.maxLength
|
schema?.maxLength
|
||||||
)
|
)
|
||||||
if (constraintStringRange !== null) constraints.push(constraintStringRange)
|
if (stringRange !== null) constraints.push(stringRange)
|
||||||
if (schema?.pattern) constraints.push(`matches ${schema?.pattern}`)
|
if (schema?.pattern) constraints.push(`matches ${schema?.pattern}`)
|
||||||
|
|
||||||
|
// validation Keywords for Arrays
|
||||||
|
const arrayRange = stringifyConstraintRange(
|
||||||
|
schema?.hasUniqueItems ? "unique items" : "items",
|
||||||
|
schema?.minItems,
|
||||||
|
schema?.maxItems
|
||||||
|
)
|
||||||
|
if (arrayRange !== null) constraints.push(arrayRange)
|
||||||
|
const containsRange = stringifyConstraintRange(
|
||||||
|
"contained items",
|
||||||
|
schema?.minContains,
|
||||||
|
schema?.maxContains
|
||||||
|
)
|
||||||
|
if (containsRange !== null) constraints.push(containsRange)
|
||||||
|
|
||||||
return constraints
|
return constraints
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user