feat(samples): add base64url support for contentEncoding keyword (#9246)
This change is JSON Schema 2020-12 specific.
This commit is contained in:
committed by
GitHub
parent
20c2c74746
commit
fb65508eb4
@@ -9,6 +9,7 @@ import encodeQuotedPrintable from "../encoders/quoted-printable"
|
||||
import encodeBase16 from "../encoders/base16"
|
||||
import encodeBase32 from "../encoders/base32"
|
||||
import encodeBase64 from "../encoders/base64"
|
||||
import encodeBase64Url from "../encoders/base64url"
|
||||
|
||||
class EncoderRegistry extends Registry {
|
||||
#defaults = {
|
||||
@@ -19,6 +20,7 @@ class EncoderRegistry extends Registry {
|
||||
base16: encodeBase16,
|
||||
base32: encodeBase32,
|
||||
base64: encodeBase64,
|
||||
base64url: encodeBase64Url,
|
||||
}
|
||||
|
||||
data = { ...this.#defaults }
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* @prettier
|
||||
*/
|
||||
const encodeBase64Url = (content) => Buffer.from(content).toString("base64url")
|
||||
|
||||
export default encodeBase64Url
|
||||
@@ -138,6 +138,15 @@ describe("sampleFromSchema", () => {
|
||||
).toStrictEqual(
|
||||
"aHR0cHM6Ly9leGFtcGxlLmNvbS9kaWN0aW9uYXJ5L3t0ZXJtOjF9L3t0ZXJtfQ=="
|
||||
)
|
||||
expect(
|
||||
sample({
|
||||
type: "string",
|
||||
format: "uri-template",
|
||||
contentEncoding: "base64url",
|
||||
})
|
||||
).toStrictEqual(
|
||||
"aHR0cHM6Ly9leGFtcGxlLmNvbS9kaWN0aW9uYXJ5L3t0ZXJtOjF9L3t0ZXJtfQ"
|
||||
)
|
||||
expect(
|
||||
sample({
|
||||
type: "string",
|
||||
|
||||
Reference in New Issue
Block a user