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