-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
524 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
require "json-schema" | ||
|
||
module RBS | ||
class JSONValidator | ||
class Validator | ||
attr_reader :file | ||
|
||
def initialize(name) | ||
@file = Pathname(__dir__) + "../../schema/#{name}.json" | ||
end | ||
|
||
def validate(object, fragment: nil) | ||
JSON::Validator.validate( | ||
file.to_s, | ||
object, | ||
{ fragment: fragment } | ||
) | ||
end | ||
|
||
def validate!(object, fragment: nil) | ||
JSON::Validator.validate!( | ||
file.to_s, | ||
object, | ||
{ fragment: fragment } | ||
) | ||
end | ||
end | ||
|
||
class <<self | ||
def location | ||
Validator.new("location") | ||
end | ||
|
||
def types | ||
Validator.new("types") | ||
end | ||
|
||
def comment | ||
Validator.new("comment") | ||
end | ||
|
||
def method_type | ||
Validator.new("methodType") | ||
end | ||
|
||
def members | ||
Validator.new("members") | ||
end | ||
|
||
def decls | ||
Validator.new("decls") | ||
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
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 |
---|---|---|
@@ -1,14 +1,26 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"definitions": { | ||
"comment": { | ||
"type": "object", | ||
"properties": { | ||
"string": { | ||
"type": "string" | ||
}, | ||
"location": { | ||
"$ref": "location.json" | ||
} | ||
}, | ||
"required": ["string", "location"] | ||
} | ||
}, | ||
"title": "Comment associated with a declaration or a member", | ||
"type": "object", | ||
"properties": { | ||
"string": { | ||
"type": "string" | ||
"oneOf": [ | ||
{ | ||
"$ref": "#/definitions/comment" | ||
}, | ||
"location": { | ||
"$ref": "location.json" | ||
{ | ||
"type": "null" | ||
} | ||
}, | ||
"required": ["string", "location"] | ||
] | ||
} |
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,91 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"definitions": { | ||
"alias": { | ||
"title": "Type alias declaration: `type foo = Integer`, ...", | ||
"type": "object", | ||
"properties": { | ||
"declaration": { | ||
"type": "string", | ||
"enum": ["alias"] | ||
}, | ||
"name": { | ||
"type": "string" | ||
}, | ||
"type": { | ||
"$ref": "types.json" | ||
}, | ||
"annotations": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "annotation.json" | ||
} | ||
}, | ||
"location": { | ||
"$ref": "location.json" | ||
}, | ||
"comment": { | ||
"$ref": "comment.json" | ||
} | ||
}, | ||
"required": ["declaration", "name", "type", "annotations", "location", "comment"] | ||
}, | ||
"constant": { | ||
"title": "Constant declaration: `VERSION: String`, ...", | ||
"type": "object", | ||
"properties": { | ||
"declaration": { | ||
"type": "string", | ||
"enum": ["constant"] | ||
}, | ||
"name": { | ||
"type": "string" | ||
}, | ||
"type": { | ||
"$ref": "types.json" | ||
}, | ||
"location": { | ||
"$ref": "location.json" | ||
}, | ||
"comment": { | ||
"$ref": "comment.json" | ||
} | ||
}, | ||
"required": ["declaration", "name", "type", "comment", "location"] | ||
}, | ||
"global": { | ||
"title": "Global declaration: `$DEBUG: bool`, ...", | ||
"type": "object", | ||
"properties": { | ||
"declaration": { | ||
"type": "string", | ||
"enum": ["global"] | ||
}, | ||
"name": { | ||
"type": "string" | ||
}, | ||
"type": { | ||
"$ref": "types.json" | ||
}, | ||
"location": { | ||
"$ref": "location.json" | ||
}, | ||
"comment": { | ||
"$ref": "comment.json" | ||
} | ||
}, | ||
"required": ["declaration", "name", "type", "comment", "location"] | ||
} | ||
}, | ||
"oneOf": [ | ||
{ | ||
"$ref": "#/definitions/alias" | ||
}, | ||
{ | ||
"$ref": "#/definitions/constant" | ||
}, | ||
{ | ||
"$ref": "#/definitions/global" | ||
} | ||
] | ||
} |
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.