skeleton 0.3.3 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/README.md +140 -65
  4. data/Rakefile +10 -3
  5. data/lib/skeleton.rb +6 -10
  6. data/lib/skeleton/contact.rb +1 -13
  7. data/lib/skeleton/error.rb +4 -0
  8. data/lib/skeleton/graph.rb +56 -0
  9. data/lib/skeleton/header.rb +2 -63
  10. data/lib/skeleton/items.rb +34 -0
  11. data/lib/skeleton/license.rb +1 -12
  12. data/lib/skeleton/model.rb +13 -17
  13. data/lib/skeleton/operation.rb +50 -121
  14. data/lib/skeleton/parameter.rb +31 -88
  15. data/lib/skeleton/parameters.rb +40 -0
  16. data/lib/skeleton/path.rb +42 -80
  17. data/lib/skeleton/presenter.rb +19 -0
  18. data/lib/skeleton/property.rb +6 -0
  19. data/lib/skeleton/response.rb +24 -45
  20. data/lib/skeleton/schema.rb +80 -63
  21. data/lib/skeleton/scope.rb +18 -0
  22. data/lib/skeleton/security_scheme.rb +19 -37
  23. data/lib/skeleton/serializers/options.rb +215 -0
  24. data/lib/skeleton/serializers/swagger.rb +197 -0
  25. data/lib/skeleton/structure.rb +92 -138
  26. data/lib/skeleton/swagger.rb +9 -0
  27. data/lib/skeleton/tag.rb +11 -16
  28. data/lib/skeleton/version.rb +1 -1
  29. data/skeleton.gemspec +2 -0
  30. data/test/fixtures/json-schema-draft-04.json +150 -0
  31. data/test/fixtures/schema.json +1482 -0
  32. data/test/integrations/validate_complex_schema_spec.rb +42 -0
  33. data/test/skeleton/graph_test.rb +22 -0
  34. data/test/skeleton/mapper_test.rb +84 -0
  35. data/test/skeleton/operation_test.rb +11 -0
  36. data/test/skeleton/parameter_test.rb +34 -0
  37. data/test/skeleton/parameters_test.rb +9 -0
  38. data/test/skeleton/path_test.rb +46 -0
  39. data/test/skeleton/property_test.rb +8 -0
  40. data/test/skeleton/serializers/options_test.rb +68 -0
  41. data/test/skeleton/serializers/swagger_test.rb +30 -0
  42. data/test/support/factories/structure_factory.rb +86 -0
  43. data/test/support/fixtures.rb +6 -0
  44. data/test/support/kissmetrics/core_api.rb +542 -0
  45. data/{spec/spec_helper.rb → test/test_helper.rb} +7 -1
  46. metadata +73 -25
  47. data/lib/skeleton/config.rb +0 -37
  48. data/lib/skeleton/documentation.rb +0 -17
  49. data/lib/skeleton/example.rb +0 -31
  50. data/lib/skeleton/headers.rb +0 -50
  51. data/lib/skeleton/helpers/controller_helpers.rb +0 -25
  52. data/lib/skeleton/info.rb +0 -40
  53. data/lib/skeleton/item.rb +0 -99
  54. data/lib/skeleton/responses.rb +0 -59
  55. data/lib/skeleton/scopes.rb +0 -24
  56. data/lib/skeleton/security_definitions.rb +0 -46
  57. data/lib/skeleton/security_requirement.rb +0 -29
  58. data/spec/integrations/use_case_spec.rb +0 -131
  59. data/spec/skeleton/operation_spec.rb +0 -113
  60. data/spec/skeleton/serializers/contact_spec.rb +0 -30
  61. data/spec/skeleton/serializers/documentation_spec.rb +0 -23
  62. data/spec/skeleton/serializers/header_spec.rb +0 -57
