skeleton 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
require 'skeleton'
|
4
|
-
|
5
|
-
describe 'Full integration test' do
|
6
|
-
it 'when describing collection resource' do
|
7
|
-
skeleton = Skeleton.build do |config|
|
8
|
-
config.define(:get, also: :head) do |action|
|
9
|
-
action.description = 'Display a list of resources'
|
10
|
-
|
11
|
-
action.param('limit') do |p|
|
12
|
-
p.type = 'integer'
|
13
|
-
p.description = 'The number of items desired'
|
14
|
-
p.required = false
|
15
|
-
p.restriction('Minimum value is 0')
|
16
|
-
p.restriction('Maximum value is 9000')
|
17
|
-
end
|
18
|
-
|
19
|
-
action.param('offset') do |p|
|
20
|
-
p.type = 'integer'
|
21
|
-
p.description = 'The offset within the collection'
|
22
|
-
p.required = false
|
23
|
-
p.restriction('Minimum value is 0')
|
24
|
-
end
|
25
|
-
|
26
|
-
action.example do |e|
|
27
|
-
e.param('limit', 10)
|
28
|
-
e.param('offset', 0)
|
29
|
-
end
|
30
|
-
action.link(name: 'Self', rel: 'self', href: 'https://api.example.org/resources')
|
31
|
-
end
|
32
|
-
config.link(name: 'Documentation', rel: 'docs', href: 'https://docs.example.org/resources')
|
33
|
-
end
|
34
|
-
|
35
|
-
refute_nil(skeleton.actions['get'])
|
36
|
-
refute_nil(skeleton.actions['head'])
|
37
|
-
end
|
38
|
-
end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
require 'skeleton/action'
|
4
|
-
|
5
|
-
module Skeleton
|
6
|
-
class ActionTest < Minitest::Test
|
7
|
-
def setup
|
8
|
-
@action = Action.new
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_param
|
12
|
-
@action.param(:foo) do |param|
|
13
|
-
param.type = 'integer'
|
14
|
-
param.required = true
|
15
|
-
end
|
16
|
-
refute_nil(@action.parameters['foo'], 'expected parameters to contain "foo"')
|
17
|
-
parameter = @action.parameters['foo']
|
18
|
-
assert_equal('integer', parameter.type)
|
19
|
-
assert(parameter.required, 'expected the parameter to be required')
|
20
|
-
|
21
|
-
@action.param('bar[nested]') do |param|
|
22
|
-
param.type = 'string'
|
23
|
-
param.required = false
|
24
|
-
end
|
25
|
-
refute_nil(@action.parameters['bar[nested]'], 'expected parameters to contain "bar[nested]"')
|
26
|
-
parameter = @action.parameters['bar[nested]']
|
27
|
-
assert_equal('string', parameter.type)
|
28
|
-
refute(parameter.required, 'expected the parameter to not be required')
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_link
|
32
|
-
assert_raises(ArgumentError) do
|
33
|
-
@action.link({})
|
34
|
-
end
|
35
|
-
|
36
|
-
assert_raises(ArgumentError) do
|
37
|
-
@action.link(name: 'Self', href: 'http://example.org/resource/{id}', templated: true)
|
38
|
-
end
|
39
|
-
|
40
|
-
assert_raises(ArgumentError) do
|
41
|
-
@action.link(name: 'Self', rel: 'self', templated: true)
|
42
|
-
end
|
43
|
-
|
44
|
-
@action.link(name: 'Self', rel: 'self', href: 'http://example.org/resource/{id}', templated: true)
|
45
|
-
refute_nil(@action.links['self'])
|
46
|
-
@action.link(name: 'Root', rel: 'root', href: 'http://example.org/')
|
47
|
-
refute_nil(@action.links['root'])
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_example
|
51
|
-
assert_empty(@action.examples)
|
52
|
-
@action.example do |e|
|
53
|
-
e.param('some[val]', '123')
|
54
|
-
end
|
55
|
-
assert_equal(1, @action.examples.count)
|
56
|
-
@action.example do |e|
|
57
|
-
e.param('some[val]', '123')
|
58
|
-
end
|
59
|
-
assert_equal(2, @action.examples.count)
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_to_h
|
63
|
-
@action.description = 'test'
|
64
|
-
@action.param(:foo) do |param|
|
65
|
-
param.type = 'integer'
|
66
|
-
param.required = true
|
67
|
-
param.allowed = [12]
|
68
|
-
end
|
69
|
-
|
70
|
-
hash = @action.to_h
|
71
|
-
|
72
|
-
assert_equal('test', hash['description'])
|
73
|
-
refute_nil(hash['links'])
|
74
|
-
refute_nil(hash['examples'])
|
75
|
-
refute_nil(hash['parameters'])
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
require 'skeleton/builder'
|
4
|
-
|
5
|
-
module Skeleton
|
6
|
-
class BuilderTest < Minitest::Test
|
7
|
-
def setup
|
8
|
-
@builder = Builder.new
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_define_single
|
12
|
-
@builder.define('get') do |action|
|
13
|
-
action.description = 'something'
|
14
|
-
end
|
15
|
-
refute_nil(@builder.actions['get'])
|
16
|
-
assert_equal('something', @builder.actions['get'].description)
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_define_extra
|
20
|
-
@builder.define('get', also: 'post') do |action|
|
21
|
-
action.description = 'something'
|
22
|
-
end
|
23
|
-
refute_nil(@builder.actions['get'])
|
24
|
-
refute_nil(@builder.actions['post'])
|
25
|
-
assert_equal('something', @builder.actions['get'].description)
|
26
|
-
assert_equal('something', @builder.actions['post'].description)
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_define_array
|
30
|
-
@builder.define('get', also: ['post']) do |action|
|
31
|
-
action.description = 'something'
|
32
|
-
end
|
33
|
-
refute_nil(@builder.actions['get'])
|
34
|
-
refute_nil(@builder.actions['post'])
|
35
|
-
assert_equal('something', @builder.actions['get'].description)
|
36
|
-
assert_equal('something', @builder.actions['post'].description)
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_define_multiple
|
40
|
-
@builder.define('get', also: ['post', 'head']) do |action|
|
41
|
-
action.description = 'something'
|
42
|
-
end
|
43
|
-
refute_nil(@builder.actions['get'])
|
44
|
-
refute_nil(@builder.actions['post'])
|
45
|
-
refute_nil(@builder.actions['head'])
|
46
|
-
assert_equal('something', @builder.actions['get'].description)
|
47
|
-
assert_equal('something', @builder.actions['post'].description)
|
48
|
-
assert_equal('something', @builder.actions['head'].description)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
data/test/skeleton/link_test.rb
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
require 'skeleton/link'
|
4
|
-
|
5
|
-
module Skeleton
|
6
|
-
class LinkTest < Minitest::Test
|
7
|
-
def setup
|
8
|
-
@link = Link.new(rel: 'self', name: 'Self', href: 'http://example.org')
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_initialize
|
12
|
-
assert_raises(ArgumentError) do
|
13
|
-
Link.new
|
14
|
-
end
|
15
|
-
assert_raises(ArgumentError) do
|
16
|
-
Link.new(rel: 'self')
|
17
|
-
end
|
18
|
-
|
19
|
-
Link.new(rel: 'self', href: 'http://example.org')
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_method_missing
|
23
|
-
assert_raises(NoMethodError) do
|
24
|
-
@link.foo
|
25
|
-
end
|
26
|
-
|
27
|
-
@link = Link.new(rel: 'self', href: 'http://example.org', foo: 'bar')
|
28
|
-
assert_equal('bar', @link.foo)
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_templated?
|
32
|
-
refute(@link.templated?)
|
33
|
-
@link.templated = 'asdf'
|
34
|
-
assert(@link.templated?)
|
35
|
-
@link.templated = false
|
36
|
-
refute(@link.templated?)
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_comparable
|
40
|
-
other = Link.new(rel: 'self', name: 'Self', href: 'http://example.org')
|
41
|
-
assert_equal(0, other <=> @link)
|
42
|
-
|
43
|
-
before = Link.new(rel: 'other', href: 'http://example.org')
|
44
|
-
assert_equal(-1, before <=> @link)
|
45
|
-
|
46
|
-
after = Link.new(rel: 'zoo', href: 'http://example.org')
|
47
|
-
assert_equal(1, after <=> @link)
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_eql?
|
51
|
-
other = Link.new(rel: 'self', name: 'Self', href: 'http://example.org')
|
52
|
-
assert(@link.eql?(other))
|
53
|
-
|
54
|
-
other = Link.new(rel: 'other', href: 'http://example.org')
|
55
|
-
refute(@link.eql?(other))
|
56
|
-
|
57
|
-
other = Object.new
|
58
|
-
refute(@link.eql?(other))
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_to_h
|
62
|
-
hash = @link.to_h
|
63
|
-
assert_equal('self', hash['rel'])
|
64
|
-
assert_equal('Self', hash['name'])
|
65
|
-
assert_equal('http://example.org', hash['href'])
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|