skeleton 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +92 -69
- data/Rakefile +2 -7
- data/lib/skeleton.rb +14 -4
- data/lib/skeleton/attributes.rb +19 -0
- data/lib/skeleton/config.rb +38 -0
- data/lib/skeleton/contact.rb +17 -0
- data/lib/skeleton/documentation.rb +17 -0
- data/lib/skeleton/example.rb +20 -6
- data/lib/skeleton/header.rb +67 -0
- data/lib/skeleton/headers.rb +50 -0
- data/lib/skeleton/helpers/controller_helpers.rb +25 -0
- data/lib/skeleton/info.rb +40 -0
- data/lib/skeleton/item.rb +99 -0
- data/lib/skeleton/license.rb +16 -0
- data/lib/skeleton/model.rb +31 -0
- data/lib/skeleton/operation.rb +157 -0
- data/lib/skeleton/parameter.rb +100 -20
- data/lib/skeleton/path.rb +111 -0
- data/lib/skeleton/response.rb +59 -0
- data/lib/skeleton/responses.rb +59 -0
- data/lib/skeleton/schema.rb +70 -0
- data/lib/skeleton/scopes.rb +24 -0
- data/lib/skeleton/security_definitions.rb +46 -0
- data/lib/skeleton/security_requirement.rb +29 -0
- data/lib/skeleton/security_scheme.rb +47 -0
- data/lib/skeleton/serializers/swagger.rb +212 -0
- data/lib/skeleton/structure.rb +191 -0
- data/lib/skeleton/tag.rb +24 -0
- data/lib/skeleton/version.rb +1 -1
- data/spec/integrations/use_case_spec.rb +130 -0
- data/spec/skeleton/operation_spec.rb +113 -0
- data/spec/skeleton/serializers/contact_spec.rb +30 -0
- data/spec/skeleton/serializers/documentation_spec.rb +23 -0
- data/spec/skeleton/serializers/header_spec.rb +57 -0
- data/spec/spec_helper.rb +8 -0
- metadata +36 -15
- data/lib/skeleton/action.rb +0 -46
- data/lib/skeleton/builder.rb +0 -47
- data/lib/skeleton/link.rb +0 -57
- data/spec/skeleton/integrated_spec.rb +0 -38
- data/test/skeleton/action_test.rb +0 -78
- data/test/skeleton/builder_test.rb +0 -51
- data/test/skeleton/link_test.rb +0 -68
- data/test/test_helper.rb +0 -6
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'skeleton/structure'
|
2
|
+
|
3
|
+
module Skeleton
|
4
|
+
module Helpers
|
5
|
+
module ControllerHelpers
|
6
|
+
def self.included(base)
|
7
|
+
base.send(:extend, ClassMethods)
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def define_api_path(resource, &block)
|
12
|
+
Skeleton.config.path(resource, &block)
|
13
|
+
end
|
14
|
+
|
15
|
+
def define_global_parameter(location, name, &block)
|
16
|
+
Skeleton.config.parameter(location, name, &block)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_api_path(resource)
|
21
|
+
Skeleton.config.path(resource)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'skeleton/model'
|
2
|
+
require 'skeleton/license'
|
3
|
+
require 'skeleton/contact'
|
4
|
+
|
5
|
+
module Skeleton
|
6
|
+
class Info < Model
|
7
|
+
attr_accessor :title, :description, :terms_of_service, :license, :version
|
8
|
+
attr_presence :title, :description, :terms_of_service, :license, :version
|
9
|
+
|
10
|
+
def contact
|
11
|
+
@contact ||= Skeleton::Contact.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def license
|
15
|
+
@license ||= Skeleton::License.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_h
|
19
|
+
hash = {}
|
20
|
+
hash[:title] = title if title?
|
21
|
+
hash[:description] = description if description?
|
22
|
+
hash[:version] = version if version?
|
23
|
+
hash[:terms_of_service] = terms_of_service if terms_of_service?
|
24
|
+
hash[:license] = license.to_h
|
25
|
+
hash[:contact] = contact.to_h
|
26
|
+
hash
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_swagger_hash
|
30
|
+
hash = {}
|
31
|
+
hash[:title] = title if title?
|
32
|
+
hash[:description] = description if description?
|
33
|
+
hash[:version] = version if version?
|
34
|
+
hash[:termsOfService] = terms_of_service if terms_of_service?
|
35
|
+
hash[:license] = license.to_swagger_hash
|
36
|
+
hash[:contact] = contact.to_swagger_hash
|
37
|
+
hash
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'skeleton/model'
|
2
|
+
|
3
|
+
module Skeleton
|
4
|
+
class Item < Model
|
5
|
+
attr_accessor :type, :format, :title, :description, :default, :multiple_of,
|
6
|
+
:maximum, :exclusive_maximum, :minimum, :exclusive_minimum,
|
7
|
+
:max_length, :min_length, :pattern, :max_items, :min_items,
|
8
|
+
:unique_items, :max_properties, :min_properties, :items
|
9
|
+
|
10
|
+
attr_writer :enum
|
11
|
+
attr_presence :exclusive_maximum, :exclusive_minimum, :unique_items, :items
|
12
|
+
|
13
|
+
def enum
|
14
|
+
@enum ||= []
|
15
|
+
end
|
16
|
+
|
17
|
+
def enum?
|
18
|
+
!enum.empty?
|
19
|
+
end
|
20
|
+
|
21
|
+
def array?
|
22
|
+
@type == 'array'
|
23
|
+
end
|
24
|
+
|
25
|
+
def string?
|
26
|
+
@type == 'string'
|
27
|
+
end
|
28
|
+
|
29
|
+
def number?
|
30
|
+
@type == 'number'
|
31
|
+
end
|
32
|
+
|
33
|
+
def integer?
|
34
|
+
@type == 'integer'
|
35
|
+
end
|
36
|
+
|
37
|
+
def boolean?
|
38
|
+
@type == 'boolean'
|
39
|
+
end
|
40
|
+
|
41
|
+
def file?
|
42
|
+
@type == 'file'
|
43
|
+
end
|
44
|
+
|
45
|
+
def to_h
|
46
|
+
hash = {}
|
47
|
+
hash[:type] = type if type?
|
48
|
+
hash[:format] = format if format?
|
49
|
+
|
50
|
+
hash[:items] = items.to_hash if items?
|
51
|
+
|
52
|
+
hash[:title] = title if title?
|
53
|
+
hash[:description] = description if description?
|
54
|
+
hash[:default] = default if default?
|
55
|
+
hash[:multiple_of] = multiple_of if multiple_of?
|
56
|
+
hash[:maximum] = maximum if maximum?
|
57
|
+
hash[:exclusive_maximum] = exclusive_maximum if exclusive_maximum?
|
58
|
+
hash[:minimum] = minimum if minimum?
|
59
|
+
hash[:exclusive_minimum] = exclusive_minimum if exclusive_minimum?
|
60
|
+
hash[:max_length] = max_length if max_length?
|
61
|
+
hash[:min_length] = min_length if min_length?
|
62
|
+
hash[:pattern] = pattern if pattern?
|
63
|
+
hash[:max_items] = max_items if max_items?
|
64
|
+
hash[:min_items] = min_items if min_items?
|
65
|
+
hash[:unique_items] = unique_items if unique_items?
|
66
|
+
hash[:max_properties] = max_properties if max_properties?
|
67
|
+
hash[:min_properties] = min_properties if min_properties?
|
68
|
+
hash[:enum] = enum if enum?
|
69
|
+
hash
|
70
|
+
end
|
71
|
+
|
72
|
+
def to_swagger_hash
|
73
|
+
hash = {}
|
74
|
+
hash[:type] = type if type?
|
75
|
+
hash[:format] = format if format?
|
76
|
+
|
77
|
+
hash[:items] = items.to_swagger_hash if items?
|
78
|
+
|
79
|
+
hash[:title] = title if title?
|
80
|
+
hash[:description] = description if description?
|
81
|
+
hash[:default] = default if default?
|
82
|
+
hash[:multipleOf] = multiple_of if multiple_of?
|
83
|
+
hash[:maximum] = maximum if maximum?
|
84
|
+
hash[:exclusiveMaximum] = exclusive_maximum if exclusive_maximum?
|
85
|
+
hash[:minimum] = minimum if minimum?
|
86
|
+
hash[:exclusiveMinimum] = exclusive_minimum if exclusive_minimum?
|
87
|
+
hash[:maxLength] = max_length if max_length?
|
88
|
+
hash[:minLength] = min_length if min_length?
|
89
|
+
hash[:pattern] = pattern if pattern?
|
90
|
+
hash[:maxItems] = max_items if max_items?
|
91
|
+
hash[:minItems] = min_items if min_items?
|
92
|
+
hash[:uniqueItems] = unique_items if unique_items?
|
93
|
+
hash[:maxProperties] = max_properties if max_properties?
|
94
|
+
hash[:minProperties] = min_properties if min_properties?
|
95
|
+
hash[:enum] = enum if enum?
|
96
|
+
hash
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'skeleton/model'
|
2
|
+
|
3
|
+
module Skeleton
|
4
|
+
class License < Model
|
5
|
+
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
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'multi_json'
|
2
|
+
require 'skeleton/attributes'
|
3
|
+
|
4
|
+
module Skeleton
|
5
|
+
class Model
|
6
|
+
extend Skeleton::Attributes
|
7
|
+
|
8
|
+
def initialize(args={})
|
9
|
+
args.each do |k, v|
|
10
|
+
setter = "#{k}="
|
11
|
+
self.public_send(setter, v) if self.respond_to?(setter)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_swagger_hash
|
16
|
+
raise(NotImplementedError)
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_h
|
20
|
+
raise(NotImplementedError)
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_json
|
24
|
+
MultiJson.dump(to_h)
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_swagger_json
|
28
|
+
MultiJson.dump(to_swagger_hash)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
require 'skeleton/model'
|
2
|
+
require 'skeleton/parameter'
|
3
|
+
require 'skeleton/responses'
|
4
|
+
|
5
|
+
module Skeleton
|
6
|
+
class Operation < Model
|
7
|
+
attr_accessor :summary, :description, :external_docs, :operation_id, :deprecated
|
8
|
+
attr_presence :summary, :description, :external_docs, :operation_id, :deprecated
|
9
|
+
attr_not_empty :tags, :consumes, :produces, :responses, :schemes, :security, :parameters
|
10
|
+
|
11
|
+
attr_writer :responses
|
12
|
+
|
13
|
+
def consumes
|
14
|
+
@consumes ||= []
|
15
|
+
end
|
16
|
+
|
17
|
+
def consumes=(value)
|
18
|
+
@consumes = Array(value)
|
19
|
+
end
|
20
|
+
|
21
|
+
def produces
|
22
|
+
@produces ||= []
|
23
|
+
end
|
24
|
+
|
25
|
+
def produces=(value)
|
26
|
+
@produces = Array(value)
|
27
|
+
end
|
28
|
+
|
29
|
+
def parameters
|
30
|
+
@parameters ||= []
|
31
|
+
end
|
32
|
+
|
33
|
+
def parameters=(value)
|
34
|
+
@parameters = Array(value)
|
35
|
+
end
|
36
|
+
|
37
|
+
def schemes
|
38
|
+
@schemes ||= []
|
39
|
+
end
|
40
|
+
|
41
|
+
def schemes=(value)
|
42
|
+
@schemes = Array(value)
|
43
|
+
end
|
44
|
+
|
45
|
+
def security
|
46
|
+
@security ||= []
|
47
|
+
end
|
48
|
+
|
49
|
+
def security=(value)
|
50
|
+
@security = Array(value)
|
51
|
+
end
|
52
|
+
|
53
|
+
def responses
|
54
|
+
@responses ||= Skeleton::Responses.new
|
55
|
+
end
|
56
|
+
|
57
|
+
def tags=(value)
|
58
|
+
@tags = Array(value)
|
59
|
+
end
|
60
|
+
|
61
|
+
def tags
|
62
|
+
@tags ||= []
|
63
|
+
end
|
64
|
+
|
65
|
+
def response(name, args={})
|
66
|
+
responses.set(name, args)
|
67
|
+
end
|
68
|
+
|
69
|
+
def tag(value)
|
70
|
+
tags << value
|
71
|
+
end
|
72
|
+
|
73
|
+
def parameter(location, name, &block)
|
74
|
+
param = Parameter.new(location: location, name: name)
|
75
|
+
yield(param) if block
|
76
|
+
parameters << param
|
77
|
+
end
|
78
|
+
|
79
|
+
def to_h
|
80
|
+
hash = {}
|
81
|
+
hash[:tags] = self.tags if self.tags?
|
82
|
+
hash[:summary] = self.summary if self.summary?
|
83
|
+
hash[:description] = self.description if self.description?
|
84
|
+
hash[:external_docs] = self.external_docs if self.external_docs?
|
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
|
98
|
+
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
|
115
|
+
end
|
116
|
+
|
117
|
+
def to_swagger_hash
|
118
|
+
hash = {}
|
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
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
data/lib/skeleton/parameter.rb
CHANGED
@@ -1,32 +1,112 @@
|
|
1
|
+
require 'skeleton/model'
|
2
|
+
|
1
3
|
module Skeleton
|
2
|
-
class Parameter
|
3
|
-
attr_accessor :
|
4
|
+
class Parameter < Model
|
5
|
+
attr_accessor :name, :location, :description, :required, :schema, :type,
|
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
|
10
|
+
|
11
|
+
attr_writer :enum
|
12
|
+
attr_presence :pattern, :multiple_of, :unique_items, :max_items, :min_items,
|
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 ||= []
|
20
|
+
end
|
21
|
+
|
22
|
+
def enum?
|
23
|
+
!enum.empty?
|
24
|
+
end
|
25
|
+
|
26
|
+
def array?
|
27
|
+
@type == 'array'
|
28
|
+
end
|
29
|
+
|
30
|
+
def string?
|
31
|
+
@type == 'string'
|
32
|
+
end
|
33
|
+
|
34
|
+
def number?
|
35
|
+
@type == 'number'
|
36
|
+
end
|
4
37
|
|
5
|
-
def
|
6
|
-
@
|
7
|
-
|
8
|
-
@restrictions = []
|
38
|
+
def integer?
|
39
|
+
@type == 'integer'
|
40
|
+
end
|
9
41
|
|
10
|
-
|
11
|
-
|
12
|
-
end
|
42
|
+
def boolean?
|
43
|
+
@type == 'boolean'
|
13
44
|
end
|
14
45
|
|
15
|
-
def
|
16
|
-
@
|
46
|
+
def file?
|
47
|
+
@type == 'file'
|
17
48
|
end
|
18
49
|
|
19
50
|
def to_h
|
20
|
-
hash = {
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
hash[
|
27
|
-
|
51
|
+
hash = {}
|
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
|
79
|
+
end
|
80
|
+
|
81
|
+
def to_swagger_hash
|
82
|
+
hash = {}
|
83
|
+
hash[:name] = name if name?
|
84
|
+
hash[:location] = 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?
|
28
109
|
hash
|
29
110
|
end
|
30
|
-
alias_method :to_hash, :to_h
|
31
111
|
end
|
32
112
|
end
|