-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support custom content encodings and media types
This exposes hooks for the `contentEncoding` and `contentMediaType` keywords, similar to the existing custom formats behavior. The provided callables must return a tuple comprised of a validation boolean and annotation of any type. The validation boolean is ignored in draft 2019-09 and 2020-12, because the [specification][0] says: > They do not function as validation assertions; a malformed string-encoded document MUST NOT cause the containing instance to be considered invalid. Drafts 7 and earlier will return a validation error based on the validation boolean. From the [specification][1]: > Implementations MAY support the "contentMediaType" and "contentEncoding" keywords as validation assertions. All drafts forward the returned annotation as an annotation in the overall result. I don't love the API here, since it requires returning an array even when it's ignored in the latest drafts, but I couldn't come up with anything better. Closes: #137 [0]: https://json-schema.org/draft/2020-12/json-schema-validation#section-8.1 [1]: https://json-schema.org/draft-07/draft-handrews-json-schema-validation-01#rfc.section.8.2
- Loading branch information
1 parent
69fe7a8
commit febaf26
Showing
14 changed files
with
159 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
module JSONSchemer | ||
module ContentEncoding | ||
BASE64 = proc do |instance| | ||
[true, Base64.strict_decode64(instance)] | ||
rescue | ||
[false, nil] | ||
end | ||
end | ||
|
||
module ContentMediaType | ||
JSON = proc do |instance| | ||
[true, ::JSON.parse(instance)] | ||
rescue | ||
[false, nil] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.