Skip to content

Commit

Permalink
fix(json-schema-2020-12-samples): apply string constraints sensibly
Browse files Browse the repository at this point in the history
Refs #9739
  • Loading branch information
char0n committed Apr 9, 2024
1 parent 7db9c98 commit 88b2094
Showing 1 changed file with 4 additions and 4 deletions.
Expand Up @@ -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 (
Expand All @@ -137,18 +137,18 @@ 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)
if (typeof mediaTypeGenerator === "function") {
generatedString = mediaTypeGenerator(schema)
}
} else {
generatedString = randomString()
generatedString = applyStringConstraints(randomString(), schema)
}

return encode(applyStringConstraints(generatedString, schema))
return encode(generatedString)
}

export default stringType

0 comments on commit 88b2094

Please sign in to comment.