From 521a40adf0c9a3f6b349982d06303b3335107ccb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Gorej?= Date: Thu, 8 Jun 2023 14:34:24 +0200 Subject: [PATCH] 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 --- src/core/plugins/json-schema-2020-12/samples-extensions/fn.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/plugins/json-schema-2020-12/samples-extensions/fn.js b/src/core/plugins/json-schema-2020-12/samples-extensions/fn.js index aeacefcc..d0e71ebe 100644 --- a/src/core/plugins/json-schema-2020-12/samples-extensions/fn.js +++ b/src/core/plugins/json-schema-2020-12/samples-extensions/fn.js @@ -819,10 +819,10 @@ export const sampleFromSchemaGeneric = ( } } if (typeof value === "string") { - if (typeof schema.maxLength === "number") { + if (Number.isInteger(schema.maxLength) && schema.maxLength > 0) { value = value.slice(0, schema.maxLength) } - if (typeof schema.minLength === "number") { + if (Number.isInteger(schema.minLength) && schema.minLength > 0) { let i = 0 while (value.length < schema.minLength) { value += value[i++ % value.length]