@@ -1,59 +0,0 @@
1
- require 'skeleton/model'
2
- require 'skeleton/response'
3
-
4
- module Skeleton
5
- class Responses < Model
6
- attr_accessor :default
7
- attr_presence :default
8
-
9
- def initialize(args={})
10
- @responses = {}
11
- args.each { |k, v| set(k, v) }
12
- end
13
-
14
- def get(code)
15
- @responses[code]
16
- end
17
- alias_method :[], :get
18
-
19
- def set(code, value)
20
- case value
21
- when Hash
22
- @responses[code] = Skeleton::Response.new(value)
23
- else
24
- @responses[code] = value
25
- end
26
- end
27
- alias_method :[]=, :set
28
-
29
- def empty?
30
- @responses.empty?
31
- end
32
-
33
- def to_h
34
- hash = {}
35
- hash[:default] = default.to_h if default?
36
- @responses.each do |code, response|
37
- if response.respond_to?(:to_h)
38
- hash[code] = response.to_h
39
- else
40
- hash[code] = response
41
- end
42
- end
43
- hash
44
- end
45
-
46
- def to_swagger_hash
47
- hash = {}
48
- hash[:default] = default.to_h if default?
49
- @responses.each do |code, response|
50
- if response.respond_to?(:to_swagger_hash)
51
- hash[code] = response.to_swagger_hash
52
- else
53
- hash[code] = response
54
- end
55
- end
56
- hash
57
- end
58
- end
59
- end
@@ -1,24 +0,0 @@
1
- require 'skeleton/model'
2
-
3
- module Skeleton
4
- class Scopes < Model
5
- attr_reader :scopes
6
-
7
- def initialize
8
- @scopes = {}
9
- end
10
-
11
- def [](name)
12
- @scopes[name]
13
- end
14
-
15
- def []=(name, description)
16
- @scopes[name] = description
17
- end
18
-
19
- def to_h
20
- @scopes
21
- end
22
- alias_method :to_swagger_hash, :to_h
23
- end
24
- end
@@ -1,46 +0,0 @@
1
- require 'skeleton/model'
2
- require 'skeleton/security_scheme'
3
-
4
- module Skeleton
5
- class SecurityDefinitions < Model
6
- def initialize(args={})
7
- @schemes = {}
8
- args.each { |k, v| set(k, v) }
9
- end
10
-
11
- def get(name)
12
- @schemes[name]
13
- end
14
- alias_method :[], :get
15
-
16
- def set(name, value)
17
- case value
18
- when Hash
19
- @schemes[name] = Skeleton::SecurityScheme.new(value)
20
- else
21
- @schemes[name] = value
22
- end
23
- end
24
- alias_method :[]=, :set
25
-
26
- def empty?
27
- !@schemes.empty?
28
- end
29
-
30
- def to_h
31
- hash = {}
32
- @schemes.each do |name, scheme|
33
- hash[name] = scheme.to_h
34
- end
35
- hash
36
- end
37
-
38
- def to_swagger_hash
39
- hash = {}
40
- @schemes.each do |name, scheme|
41
- hash[name] = scheme.to_swagger_hash
42
- end
43
- hash
44
- end
45
- end
46
- end
@@ -1,29 +0,0 @@
1
- require 'skeleton/model'
2
-
3
- module Skeleton
4
- class SecurityRequirement < Model
5
- def initialize(args={})
6
- @requirements = []
7
- args.each { |name, value| set(name, value) }
8
- end
9
-
10
- def get(name)
11
- @requirements[name]
12
- end
13
- alias_method :[], :get
14
-
15
- def set(name, value)
16
- @requirements[name] = Array(value)
17
- end
18
- alias_method :[]=, :set
19
-
20
- def to_h
21
- hash = {}
22
- @requirements.each do |name, definition|
23
- hash[name] = definition
24
- end
25
- hash
26
- end
27
- alias_method :to_swagger_hash, :to_h
28
- end
29
- end
@@ -1,131 +0,0 @@
1
- require 'spec_helper'
2
-
3
- require 'skeleton'
4
-
5
- describe 'A simple use case' do
6
- describe 'validating the first case' do
7
- it 'works' do
8
- @structure = Skeleton.build do |s|
9
- s.host = 'api.example.com'
10
- s.info.version = '1.0'
11
- s.info.title = 'Waffles Emporium API'
12
- s.info.description = 'A test integration'
13
-
14
- s.info.contact.name = 'WarmWaffles'
15
- s.info.contact.email = 'warmwaffles@gmail.com'
16
- s.info.contact.url = 'https://github.com/warmwaffles/skeleton'
17
-
18
- s.info.license.name = 'MIT'
19
-
20
- s.schemes = %w(https)
21
- s.consumes = %(application/json)
22
- s.produces = %(application/json)
23
-
24
- s.path('/users') do |path|
25
- path.get do |o|
26
- o.tag('users')
27
- o.parameter(:query, 'limit') do |p|
28
- p.description = 'maximum number of results to return'
29
- p.type = 'integer'
30
- p.format = 'int32'
31
- p.required = false
32
- end
33
- o.parameter(:query, 'offset') do |p|
34
- p.description = 'offset within the results returned'
35
- p.type = 'integer'
36
- p.format = 'int32'
37
- p.required = false
38
- end
39
- end
40
-
41
- path.post do |o|
42
- o.tag('user')
43
- o.parameter(:body, 'user[email]') do |p|
44
- p.description = 'the user email'
45
- p.type = 'string'
46
- p.required = true
47
- end
48
- o.parameter(:body, 'user[name]') do |p|
49
- p.description = 'the user name'
50
- p.type = 'string'
51
- p.required = true
52
- end
53
- o.parameter(:body, 'user[password]') do |p|
54
- p.description = 'the user password'
55
- p.type = 'string'
56
- p.required = true
57
- end
58
- o.parameter(:body, 'user[password_confirmation]') do |p|
59
- p.description = 'the user password confirmation'
60
- p.type = 'string'
61
- p.required = true
62
- end
63
- end
64
- end
65
-
66
- s.path('/users/{user_id}') do |path|
67
- path.get do |o|
68
- o.tag('user')
69
- o.parameter(:query, 'user_id') do |p|
70
- p.description = 'the user id'
71
- p.type = 'string'
72
- p.format = 'uuid'
73
- p.required = true
74
- end
75
- end
76
-
77
- path.put do |o|
78
- o.tag('user')
79
- o.parameter(:body, 'user[email]') do |p|
80
- p.description = 'the user email'
81
- p.type = 'string'
82
- p.required = false
83
- end
84
- o.parameter(:body, 'user[name]') do |p|
85
- p.description = 'the user name'
86
- p.type = 'string'
87
- p.required = false
88
- end
89
- o.parameter(:body, 'user[password]') do |p|
90
- p.description = 'the user password'
91
- p.type = 'string'
92
- p.required = false
93
- end
94
- o.parameter(:body, 'user[password_confirmation]') do |p|
95
- p.description = 'the user password confirmation'
96
- p.type = 'string'
97
- p.required = false
98
- end
99
- end
100
-
101
- path.patch do |o|
102
- o.tag('user')
103
- o.parameter(:body, 'user[email]') do |p|
104
- p.description = 'the user email'
105
- p.type = 'string'
106
- p.required = false
107
- end
108
- o.parameter(:body, 'user[name]') do |p|
109
- p.description = 'the user name'
110
- p.type = 'string'
111
- p.required = false
112
- end
113
- o.parameter(:body, 'user[password]') do |p|
114
- p.description = 'the user password'
115
- p.type = 'string'
116
- p.required = false
117
- end
118
- o.parameter(:body, 'user[password_confirmation]') do |p|
119
- p.description = 'the user password confirmation'
120
- p.type = 'string'
121
- p.required = false
122
- end
123
- end
124
- end
125
- end
126
- @structure.to_json
127
- @structure.to_swagger_json
128
- end
129
-
130
- end
131
- end
@@ -1,113 +0,0 @@
1
- require 'spec_helper'
2
-
3
- require 'skeleton/operation'
4
-
5
- describe Skeleton::Operation do
6
- describe '#summary=' do
7
- it 'sets the summary' do
8
- operation = Skeleton::Operation.new
9
- operation.summary = 'foo bar'
10
- assert_equal('foo bar', operation.summary)
11
- end
12
- end
13
-
14
- describe '#summary?' do
15
- context 'when not set' do
16
- it 'returns false' do
17
- operation = Skeleton::Operation.new
18
- refute(operation.summary?)
19
- end
20
- end
21
-
22
- context 'when set' do
23
- it 'returns true' do
24
- operation = Skeleton::Operation.new(summary: 'foo bar')
25
- assert(operation.summary?)
26
- end
27
- end
28
- end
29
-
30
- describe '#consumes' do
31
- context 'when not set' do
32
- it 'returns an empty array' do
33
- operation = Skeleton::Operation.new
34
- assert_empty(operation.consumes)
35
- end
36
- end
37
-
38
- context 'when set' do
39
- it 'returns strings' do
40
- operation = Skeleton::Operation.new({consumes: ['application/json', 'application/xml']})
41
- assert_includes(operation.consumes, 'application/json')
42
- assert_includes(operation.consumes, 'application/xml')
43
- end
44
- end
45
- end
46
-
47
- describe '#consumes?' do
48
- context 'when not set' do
49
- it 'returns an empty array' do
50
- operation = Skeleton::Operation.new
51
- refute(operation.consumes?)
52
- end
53
- end
54
-
55
- context 'when set' do
56
- it 'returns strings' do
57
- operation = Skeleton::Operation.new({consumes: ['application/json', 'application/xml']})
58
- assert(operation.consumes?)
59
- end
60
- end
61
- end
62
-
63
- describe '#produces' do
64
- context 'when not set' do
65
- it 'returns an empty array' do
66
- operation = Skeleton::Operation.new
67
- assert_empty(operation.produces)
68
- end
69
- end
70
-
71
- context 'when set' do
72
- it 'returns strings' do
73
- operation = Skeleton::Operation.new({produces: ['application/json', 'application/xml']})
74
- assert_includes(operation.produces, 'application/json')
75
- assert_includes(operation.produces, 'application/xml')
76
- end
77
- end
78
- end
79
-
80
- describe '#produces?' do
81
- context 'when not set' do
82
- it 'returns an empty array' do
83
- operation = Skeleton::Operation.new
84
- refute(operation.produces?)
85
- end
86
- end
87
-
88
- context 'when set' do
89
- it 'returns strings' do
90
- operation = Skeleton::Operation.new({produces: ['application/json', 'application/xml']})
91
- assert(operation.produces?)
92
- end
93
- end
94
- end
95
-
96
- describe '#to_h' do
97
- context 'when nothing is set' do
98
- it 'returns an empty hash' do
99
- operation = Skeleton::Operation.new
100
- assert_empty(operation.to_h)
101
- end
102
- end
103
-
104
- context 'when consumes is set' do
105
- it 'returns a hash with the consumes field' do
106
- operation = Skeleton::Operation.new({consumes: ['application/json', 'application/xml']})
107
- hash = operation.to_h
108
- refute_empty(hash, 'expected the hash to contain data')
109
- assert(hash.key?(:consumes), 'expected the hash to contain :consumes')
110
- end
111
- end
112
- end
113
- end
@@ -1,30 +0,0 @@
1
- require 'spec_helper'
2
-
3
- require 'skeleton/contact'
4
-
5
- describe Skeleton::Contact do
6
- before do
7
- @contact = Skeleton::Contact.new
8
- end
9
-
10
- describe '#name=' do
11
- it 'sets the name' do
12
- @contact.name = 'foo'
13
- assert_equal('foo', @contact.name)
14
- end
15
- end
16
-
17
- describe '#email=' do
18
- it 'sets the email' do
19
- @contact.email = 'foo'
20
- assert_equal('foo', @contact.email)
21
- end
22
- end
23
-
24
- describe '#url=' do
25
- it 'sets the url' do
26
- @contact.url = 'foo'
27
- assert_equal('foo', @contact.url)
28
- end
29
- end
30
- end
@@ -1,23 +0,0 @@
1
- require 'spec_helper'
2
-
3
- require 'skeleton/documentation'
4
-
5
- describe Skeleton::Documentation do
6
- before do
7
- @documentation = Skeleton::Documentation.new
8
- end
9
-
10
- describe '#description=' do
11
- it 'sets the description' do
12
- @documentation.description = 'foo'
13
- assert_equal('foo', @documentation.description)
14
- end
15
- end
16
-
17
- describe '#url=' do
18
- it 'sets the url' do
19
- @documentation.url = 'foo'
20
- assert_equal('foo', @documentation.url)
21
- end
22
- end
23
- end