skeleton 0.3.3 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +140 -65
- data/Rakefile +10 -3
- data/lib/skeleton.rb +6 -10
- data/lib/skeleton/contact.rb +1 -13
- data/lib/skeleton/error.rb +4 -0
- data/lib/skeleton/graph.rb +56 -0
- data/lib/skeleton/header.rb +2 -63
- data/lib/skeleton/items.rb +34 -0
- data/lib/skeleton/license.rb +1 -12
- data/lib/skeleton/model.rb +13 -17
- data/lib/skeleton/operation.rb +50 -121
- data/lib/skeleton/parameter.rb +31 -88
- data/lib/skeleton/parameters.rb +40 -0
- data/lib/skeleton/path.rb +42 -80
- data/lib/skeleton/presenter.rb +19 -0
- data/lib/skeleton/property.rb +6 -0
- data/lib/skeleton/response.rb +24 -45
- data/lib/skeleton/schema.rb +80 -63
- data/lib/skeleton/scope.rb +18 -0
- data/lib/skeleton/security_scheme.rb +19 -37
- data/lib/skeleton/serializers/options.rb +215 -0
- data/lib/skeleton/serializers/swagger.rb +197 -0
- data/lib/skeleton/structure.rb +92 -138
- data/lib/skeleton/swagger.rb +9 -0
- data/lib/skeleton/tag.rb +11 -16
- data/lib/skeleton/version.rb +1 -1
- data/skeleton.gemspec +2 -0
- data/test/fixtures/json-schema-draft-04.json +150 -0
- data/test/fixtures/schema.json +1482 -0
- data/test/integrations/validate_complex_schema_spec.rb +42 -0
- data/test/skeleton/graph_test.rb +22 -0
- data/test/skeleton/mapper_test.rb +84 -0
- data/test/skeleton/operation_test.rb +11 -0
- data/test/skeleton/parameter_test.rb +34 -0
- data/test/skeleton/parameters_test.rb +9 -0
- data/test/skeleton/path_test.rb +46 -0
- data/test/skeleton/property_test.rb +8 -0
- data/test/skeleton/serializers/options_test.rb +68 -0
- data/test/skeleton/serializers/swagger_test.rb +30 -0
- data/test/support/factories/structure_factory.rb +86 -0
- data/test/support/fixtures.rb +6 -0
- data/test/support/kissmetrics/core_api.rb +542 -0
- data/{spec/spec_helper.rb → test/test_helper.rb} +7 -1
- metadata +73 -25
- data/lib/skeleton/config.rb +0 -37
- data/lib/skeleton/documentation.rb +0 -17
- data/lib/skeleton/example.rb +0 -31
- data/lib/skeleton/headers.rb +0 -50
- data/lib/skeleton/helpers/controller_helpers.rb +0 -25
- data/lib/skeleton/info.rb +0 -40
- data/lib/skeleton/item.rb +0 -99
- data/lib/skeleton/responses.rb +0 -59
- data/lib/skeleton/scopes.rb +0 -24
- data/lib/skeleton/security_definitions.rb +0 -46
- data/lib/skeleton/security_requirement.rb +0 -29
- data/spec/integrations/use_case_spec.rb +0 -131
- data/spec/skeleton/operation_spec.rb +0 -113
- data/spec/skeleton/serializers/contact_spec.rb +0 -30
- data/spec/skeleton/serializers/documentation_spec.rb +0 -23
- data/spec/skeleton/serializers/header_spec.rb +0 -57
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'skeleton/schema'
|
2
|
+
|
3
|
+
module Skeleton
|
4
|
+
class Items < Schema
|
5
|
+
attr_reader :items, :collection_format
|
6
|
+
|
7
|
+
def items=(value)
|
8
|
+
case value
|
9
|
+
when Hash
|
10
|
+
@items = Skeleton::Items.new(value)
|
11
|
+
else
|
12
|
+
@items = value
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def collection_format
|
17
|
+
return nil unless array?
|
18
|
+
|
19
|
+
if @collection_format.nil?
|
20
|
+
'csv'
|
21
|
+
else
|
22
|
+
@collection_format
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def collection_format=(value)
|
27
|
+
@collection_format = value.to_s
|
28
|
+
end
|
29
|
+
|
30
|
+
def items?
|
31
|
+
!!@items
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/skeleton/license.rb
CHANGED
@@ -1,16 +1,5 @@
|
|
1
|
-
require 'skeleton/model'
|
2
|
-
|
3
1
|
module Skeleton
|
4
|
-
class License
|
2
|
+
class License
|
5
3
|
attr_accessor :name, :url
|
6
|
-
attr_presence :name, :url
|
7
|
-
|
8
|
-
def to_h
|
9
|
-
hash = {}
|
10
|
-
hash[:name] = name if name?
|
11
|
-
hash[:url] = url if url?
|
12
|
-
hash
|
13
|
-
end
|
14
|
-
alias_method :to_swagger_hash, :to_h
|
15
4
|
end
|
16
5
|
end
|
data/lib/skeleton/model.rb
CHANGED
@@ -1,31 +1,27 @@
|
|
1
|
-
require '
|
2
|
-
require 'skeleton/attributes'
|
1
|
+
require 'skeleton/schema'
|
3
2
|
|
4
3
|
module Skeleton
|
5
|
-
class Model
|
6
|
-
|
4
|
+
class Model < Schema
|
5
|
+
attr_reader :description, :descriptor, :name
|
7
6
|
|
8
|
-
def
|
9
|
-
|
10
|
-
setter = "#{k}="
|
11
|
-
self.public_send(setter, v) if self.respond_to?(setter)
|
12
|
-
end
|
7
|
+
def describe(value)
|
8
|
+
@description = value
|
13
9
|
end
|
14
10
|
|
15
|
-
def
|
16
|
-
|
11
|
+
def extends(value)
|
12
|
+
@descriptor = value
|
17
13
|
end
|
18
14
|
|
19
|
-
def
|
20
|
-
|
15
|
+
def required(field, options={})
|
16
|
+
property(field, { required: true }.merge(options))
|
21
17
|
end
|
22
18
|
|
23
|
-
def
|
24
|
-
|
19
|
+
def optional(field, options={})
|
20
|
+
property(field, { required: false }.merge(options))
|
25
21
|
end
|
26
22
|
|
27
|
-
def
|
28
|
-
|
23
|
+
def property(field, options={})
|
24
|
+
properties[field] = Skeleton::Schema.new(options)
|
29
25
|
end
|
30
26
|
end
|
31
27
|
end
|
data/lib/skeleton/operation.rb
CHANGED
@@ -1,157 +1,86 @@
|
|
1
|
-
require 'skeleton/
|
2
|
-
require 'skeleton/
|
3
|
-
require 'skeleton/responses'
|
1
|
+
require 'skeleton/response'
|
2
|
+
require 'skeleton/parameters'
|
4
3
|
|
5
4
|
module Skeleton
|
6
|
-
class Operation
|
7
|
-
attr_accessor :
|
8
|
-
|
9
|
-
attr_not_empty :tags, :consumes, :produces, :responses, :schemes, :security, :parameters
|
5
|
+
class Operation
|
6
|
+
attr_accessor :description, :summary, :id
|
7
|
+
attr_reader :responses
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
@consumes
|
9
|
+
def initialize
|
10
|
+
@responses = {}
|
11
|
+
@tags = {}
|
12
|
+
@consumes = {}
|
13
|
+
@produces = {}
|
14
|
+
@parameters = Skeleton::Parameters.new
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
def produces
|
22
|
-
@produces ||= []
|
23
|
-
end
|
17
|
+
alias_method :summarize, :summary=
|
18
|
+
alias_method :describe, :description=
|
19
|
+
alias_method :identify, :id=
|
24
20
|
|
25
|
-
def
|
26
|
-
@
|
21
|
+
def deprecate
|
22
|
+
@deprecated = true
|
27
23
|
end
|
28
24
|
|
29
|
-
def
|
30
|
-
|
25
|
+
def deprecated?
|
26
|
+
!!@deprecated
|
31
27
|
end
|
32
28
|
|
33
|
-
def
|
34
|
-
|
29
|
+
def id?
|
30
|
+
!!@id
|
35
31
|
end
|
36
32
|
|
37
|
-
def
|
38
|
-
|
33
|
+
def tag(*values)
|
34
|
+
values.each { |v| @tags[v] = true }
|
39
35
|
end
|
40
36
|
|
41
|
-
def
|
42
|
-
@
|
37
|
+
def tags
|
38
|
+
@tags.map { |t,_| t.to_s }
|
43
39
|
end
|
44
40
|
|
45
|
-
def
|
46
|
-
|
41
|
+
def consume(*values)
|
42
|
+
values.each { |t| @consumes[t.to_s] = true }
|
47
43
|
end
|
48
44
|
|
49
|
-
def
|
50
|
-
@
|
45
|
+
def consumes
|
46
|
+
@consumes.map { |s, _| s }
|
51
47
|
end
|
52
48
|
|
53
|
-
def
|
54
|
-
|
49
|
+
def consumes?
|
50
|
+
!@consumes.empty?
|
55
51
|
end
|
56
52
|
|
57
|
-
def
|
58
|
-
@
|
53
|
+
def produce(*values)
|
54
|
+
values.each { |t| @produces[t.to_s] = true }
|
59
55
|
end
|
60
56
|
|
61
|
-
def
|
62
|
-
@
|
63
|
-
end
|
64
|
-
|
65
|
-
def response(name, args={})
|
66
|
-
responses.set(name, args)
|
57
|
+
def produces
|
58
|
+
@produces.map { |s, _| s }
|
67
59
|
end
|
68
60
|
|
69
|
-
def
|
70
|
-
|
61
|
+
def produces?
|
62
|
+
!@produces.empty?
|
71
63
|
end
|
72
64
|
|
73
|
-
def
|
74
|
-
|
75
|
-
|
76
|
-
|
65
|
+
def response(value, options={}, &block)
|
66
|
+
@responses[value] = Skeleton::Response.new
|
67
|
+
@responses[value].instance_eval(&block) if block
|
68
|
+
@responses[:default] = @responses[value] if options[:default]
|
69
|
+
@responses[value]
|
77
70
|
end
|
78
71
|
|
79
|
-
def
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
hash[:operation_id] = self.operation_id if self.operation_id?
|
86
|
-
hash[:consumes] = self.consumes if self.consumes?
|
87
|
-
hash[:produces] = self.produces if self.produces?
|
88
|
-
|
89
|
-
if self.parameters?
|
90
|
-
hash[:parameters] = []
|
91
|
-
self.parameters.each do |parameter|
|
92
|
-
if parameter.respond_to?(:to_h)
|
93
|
-
hash[:parameters] << parameter.to_h
|
94
|
-
else
|
95
|
-
hash[:parameters] = parameter
|
96
|
-
end
|
97
|
-
end
|
72
|
+
def parameters(location=:query, &block)
|
73
|
+
params = Skeleton::Parameters.new
|
74
|
+
params.instance_eval(&block) if block
|
75
|
+
params.each do |p|
|
76
|
+
p.location = location
|
77
|
+
@parameters.add(p)
|
98
78
|
end
|
99
|
-
|
100
|
-
hash[:responses] = self.responses.to_h if self.responses?
|
101
|
-
hash[:schemes] = self.schemes if self.schemes?
|
102
|
-
hash[:deprecated] = self.deprecated if self.deprecated?
|
103
|
-
if self.security?
|
104
|
-
hash[:security] = []
|
105
|
-
self.security.each do |sec|
|
106
|
-
if sec.respond_to?(:to_h)
|
107
|
-
hash[:secuirty] << sec.to_h
|
108
|
-
else
|
109
|
-
hash[:security] << sec
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
hash[:security] = self.deprecated if self.deprecated?
|
114
|
-
hash
|
79
|
+
@parameters
|
115
80
|
end
|
116
81
|
|
117
|
-
def
|
118
|
-
|
119
|
-
hash[:tags] = self.tags if self.tags?
|
120
|
-
hash[:summary] = self.summary if self.summary?
|
121
|
-
hash[:description] = self.description if self.description?
|
122
|
-
hash[:externalDocs] = self.external_docs if self.external_docs?
|
123
|
-
hash[:operationId] = self.operation_id if self.operation_id?
|
124
|
-
hash[:consumes] = self.consumes if self.consumes?
|
125
|
-
hash[:produces] = self.produces if self.produces?
|
126
|
-
|
127
|
-
if self.parameters?
|
128
|
-
hash[:parameters] = []
|
129
|
-
self.parameters.each do |parameter|
|
130
|
-
if parameter.respond_to?(:to_swagger_hash)
|
131
|
-
hash[:parameters] << parameter.to_swagger_hash
|
132
|
-
else
|
133
|
-
hash[:parameters] = parameter
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
hash[:responses] = self.responses.to_swagger_hash if self.responses?
|
139
|
-
|
140
|
-
hash[:schemes] = self.schemes if self.schemes?
|
141
|
-
hash[:deprecated] = self.deprecated if self.deprecated?
|
142
|
-
|
143
|
-
if self.security?
|
144
|
-
hash[:security] = []
|
145
|
-
self.security.each do |sec|
|
146
|
-
if sec.respond_to?(:to_swagger_hash)
|
147
|
-
hash[:secuirty] << sec.to_swagger_hash
|
148
|
-
else
|
149
|
-
hash[:security] << sec
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
153
|
-
hash[:security] = self.deprecated if self.deprecated?
|
154
|
-
hash
|
82
|
+
def parameters?
|
83
|
+
!@parameters.empty?
|
155
84
|
end
|
156
85
|
end
|
157
86
|
end
|
data/lib/skeleton/parameter.rb
CHANGED
@@ -1,112 +1,55 @@
|
|
1
|
-
require 'skeleton/
|
1
|
+
require 'skeleton/schema'
|
2
|
+
require 'skeleton/items'
|
2
3
|
|
3
4
|
module Skeleton
|
4
|
-
class Parameter <
|
5
|
-
|
6
|
-
:format, :items, :collection_format, :default, :maximum,
|
7
|
-
:exclusive_maximum, :minimum, :exclusive_minimum, :max_length,
|
8
|
-
:min_length, :unique_items, :multiple_of, :min_items,
|
9
|
-
:max_items, :pattern
|
5
|
+
class Parameter < Schema
|
6
|
+
attr_reader :name, :location, :items, :schema
|
10
7
|
|
11
|
-
|
12
|
-
|
13
|
-
:min_length, :max_length, :minimum, :maximum, :default,
|
14
|
-
:collection_format, :items, :format, :type, :schema, :required,
|
15
|
-
:description, :location, :name, :exclusive_maximum,
|
16
|
-
:exclusive_minimum, :unique_items
|
17
|
-
|
18
|
-
def enum
|
19
|
-
@enum ||= []
|
8
|
+
def items?
|
9
|
+
!!@items
|
20
10
|
end
|
21
11
|
|
22
|
-
def
|
23
|
-
|
12
|
+
def items=(hash)
|
13
|
+
self.type = 'array'
|
14
|
+
@items = Skeleton::Items.new(hash)
|
24
15
|
end
|
16
|
+
alias_method :array=, :items=
|
25
17
|
|
26
|
-
def
|
27
|
-
|
18
|
+
def schema?
|
19
|
+
!!@schema
|
28
20
|
end
|
29
21
|
|
30
|
-
def
|
31
|
-
|
22
|
+
def schema=(value)
|
23
|
+
case value
|
24
|
+
when Hash
|
25
|
+
@schema = Skeleton::Schema.new(value)
|
26
|
+
else
|
27
|
+
@schema = value
|
28
|
+
end
|
32
29
|
end
|
33
30
|
|
34
|
-
def
|
35
|
-
@
|
31
|
+
def name=(value)
|
32
|
+
@name = value.to_s
|
36
33
|
end
|
37
34
|
|
38
|
-
def
|
39
|
-
@
|
35
|
+
def location=(value)
|
36
|
+
@location = value.to_s
|
40
37
|
end
|
41
38
|
|
42
|
-
def
|
43
|
-
@
|
39
|
+
def body?
|
40
|
+
@location == 'body'
|
44
41
|
end
|
45
42
|
|
46
|
-
def
|
47
|
-
@
|
43
|
+
def query?
|
44
|
+
@location == 'query'
|
48
45
|
end
|
49
46
|
|
50
|
-
def
|
51
|
-
|
52
|
-
hash[:name] = name if name?
|
53
|
-
hash[:location] = location if location?
|
54
|
-
hash[:description] = description if description?
|
55
|
-
hash[:required] = required if required?
|
56
|
-
|
57
|
-
hash[:schema] = schema.to_h if schema?
|
58
|
-
|
59
|
-
hash[:type] = type if type?
|
60
|
-
hash[:format] = format if format?
|
61
|
-
|
62
|
-
hash[:items] = items.to_h if items?
|
63
|
-
|
64
|
-
hash[:collection_format] = collection_format if collection_format?
|
65
|
-
hash[:default] = default if default?
|
66
|
-
hash[:maximum] = maximum if maximum?
|
67
|
-
hash[:exclusive_maximum] = exclusive_maximum if exclusive_maximum?
|
68
|
-
hash[:minimum] = minimum if minimum?
|
69
|
-
hash[:exclusive_minimum] = exclusive_minimum if exclusive_minimum?
|
70
|
-
hash[:max_length] = max_length if max_length?
|
71
|
-
hash[:min_length] = min_length if min_length?
|
72
|
-
hash[:unique_items] = unique_items if unique_items?
|
73
|
-
hash[:multiple_of] = multiple_of if multiple_of?
|
74
|
-
hash[:min_items] = min_items if min_items?
|
75
|
-
hash[:max_items] = max_items if max_items?
|
76
|
-
hash[:pattern] = pattern if pattern?
|
77
|
-
hash[:enum] = enum if enum?
|
78
|
-
hash
|
47
|
+
def path?
|
48
|
+
@location == 'path'
|
79
49
|
end
|
80
50
|
|
81
|
-
def
|
82
|
-
|
83
|
-
hash[:name] = name if name?
|
84
|
-
hash[:in] = location if location?
|
85
|
-
hash[:description] = description if description?
|
86
|
-
hash[:required] = required if required?
|
87
|
-
|
88
|
-
hash[:schema] = schema.to_swagger_json if schema?
|
89
|
-
|
90
|
-
hash[:type] = type if type?
|
91
|
-
hash[:format] = format if format?
|
92
|
-
|
93
|
-
hash[:items] = items.to_swagger_json if items?
|
94
|
-
|
95
|
-
hash[:collectionFormat] = collection_format if collection_format?
|
96
|
-
hash[:default] = default if default?
|
97
|
-
hash[:maximum] = maximum if maximum?
|
98
|
-
hash[:exclusiveMaximum] = exclusive_maximum if exclusive_maximum?
|
99
|
-
hash[:minimum] = minimum if minimum?
|
100
|
-
hash[:exclusiveMinimum] = exclusive_minimum if exclusive_minimum?
|
101
|
-
hash[:maxLength] = max_length if max_length?
|
102
|
-
hash[:minLength] = min_length if min_length?
|
103
|
-
hash[:uniqueItems] = unique_items if unique_items?
|
104
|
-
hash[:multipleOf] = multiple_of if multiple_of?
|
105
|
-
hash[:minItems] = min_items if min_items?
|
106
|
-
hash[:maxItems] = max_items if max_items?
|
107
|
-
hash[:pattern] = pattern if pattern?
|
108
|
-
hash[:enum] = enum if enum?
|
109
|
-
hash
|
51
|
+
def header?
|
52
|
+
@location == 'header'
|
110
53
|
end
|
111
54
|
end
|
112
55
|
end
|