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,40 @@
|
|
1
|
+
require 'skeleton/parameter'
|
2
|
+
|
3
|
+
module Skeleton
|
4
|
+
class Parameters
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@list = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def empty?
|
12
|
+
@list.empty?
|
13
|
+
end
|
14
|
+
|
15
|
+
def each(&block)
|
16
|
+
@list.each(&block)
|
17
|
+
end
|
18
|
+
|
19
|
+
def get(name)
|
20
|
+
find { |p| p.name == name }
|
21
|
+
end
|
22
|
+
alias_method :[], :get
|
23
|
+
|
24
|
+
def add(parameter)
|
25
|
+
@list << parameter
|
26
|
+
parameter
|
27
|
+
end
|
28
|
+
|
29
|
+
def required(name, args={})
|
30
|
+
opts = args.merge(name: name, required: true)
|
31
|
+
add(Skeleton::Parameter.new(opts))
|
32
|
+
end
|
33
|
+
|
34
|
+
def optional(name, args={})
|
35
|
+
opts = args.merge(name: name, required: false)
|
36
|
+
add(Skeleton::Parameter.new(opts))
|
37
|
+
end
|
38
|
+
alias_method :param, :optional
|
39
|
+
end
|
40
|
+
end
|
data/lib/skeleton/path.rb
CHANGED
@@ -1,111 +1,73 @@
|
|
1
1
|
require 'skeleton/operation'
|
2
|
-
require 'skeleton/parameter'
|
3
|
-
require 'skeleton/model'
|
4
2
|
|
5
3
|
module Skeleton
|
6
|
-
class Path
|
7
|
-
|
8
|
-
attr_writer :operations
|
9
|
-
attr_not_empty :parameters, :operations
|
4
|
+
class Path
|
5
|
+
attr_reader :operations
|
10
6
|
|
11
|
-
def
|
12
|
-
@operations
|
7
|
+
def initialize
|
8
|
+
@operations = Hash.new
|
13
9
|
end
|
14
10
|
|
15
|
-
def
|
16
|
-
|
11
|
+
def head(&block)
|
12
|
+
operation(:head, &block)
|
17
13
|
end
|
18
14
|
|
19
|
-
def
|
20
|
-
@
|
15
|
+
def head?
|
16
|
+
@operations.key?(:head)
|
21
17
|
end
|
22
18
|
|
23
|
-
def
|
24
|
-
|
25
|
-
yield(param) if block
|
26
|
-
parameters << param
|
19
|
+
def get(&block)
|
20
|
+
operation(:get, &block)
|
27
21
|
end
|
28
22
|
|
29
|
-
def get
|
30
|
-
|
23
|
+
def get?
|
24
|
+
@operations.key?(:get)
|
31
25
|
end
|
32
26
|
|
33
27
|
def put(&block)
|
34
|
-
|
28
|
+
operation(:put, &block)
|
29
|
+
end
|
30
|
+
|
31
|
+
def put?
|
32
|
+
@operations.key?(:put)
|
35
33
|
end
|
36
34
|
|
37
35
|
def post(&block)
|
38
|
-
|
36
|
+
operation(:post, &block)
|
37
|
+
end
|
38
|
+
|
39
|
+
def post?
|
40
|
+
@operations.key?(:post)
|
41
|
+
end
|
42
|
+
|
43
|
+
def patch(&block)
|
44
|
+
operation(:patch, &block)
|
45
|
+
end
|
46
|
+
|
47
|
+
def patch?
|
48
|
+
@operations.key?(:patch)
|
39
49
|
end
|
40
50
|
|
41
51
|
def delete(&block)
|
42
|
-
|
52
|
+
operation(:delete, &block)
|
53
|
+
end
|
54
|
+
|
55
|
+
def delete?
|
56
|
+
@operations.key?(:delete)
|
43
57
|
end
|
44
58
|
|
45
59
|
def options(&block)
|
46
|
-
|
60
|
+
operation(:options, &block)
|
47
61
|
end
|
48
62
|
|
49
|
-
def
|
50
|
-
|
63
|
+
def options?
|
64
|
+
@operations.key?(:options)
|
51
65
|
end
|
52
66
|
|
53
|
-
def
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
def to_h
|
58
|
-
hash = {}
|
59
|
-
if operations?
|
60
|
-
operations.each do |method, operation|
|
61
|
-
if operation.respond_to?(:to_h)
|
62
|
-
hash[method] = operation.to_h
|
63
|
-
else
|
64
|
-
hash[method] = operation
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
if parameters?
|
69
|
-
hash[:parameters] = parameters.map do |parameter|
|
70
|
-
if parameter.respond_to?(:to_h)
|
71
|
-
parameter.to_h
|
72
|
-
else
|
73
|
-
parameter
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
hash
|
78
|
-
end
|
79
|
-
|
80
|
-
def to_swagger_hash
|
81
|
-
hash = {}
|
82
|
-
if operations?
|
83
|
-
operations.each do |method, operation|
|
84
|
-
if operation.respond_to?(:to_swagger_hash)
|
85
|
-
hash[method] = operation.to_swagger_hash
|
86
|
-
else
|
87
|
-
hash[method] = operation
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
if parameters?
|
92
|
-
hash[:parameters] = parameters.map do |parameter|
|
93
|
-
if parameter.respond_to?(:to_swagger_hash)
|
94
|
-
parameter.to_swagger_hash
|
95
|
-
else
|
96
|
-
parameter
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
hash
|
101
|
-
end
|
102
|
-
|
103
|
-
private
|
104
|
-
|
105
|
-
def define_operation(method, &block)
|
106
|
-
operation = Skeleton::Operation.new
|
107
|
-
yield(operation) if block
|
108
|
-
operations[method] = operation
|
67
|
+
def operation(type, &block)
|
68
|
+
@operations[type] = Skeleton::Operation.new
|
69
|
+
@operations[type].instance_eval(&block)
|
70
|
+
@operations[type]
|
109
71
|
end
|
110
72
|
end
|
111
73
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Skeleton
|
2
|
+
class Presenter
|
3
|
+
def initialize(object)
|
4
|
+
@object = object
|
5
|
+
end
|
6
|
+
|
7
|
+
def method_missing(m, *args, &blk)
|
8
|
+
if @object.respond_to?(m)
|
9
|
+
@object.__send__ m, *args, &blk
|
10
|
+
else
|
11
|
+
super
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def respond_to_missing?(m, include_private = false)
|
16
|
+
@object.respond_to?(m, include_private)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/skeleton/response.rb
CHANGED
@@ -1,59 +1,38 @@
|
|
1
|
-
require 'skeleton/model'
|
2
|
-
require 'skeleton/headers'
|
3
1
|
require 'skeleton/schema'
|
2
|
+
require 'skeleton/header'
|
4
3
|
|
5
4
|
module Skeleton
|
6
|
-
class Response <
|
7
|
-
attr_accessor :description
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
def headers
|
13
|
-
|
14
|
-
when Hash
|
15
|
-
@headers = Skeleton::Headers.new(value)
|
16
|
-
else
|
17
|
-
@headers = value
|
18
|
-
end
|
5
|
+
class Response < Schema
|
6
|
+
attr_accessor :summary, :description
|
7
|
+
|
8
|
+
alias_method :summarize, :summary=
|
9
|
+
alias_method :describe, :description=
|
10
|
+
|
11
|
+
def headers
|
12
|
+
@headers ||= {}
|
19
13
|
end
|
20
14
|
|
21
|
-
def
|
22
|
-
|
23
|
-
when Hash
|
24
|
-
@schema = Skeleton::Schema.new(value)
|
25
|
-
else
|
26
|
-
@schema = value
|
27
|
-
end
|
15
|
+
def no_body
|
16
|
+
@schema = nil
|
28
17
|
end
|
29
18
|
|
30
|
-
def
|
31
|
-
|
32
|
-
when Hash
|
33
|
-
@examples = Skeleton::Example.new(value)
|
34
|
-
else
|
35
|
-
@examples = value
|
36
|
-
end
|
19
|
+
def schema?
|
20
|
+
!!@schema
|
37
21
|
end
|
38
22
|
|
39
|
-
def
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
23
|
+
def schema(value=nil, &block)
|
24
|
+
if block
|
25
|
+
@schema = Skeleton::Model.new
|
26
|
+
@schema.instance_eval(&block)
|
27
|
+
elsif value.is_a?(Hash)
|
28
|
+
@schema = Skeleton::Schema.new(value)
|
29
|
+
end
|
30
|
+
|
31
|
+
@schema
|
47
32
|
end
|
48
33
|
|
49
|
-
def
|
50
|
-
|
51
|
-
hash[:description] = description if description?
|
52
|
-
hash[:examples] = examples.to_swagger_hash if examples?
|
53
|
-
hash[:headers] = headers.to_swagger_hash if headers?
|
54
|
-
hash[:schema] = schema.to_swagger_hash if schema?
|
55
|
-
hash[:examples] = examples.to_swagger_hash if examples?
|
56
|
-
hash
|
34
|
+
def header(field, options={})
|
35
|
+
headers[field] = Skeleton::Header.new(options)
|
57
36
|
end
|
58
37
|
end
|
59
38
|
end
|
data/lib/skeleton/schema.rb
CHANGED
@@ -1,70 +1,87 @@
|
|
1
|
-
require 'skeleton/
|
1
|
+
require 'skeleton/attributes'
|
2
2
|
|
3
3
|
module Skeleton
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
4
|
+
# @abstract This is simply an abstract class
|
5
|
+
class Schema
|
6
|
+
extend Skeleton::Attributes
|
7
|
+
|
8
|
+
PRIMITIVES = %w(string number integer boolean array file)
|
9
|
+
|
10
|
+
attr_accessor :ref, :title, :description, :default, :maximum,
|
11
|
+
:exclusive_maximum, :minimum, :exclusive_minimum, :max_length,
|
12
|
+
:min_length, :pattern, :max_items, :min_items, :unique_items,
|
13
|
+
:max_properties, :min_properties, :required, :multiple_of
|
14
|
+
|
15
|
+
attr_reader :type, :format, :items
|
16
|
+
|
17
|
+
attr_presence :ref, :title, :description, :default, :maximum,
|
18
|
+
:exclusive_maximum, :minimum, :exclusive_minimum, :max_length,
|
19
|
+
:min_length, :pattern, :max_items, :min_items, :unique_items,
|
20
|
+
:max_properties, :min_properties, :required, :format, :multiple_of,
|
21
|
+
:items
|
22
|
+
|
23
|
+
def initialize(args={})
|
24
|
+
args.each do |k, v|
|
25
|
+
setter = "#{k}="
|
26
|
+
self.send(setter, v) if self.respond_to?(setter)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def items=(value)
|
31
|
+
case value
|
32
|
+
when Hash
|
33
|
+
@items = Skeleton::Items.new(value)
|
34
|
+
else
|
35
|
+
@items = value
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def properties
|
40
|
+
@properties ||= {}
|
41
|
+
end
|
42
|
+
|
43
|
+
def properties?
|
44
|
+
!properties.empty?
|
45
|
+
end
|
46
|
+
|
47
|
+
def enum
|
48
|
+
@enum ||= []
|
49
|
+
end
|
50
|
+
|
51
|
+
def format=(value)
|
52
|
+
@format = value.to_s
|
53
|
+
end
|
54
|
+
|
55
|
+
def type=(value)
|
56
|
+
@type = value.to_s
|
57
|
+
end
|
58
|
+
|
59
|
+
def primitive?
|
60
|
+
PRIMITIVES.include?(@type)
|
61
|
+
end
|
62
|
+
|
63
|
+
def array?
|
64
|
+
@type == 'array'
|
65
|
+
end
|
66
|
+
|
67
|
+
def string?
|
68
|
+
@type == 'string'
|
69
|
+
end
|
70
|
+
|
71
|
+
def number?
|
72
|
+
@type == 'number'
|
73
|
+
end
|
74
|
+
|
75
|
+
def integer?
|
76
|
+
@type == 'integer'
|
77
|
+
end
|
78
|
+
|
79
|
+
def boolean?
|
80
|
+
@type == 'boolean'
|
41
81
|
end
|
42
82
|
|
43
|
-
def
|
44
|
-
|
45
|
-
hash[:type] = type if type?
|
46
|
-
hash[:format] = format if format?
|
47
|
-
|
48
|
-
hash[:items] = items.to_swagger_hash if items?
|
49
|
-
|
50
|
-
hash[:title] = title if title?
|
51
|
-
hash[:description] = description if description?
|
52
|
-
hash[:default] = default if default?
|
53
|
-
hash[:multipleOf] = multiple_of if multiple_of?
|
54
|
-
hash[:maximum] = maximum if maximum?
|
55
|
-
hash[:exclusiveMaximum] = exclusive_maximum if exclusive_maximum?
|
56
|
-
hash[:minimum] = minimum if minimum?
|
57
|
-
hash[:exclusiveMinimum] = exclusive_minimum if exclusive_minimum?
|
58
|
-
hash[:maxLength] = max_length if max_length?
|
59
|
-
hash[:minLength] = min_length if min_length?
|
60
|
-
hash[:pattern] = pattern if pattern?
|
61
|
-
hash[:maxItems] = max_items if max_items?
|
62
|
-
hash[:minItems] = min_items if min_items?
|
63
|
-
hash[:uniqueItems] = unique_items if unique_items?
|
64
|
-
hash[:maxProperties] = max_properties if max_properties?
|
65
|
-
hash[:minProperties] = min_properties if min_properties?
|
66
|
-
hash[:enum] = enum if enum?
|
67
|
-
hash
|
83
|
+
def file?
|
84
|
+
@type == 'file'
|
68
85
|
end
|
69
86
|
end
|
70
87
|
end
|