refactor(samples): type check string constrains according to spec (#8897)

This change is specific to JSON Schema 2020-12
and OpenAPI 3.1.0.

Refs #8577
This commit is contained in:
Vladimír Gorej
2023-06-08 14:34:24 +02:00
committed by GitHub
parent 6549eff278
commit 521a40adf0

View File

@@ -819,10 +819,10 @@ export const sampleFromSchemaGeneric = (
} }
} }
if (typeof value === "string") { if (typeof value === "string") {
if (typeof schema.maxLength === "number") { if (Number.isInteger(schema.maxLength) && schema.maxLength > 0) {
value = value.slice(0, schema.maxLength) value = value.slice(0, schema.maxLength)
} }
if (typeof schema.minLength === "number") { if (Number.isInteger(schema.minLength) && schema.minLength > 0) {
let i = 0 let i = 0
while (value.length < schema.minLength) { while (value.length < schema.minLength) {
value += value[i++ % value.length] value += value[i++ % value.length]