Skip to content

Commit 88b2094

Browse files
committed
fix(json-schema-2020-12-samples): apply string constraints sensibly
Refs #9739
1 parent 7db9c98 commit 88b2094

File tree

1 file changed

+4
-4
lines changed
  • src/core/plugins/json-schema-2020-12-samples/fn/types

1 file changed

+4
-4
lines changed

Diff for: src/core/plugins/json-schema-2020-12-samples/fn/types/string.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ const stringType = (schema, { sample } = {}) => {
126126
let generatedString
127127

128128
if (typeof pattern === "string") {
129-
generatedString = randexp(pattern)
129+
generatedString = applyStringConstraints(randexp(pattern), schema)
130130
} else if (typeof format === "string") {
131131
generatedString = generateFormat(schema)
132132
} else if (
@@ -137,18 +137,18 @@ const stringType = (schema, { sample } = {}) => {
137137
if (Array.isArray(sample) || typeof sample === "object") {
138138
generatedString = JSON.stringify(sample)
139139
} else {
140-
generatedString = String(sample)
140+
generatedString = applyStringConstraints(String(sample), schema)
141141
}
142142
} else if (typeof contentMediaType === "string") {
143143
const mediaTypeGenerator = mediaTypeAPI(contentMediaType)
144144
if (typeof mediaTypeGenerator === "function") {
145145
generatedString = mediaTypeGenerator(schema)
146146
}
147147
} else {
148-
generatedString = randomString()
148+
generatedString = applyStringConstraints(randomString(), schema)
149149
}
150150

151-
return encode(applyStringConstraints(generatedString, schema))
151+
return encode(generatedString)
152152
}
153153

154154
export default stringType

0 commit comments

Comments
 (0)