fix(json-schema-2020-12-samples): apply string constraints sensibly (#9796)
Refs #9739
This commit is contained in:
@@ -126,7 +126,7 @@ const stringType = (schema, { sample } = {}) => {
|
|||||||
let generatedString
|
let generatedString
|
||||||
|
|
||||||
if (typeof pattern === "string") {
|
if (typeof pattern === "string") {
|
||||||
generatedString = randexp(pattern)
|
generatedString = applyStringConstraints(randexp(pattern), schema)
|
||||||
} else if (typeof format === "string") {
|
} else if (typeof format === "string") {
|
||||||
generatedString = generateFormat(schema)
|
generatedString = generateFormat(schema)
|
||||||
} else if (
|
} else if (
|
||||||
@@ -137,7 +137,7 @@ const stringType = (schema, { sample } = {}) => {
|
|||||||
if (Array.isArray(sample) || typeof sample === "object") {
|
if (Array.isArray(sample) || typeof sample === "object") {
|
||||||
generatedString = JSON.stringify(sample)
|
generatedString = JSON.stringify(sample)
|
||||||
} else {
|
} else {
|
||||||
generatedString = String(sample)
|
generatedString = applyStringConstraints(String(sample), schema)
|
||||||
}
|
}
|
||||||
} else if (typeof contentMediaType === "string") {
|
} else if (typeof contentMediaType === "string") {
|
||||||
const mediaTypeGenerator = mediaTypeAPI(contentMediaType)
|
const mediaTypeGenerator = mediaTypeAPI(contentMediaType)
|
||||||
@@ -145,10 +145,10 @@ const stringType = (schema, { sample } = {}) => {
|
|||||||
generatedString = mediaTypeGenerator(schema)
|
generatedString = mediaTypeGenerator(schema)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
generatedString = randomString()
|
generatedString = applyStringConstraints(randomString(), schema)
|
||||||
}
|
}
|
||||||
|
|
||||||
return encode(applyStringConstraints(generatedString, schema))
|
return encode(generatedString)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default stringType
|
export default stringType
|
||||||
|
|||||||
Reference in New Issue
Block a user