Skip to content

Commit

Permalink
feat(samples): add base64url support for contentEncoding keyword (#9246)
Browse files Browse the repository at this point in the history
This change is JSON Schema 2020-12 specific.
  • Loading branch information
bschoenmaeckers committed Nov 13, 2023
1 parent 20c2c74 commit fb65508
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -19,6 +20,7 @@ class EncoderRegistry extends Registry {
base16: encodeBase16,
base32: encodeBase32,
base64: encodeBase64,
base64url: encodeBase64Url,
}

data = { ...this.#defaults }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @prettier
*/
const encodeBase64Url = (content) => Buffer.from(content).toString("base64url")

export default encodeBase64Url
9 changes: 9 additions & 0 deletions test/unit/core/plugins/json-schema-2020-12-samples/fn.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ describe("sampleFromSchema", () => {
).toStrictEqual(
"aHR0cHM6Ly9leGFtcGxlLmNvbS9kaWN0aW9uYXJ5L3t0ZXJtOjF9L3t0ZXJtfQ=="
)
expect(
sample({
type: "string",
format: "uri-template",
contentEncoding: "base64url",
})
).toStrictEqual(
"aHR0cHM6Ly9leGFtcGxlLmNvbS9kaWN0aW9uYXJ5L3t0ZXJtOjF9L3t0ZXJtfQ"
)
expect(
sample({
type: "string",
Expand Down

0 comments on commit fb65508

Please sign in to comment.