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
  • Loading branch information
char0n authored Apr 9, 2024
1 parent 7db9c98 commit b6b0d28
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
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 b6b0d28

Please sign in to comment.