Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON Schema #295

Merged
merged 3 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/rbs/ast/declarations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ module Declarations
class ModuleTypeParams
attr_reader :params

TypeParam = Struct.new(:name, :variance, :skip_validation, keyword_init: true)
TypeParam = Struct.new(:name, :variance, :skip_validation, keyword_init: true) do
def to_json(*a)
{
name: name,
variance: variance,
skip_validation: skip_validation,
}.to_json(*a)
end
end

def initialize()
@params = []
Expand Down
1 change: 1 addition & 0 deletions rbs.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rubocop-rubycw"
spec.add_development_dependency "minitest-reporters", "~> 1.3.6"
spec.add_development_dependency "json", "~> 2.3.0"
spec.add_development_dependency "json-schema", "~> 2.8"
end
14 changes: 14 additions & 0 deletions schema/annotation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Annotation associated to a declaration or a member: `%a{rbs:test}`, `%a{steep:deprecated}`, ...",
"type": "object",
"properties": {
"string": {
"type": "string"
},
"location": {
"$ref": "location.json"
}
},
"required": ["string", "location"]
}
26 changes: 26 additions & 0 deletions schema/comment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"$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",
"oneOf": [
{
"$ref": "#/definitions/comment"
},
{
"type": "null"
}
]
}
327 changes: 327 additions & 0 deletions schema/decls.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,327 @@
{
"$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"]
},
"moduleTypeParam": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"variance": {
"enum": ["covariant", "contravariant", "invariant"]
},
"skip_validation": {
"type": "boolean"
}
},
"required": ["name", "variance", "skip_validation"]
},
"classMember": {
"oneOf": [
{
"$ref": "members.json#/definitions/methodDefinition"
},
{
"$ref": "members.json#/definitions/variable"
},
{
"$ref": "members.json#/definitions/include"
},
{
"$ref": "members.json#/definitions/extend"
},
{
"$ref": "members.json#/definitions/prepend"
},
{
"$ref": "members.json#/definitions/attribute"
},
{
"$ref": "members.json#/definitions/visibility"
},
{
"$ref": "members.json#/definitions/alias"
}
]
},
"class": {
"title": "Class declaration",
"type": "object",
"properties": {
"declaration": {
"enum": ["class"]
},
"name": {
"type": "string"
},
"type_params": {
"type": "object",
"properties": {
"params": {
"type": "array",
"items": {
"$ref": "#/definitions/moduleTypeParam"
}
}
},
"required": ["params"]
},
"members": {
"type": "array",
"items": {
"$ref": "#/definitions/classMember"
}
},
"super_class": {
"oneOf": [
{
"type": "null"
},
{
"type": "object",
"properties": {
"name": {
"type": "string"
},
"args": {
"type": "array",
"items": {
"$ref": "types.json"
}
}
},
"required": ["name", "args"]
}
]
},
"annotations": {
"type": "array",
"items": {
"$ref": "annotation.json"
}
},
"comment": {
"$ref": "comment.json"
},
"location": {
"$ref": "location.json"
}
},
"required": ["declaration", "name", "type_params", "members", "super_class", "annotations", "comment", "location"]
},
"module": {
"type": "object",
"properties": {
"declaration": {
"enum": ["module"]
},
"name": {
"type": "string"
},
"type_params": {
"type": "object",
"properties": {
"params": {
"type": "array",
"items": {
"$ref": "#/definitions/moduleTypeParam"
}
}
},
"required": ["params"]
},
"members": {
"type": "array",
"items": {
"$ref": "#/definitions/classMember"
}
},
"self_type": {
"oneOf": [
{
"$ref": "types.json"
},
{
"type": "null"
}
]
},
"annotations": {
"type": "array",
"items": {
"$ref": "annotation.json"
}
},
"comment": {
"$ref": "comment.json"
},
"location": {
"$ref": "location.json"
}
},
"required": ["declaration", "name", "type_params", "members", "self_type", "annotations", "location", "comment"]
},
"interfaceMember": {
"oneOf": [
{
"allOf": [
{
"$ref": "members.json#/definitions/methodDefinition"
},
{
"type": "object",
"properties": {
"kind": {
"enum": ["instance"]
}
}
}
]
},
{
"$ref": "members.json#/definitions/include"
},
{
"$ref": "members.json#/definitions/alias"
}
]
},
"interface": {
"type": "object",
"properties": {
"declaration": {
"enum": ["interface"]
},
"name": {
"type": "string"
},
"type_params": {
"type": "object",
"properties": {
"params": {
"type": "array",
"items": {
"$ref": "#/definitions/moduleTypeParam"
}
}
},
"required": ["params"]
},
"members": {
"type": "array",
"items": {
"$ref": "#/definitions/interfaceMember"
}
},
"annotations": {
"type": "array",
"items": {
"$ref": "annotation.json"
}
},
"comment": {
"$ref": "comment.json"
},
"location": {
"$ref": "location.json"
}
},
"required": ["declaration", "name", "type_params", "members", "annotations", "comment", "location"]
}
},
"oneOf": [
{
"$ref": "#/definitions/alias"
},
{
"$ref": "#/definitions/constant"
},
{
"$ref": "#/definitions/global"
},
{
"$ref": "#/definitions/class"
},
{
"$ref": "#/definitions/module"
},
{
"$ref": "#/definitions/interface"
}
]
}
Loading