schai 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/schai/cli.rb +1 -0
- data/lib/schai/json_schema/js_array.rb +26 -0
- data/lib/schai/json_schema/js_object.rb +28 -0
- data/lib/schai/json_schema/js_property.rb +29 -0
- data/lib/schai/json_schema/js_root.rb +38 -0
- data/lib/schai/version.rb +1 -1
- data/lib/schai.rb +23 -2
- data/schai.gemspec +2 -2
- metadata +7 -4
- data/lib/schai/hoge.rb +0 -156
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99670c33c4e1e826924ed5902a5d2143ab5fe033
|
4
|
+
data.tar.gz: 779db26346971a87a519e5f33c4bfecb7103423a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a029ce8f1e7176b5c99ead8dec921d612cd33542f81b40f02167e874856d06a37d7ce28e1dd94968566fe0582fc2410a1191f42bd1142668a0c15d94b2dc3bd9
|
7
|
+
data.tar.gz: 41d4eacd6480a70a29d645222a88a532130708fef0771faa5f7479711c7f0cb707e0371e6a902ee09768dd40712b003c83ff51651022d8ce237ca095b6337ef9
|
data/README.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
# schai
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/schai.svg)](http://badge.fury.io/rb/schai) [![Build Status](https://travis-ci.org/gin0606/schai.svg?branch=master)](https://travis-ci.org/gin0606/schai)
|
4
|
+
|
2
5
|
## Installation
|
3
6
|
|
4
7
|
Add this line to your application's Gemfile:
|
data/lib/schai/cli.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Schai
|
2
|
+
class JsArray
|
3
|
+
attr_accessor :optional, :description, :example, :items
|
4
|
+
|
5
|
+
def self.parse params
|
6
|
+
self.new params
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize params
|
10
|
+
@items = JsProperty.parse params['items']
|
11
|
+
@description = params["description"]
|
12
|
+
@example = params["example"]
|
13
|
+
@optional = params["optional"]
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_schema
|
17
|
+
schema = {
|
18
|
+
type: :array,
|
19
|
+
}
|
20
|
+
schema[:description] = @description if @description
|
21
|
+
schema[:items] = @items.to_schema
|
22
|
+
schema[:example] = @example if @example
|
23
|
+
schema
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Schai
|
2
|
+
class JsObject
|
3
|
+
attr_accessor :optional, :description, :example, :all
|
4
|
+
|
5
|
+
def self.parse params
|
6
|
+
self.new params
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize params
|
10
|
+
@all = Hash[params["properties"].map {|k, v|
|
11
|
+
[k || 'null', JsRoot.parse_components(v)]
|
12
|
+
}]
|
13
|
+
@description = params["description"]
|
14
|
+
@example = params["example"]
|
15
|
+
@optional = params["optional"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_schema
|
19
|
+
schema = {}
|
20
|
+
schema[:type] = :object
|
21
|
+
schema[:description] = @description if @description
|
22
|
+
schema[:properties] = Hash[@all.map {|k, p| [k, p.to_schema]}]
|
23
|
+
schema[:required] = @all.select{|k, p| !p.optional}.map{|k, p| k || 'null'}
|
24
|
+
schema[:example] = @example if @example
|
25
|
+
schema
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Schai
|
2
|
+
class JsProperty
|
3
|
+
attr_accessor :optional, :description, :example, :type, :format
|
4
|
+
|
5
|
+
def self.parse params
|
6
|
+
if params.has_key? 'include'
|
7
|
+
Schai.parse_file(params['include']).schema
|
8
|
+
else
|
9
|
+
self.new params
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize params
|
14
|
+
params.each do |k, v|
|
15
|
+
setter = "#{k}=".to_sym
|
16
|
+
self.send(setter, v)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_schema
|
21
|
+
ret = {}
|
22
|
+
ret[:type] = (@type || 'null').to_sym
|
23
|
+
ret[:format] = @format if @format
|
24
|
+
ret[:description] = @description if @description
|
25
|
+
ret[:example] = @example if @example
|
26
|
+
ret
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Schai
|
2
|
+
class JsRoot
|
3
|
+
attr_accessor :schema
|
4
|
+
|
5
|
+
def self.parse params
|
6
|
+
ret = self.new
|
7
|
+
ret.schema = parse_components params
|
8
|
+
ret
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.parse_components params
|
12
|
+
case
|
13
|
+
when params.has_key?('include')
|
14
|
+
included_schema = Schai.parse_file(params.delete('include')).schema
|
15
|
+
params.each do |k, v|
|
16
|
+
setter = "#{k}=".to_sym
|
17
|
+
included_schema.send(setter, v)
|
18
|
+
end
|
19
|
+
included_schema
|
20
|
+
when params['type'] == 'object'
|
21
|
+
JsObject.parse params
|
22
|
+
when params['type'] == 'array'
|
23
|
+
JsArray.parse params
|
24
|
+
when !params.has_key?('type')
|
25
|
+
raise "typeは必須(#{params})"
|
26
|
+
else
|
27
|
+
JsProperty.parse params
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_schema
|
32
|
+
schema = {
|
33
|
+
'$schema': "http://json-schema.org/draft-04/schema#"
|
34
|
+
}
|
35
|
+
schema.merge @schema.to_schema
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/schai/version.rb
CHANGED
data/lib/schai.rb
CHANGED
@@ -1,7 +1,28 @@
|
|
1
1
|
require "schai/version"
|
2
|
-
require "schai/
|
2
|
+
require "schai/json_schema/js_root"
|
3
|
+
require "schai/json_schema/js_object"
|
4
|
+
require "schai/json_schema/js_array"
|
5
|
+
require "schai/json_schema/js_property"
|
3
6
|
require "schai/cli"
|
7
|
+
require "yaml"
|
4
8
|
|
5
9
|
module Schai
|
6
|
-
|
10
|
+
def self.parse params
|
11
|
+
JsRoot.parse params
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.parse_file path
|
15
|
+
@@path ||=[]
|
16
|
+
if @@path.empty?
|
17
|
+
@@path << path
|
18
|
+
ret = parse YAML.load_file(path)
|
19
|
+
@@path.pop
|
20
|
+
else
|
21
|
+
expand_path = File.expand_path("../#{path}", @@path.last)
|
22
|
+
@@path << expand_path
|
23
|
+
ret = parse YAML.load_file(expand_path)
|
24
|
+
@@path.pop
|
25
|
+
end
|
26
|
+
ret
|
27
|
+
end
|
7
28
|
end
|
data/schai.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["gin0606"]
|
10
10
|
spec.email = ["kkgn06@gmail.com"]
|
11
11
|
|
12
|
-
spec.summary = "
|
13
|
-
spec.description = "
|
12
|
+
spec.summary = "Generate JSON Schema from simple yaml."
|
13
|
+
spec.description = "Generate JSON Schema from simple yaml."
|
14
14
|
spec.homepage = "https://github.com/gin0606/schai"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gin0606
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description:
|
69
|
+
description: Generate JSON Schema from simple yaml.
|
70
70
|
email:
|
71
71
|
- kkgn06@gmail.com
|
72
72
|
executables:
|
@@ -87,7 +87,10 @@ files:
|
|
87
87
|
- bin/setup
|
88
88
|
- lib/schai.rb
|
89
89
|
- lib/schai/cli.rb
|
90
|
-
- lib/schai/
|
90
|
+
- lib/schai/json_schema/js_array.rb
|
91
|
+
- lib/schai/json_schema/js_object.rb
|
92
|
+
- lib/schai/json_schema/js_property.rb
|
93
|
+
- lib/schai/json_schema/js_root.rb
|
91
94
|
- lib/schai/version.rb
|
92
95
|
- schai.gemspec
|
93
96
|
homepage: https://github.com/gin0606/schai
|
@@ -113,5 +116,5 @@ rubyforge_project:
|
|
113
116
|
rubygems_version: 2.4.5
|
114
117
|
signing_key:
|
115
118
|
specification_version: 4
|
116
|
-
summary:
|
119
|
+
summary: Generate JSON Schema from simple yaml.
|
117
120
|
test_files: []
|
data/lib/schai/hoge.rb
DELETED
@@ -1,156 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
require 'json'
|
3
|
-
|
4
|
-
module Schai
|
5
|
-
module Optional
|
6
|
-
attr_accessor :optional
|
7
|
-
end
|
8
|
-
|
9
|
-
module Metadata
|
10
|
-
attr_accessor :description, :example
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.parse params
|
14
|
-
Root.parse params
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.parse_file path
|
18
|
-
@@path ||=[]
|
19
|
-
if @@path.empty?
|
20
|
-
@@path << path
|
21
|
-
ret = parse YAML.load_file(path)
|
22
|
-
@@path.pop
|
23
|
-
else
|
24
|
-
expand_path = File.expand_path("../#{path}", @@path.last)
|
25
|
-
@@path << expand_path
|
26
|
-
ret = parse YAML.load_file(expand_path)
|
27
|
-
@@path.pop
|
28
|
-
end
|
29
|
-
ret
|
30
|
-
end
|
31
|
-
|
32
|
-
class Root
|
33
|
-
attr_accessor :schema
|
34
|
-
|
35
|
-
def self.parse params
|
36
|
-
ret = self.new
|
37
|
-
ret.schema = parse_components params
|
38
|
-
ret
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.parse_components params
|
42
|
-
case
|
43
|
-
when params.has_key?('include')
|
44
|
-
included_schema = Schai.parse_file(params.delete('include')).schema
|
45
|
-
params.each do |k, v|
|
46
|
-
setter = "#{k}=".to_sym
|
47
|
-
included_schema.send(setter, v)
|
48
|
-
end
|
49
|
-
included_schema
|
50
|
-
when params['type'] == 'object'
|
51
|
-
Object.parse params
|
52
|
-
when params['type'] == 'array'
|
53
|
-
Array.parse params
|
54
|
-
when !params.has_key?('type')
|
55
|
-
raise "typeは必須(#{params})"
|
56
|
-
else
|
57
|
-
Schai::Property.parse params
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def to_schema
|
62
|
-
schema = {
|
63
|
-
'$schema': "http://json-schema.org/draft-04/schema#"
|
64
|
-
}
|
65
|
-
schema.merge @schema.to_schema
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
class Object
|
70
|
-
include Optional
|
71
|
-
include Metadata
|
72
|
-
|
73
|
-
attr_accessor :all
|
74
|
-
|
75
|
-
def self.parse params
|
76
|
-
self.new params
|
77
|
-
end
|
78
|
-
|
79
|
-
def initialize params
|
80
|
-
@all = Hash[params["properties"].map {|k, v|
|
81
|
-
[k || 'null', Root.parse_components(v)]
|
82
|
-
}]
|
83
|
-
@description = params["description"]
|
84
|
-
@example = params["example"]
|
85
|
-
@optional = params["optional"]
|
86
|
-
end
|
87
|
-
|
88
|
-
def to_schema
|
89
|
-
schema = {}
|
90
|
-
schema[:type] = :object
|
91
|
-
schema[:description] = @description if @description
|
92
|
-
schema[:properties] = Hash[@all.map {|k, p| [k, p.to_schema]}]
|
93
|
-
schema[:required] = @all.select{|k, p| !p.optional}.map{|k, p| k || 'null'}
|
94
|
-
schema[:example] = @example if @example
|
95
|
-
schema
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
class Array
|
100
|
-
include Optional
|
101
|
-
include Metadata
|
102
|
-
|
103
|
-
attr_accessor :items
|
104
|
-
def self.parse params
|
105
|
-
self.new params
|
106
|
-
end
|
107
|
-
|
108
|
-
def initialize params
|
109
|
-
@items = Property.parse params['items']
|
110
|
-
@description = params["description"]
|
111
|
-
@example = params["example"]
|
112
|
-
@optional = params["optional"]
|
113
|
-
end
|
114
|
-
|
115
|
-
def to_schema
|
116
|
-
schema = {
|
117
|
-
type: :array,
|
118
|
-
}
|
119
|
-
schema[:description] = @description if @description
|
120
|
-
schema[:items] = @items.to_schema
|
121
|
-
schema[:example] = @example if @example
|
122
|
-
schema
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
class Property
|
127
|
-
include Optional
|
128
|
-
include Metadata
|
129
|
-
|
130
|
-
attr_accessor :type, :format
|
131
|
-
|
132
|
-
def self.parse params
|
133
|
-
if params.has_key? 'include'
|
134
|
-
Schai.parse_file(params['include']).schema
|
135
|
-
else
|
136
|
-
self.new params
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
def initialize params
|
141
|
-
params.each do |k, v|
|
142
|
-
setter = "#{k}=".to_sym
|
143
|
-
self.send(setter, v)
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
def to_schema
|
148
|
-
ret = {}
|
149
|
-
ret[:type] = (@type || 'null').to_sym
|
150
|
-
ret[:format] = @format if @format
|
151
|
-
ret[:description] = @description if @description
|
152
|
-
ret[:example] = @example if @example
|
153
|
-
ret
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|