-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds support for OpenAPI 3.0 documents and schemas. There's no published meta schema or dialect that I could find, so the meta schema refs into the published document schema instead. Everything is based off of draft 4. The keywords additions are `nullable` (implemented in `type`), `readOnly`, and `writeOnly`. There are also a couple new formats (`byte` and `binary`). `readOnly` and `writeOnly` are implemented with a new option called `access_mode` that triggers errors for invalid access, ie a `writeOnly` property is present in "read" access mode. It also removes keys from `required` depending on the specified mode. These features are implemented in draft 2020-12 because they seemed like they might be useful elsewhere and they're off by default. `nullable` just adds "null" to the allowed `type` array. You'd probably get better errors with an actual `Nullable` keyword class, but it didn't seem worth it at this point. Related: - #55
- Loading branch information
1 parent
ac13635
commit de9de96
Showing
13 changed files
with
2,028 additions
and
33 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
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,30 @@ | ||
# frozen_string_literal: true | ||
module JSONSchemer | ||
module Draft202012 | ||
module Vocab | ||
module MetaData | ||
class ReadOnly < Keyword | ||
def error(formatted_instance_location:, **) | ||
"instance at #{formatted_instance_location} is `readOnly`" | ||
end | ||
|
||
def validate(instance, instance_location, keyword_location, context) | ||
valid = parsed != true || !context.access_mode || context.access_mode == 'read' | ||
result(instance, instance_location, keyword_location, valid, :annotation => value) | ||
end | ||
end | ||
|
||
class WriteOnly < Keyword | ||
def error(formatted_instance_location:, **) | ||
"instance at #{formatted_instance_location} is `writeOnly`" | ||
end | ||
|
||
def validate(instance, instance_location, keyword_location, context) | ||
valid = parsed != true || !context.access_mode || context.access_mode == 'write' | ||
result(instance, instance_location, keyword_location, valid, :annotation => value) | ||
end | ||
end | ||
end | ||
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
Oops, something went wrong.