From b6b0d2879a80154aa7088822e223f4d9f7a8b063 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Gorej?= Date: Tue, 9 Apr 2024 15:58:37 +0200 Subject: [PATCH] fix(json-schema-2020-12-samples): apply string constraints sensibly (#9796) Refs #9739 --- .../json-schema-2020-12-samples/fn/types/string.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/plugins/json-schema-2020-12-samples/fn/types/string.js b/src/core/plugins/json-schema-2020-12-samples/fn/types/string.js index 4c9b33986e5..3fd94481fa4 100644 --- a/src/core/plugins/json-schema-2020-12-samples/fn/types/string.js +++ b/src/core/plugins/json-schema-2020-12-samples/fn/types/string.js @@ -126,7 +126,7 @@ const stringType = (schema, { sample } = {}) => { let generatedString if (typeof pattern === "string") { - generatedString = randexp(pattern) + generatedString = applyStringConstraints(randexp(pattern), schema) } else if (typeof format === "string") { generatedString = generateFormat(schema) } else if ( @@ -137,7 +137,7 @@ const stringType = (schema, { sample } = {}) => { if (Array.isArray(sample) || typeof sample === "object") { generatedString = JSON.stringify(sample) } else { - generatedString = String(sample) + generatedString = applyStringConstraints(String(sample), schema) } } else if (typeof contentMediaType === "string") { const mediaTypeGenerator = mediaTypeAPI(contentMediaType) @@ -145,10 +145,10 @@ const stringType = (schema, { sample } = {}) => { generatedString = mediaTypeGenerator(schema) } } else { - generatedString = randomString() + generatedString = applyStringConstraints(randomString(), schema) } - return encode(applyStringConstraints(generatedString, schema)) + return encode(generatedString) } export default stringType