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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +92 -69
  3. data/Rakefile +2 -7
  4. data/lib/skeleton.rb +14 -4
  5. data/lib/skeleton/attributes.rb +19 -0
  6. data/lib/skeleton/config.rb +38 -0
  7. data/lib/skeleton/contact.rb +17 -0
  8. data/lib/skeleton/documentation.rb +17 -0
  9. data/lib/skeleton/example.rb +20 -6
  10. data/lib/skeleton/header.rb +67 -0
  11. data/lib/skeleton/headers.rb +50 -0
  12. data/lib/skeleton/helpers/controller_helpers.rb +25 -0
  13. data/lib/skeleton/info.rb +40 -0
  14. data/lib/skeleton/item.rb +99 -0
  15. data/lib/skeleton/license.rb +16 -0
  16. data/lib/skeleton/model.rb +31 -0
  17. data/lib/skeleton/operation.rb +157 -0
  18. data/lib/skeleton/parameter.rb +100 -20
  19. data/lib/skeleton/path.rb +111 -0
  20. data/lib/skeleton/response.rb +59 -0
  21. data/lib/skeleton/responses.rb +59 -0
  22. data/lib/skeleton/schema.rb +70 -0
  23. data/lib/skeleton/scopes.rb +24 -0
  24. data/lib/skeleton/security_definitions.rb +46 -0
  25. data/lib/skeleton/security_requirement.rb +29 -0
  26. data/lib/skeleton/security_scheme.rb +47 -0
  27. data/lib/skeleton/serializers/swagger.rb +212 -0
  28. data/lib/skeleton/structure.rb +191 -0
  29. data/lib/skeleton/tag.rb +24 -0
  30. data/lib/skeleton/version.rb +1 -1
  31. data/spec/integrations/use_case_spec.rb +130 -0
  32. data/spec/skeleton/operation_spec.rb +113 -0
  33. data/spec/skeleton/serializers/contact_spec.rb +30 -0
  34. data/spec/skeleton/serializers/documentation_spec.rb +23 -0
  35. data/spec/skeleton/serializers/header_spec.rb +57 -0
  36. data/spec/spec_helper.rb +8 -0
  37. metadata +36 -15
  38. data/lib/skeleton/action.rb +0 -46
  39. data/lib/skeleton/builder.rb +0 -47
  40. data/lib/skeleton/link.rb +0 -57
  41. data/spec/skeleton/integrated_spec.rb +0 -38
  42. data/test/skeleton/action_test.rb +0 -78
  43. data/test/skeleton/builder_test.rb +0 -51
  44. data/test/skeleton/link_test.rb +0 -68
  45. data/test/test_helper.rb +0 -6
@@ -0,0 +1,111 @@
1
+ require 'skeleton/operation'
2
+ require 'skeleton/parameter'
3
+ require 'skeleton/model'
4
+
5
+ module Skeleton
6
+ class Path < Model
7
+ attr_accessor :ref
8
+ attr_writer :operations
9
+ attr_not_empty :parameters, :operations
10
+
11
+ def operations
12
+ @operations ||= {}
13
+ end
14
+
15
+ def parameters=(value)
16
+ @parameters = Array(value)
17
+ end
18
+
19
+ def parameters
20
+ @parameters ||= []
21
+ end
22
+
23
+ def parameter(location, name, &block)
24
+ param = Skeleton::Parameter.new({name: name})
25
+ yield(param) if block
26
+ parameters << param
27
+ end
28
+
29
+ def get(&block)
30
+ define_operation(:get, &block)
31
+ end
32
+
33
+ def put(&block)
34
+ define_operation(:put, &block)
35
+ end
36
+
37
+ def post(&block)
38
+ define_operation(:post, &block)
39
+ end
40
+
41
+ def delete(&block)
42
+ define_operation(:delete, &block)
43
+ end
44
+
45
+ def options(&block)
46
+ define_operation(:options, &block)
47
+ end
48
+
49
+ def head(&block)
50
+ define_operation(:head, &block)
51
+ end
52
+
53
+ def patch(&block)
54
+ define_operation(:patch, &block)
55
+ end
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
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,59 @@
1
+ require 'skeleton/model'
2
+ require 'skeleton/headers'
3
+ require 'skeleton/schema'
4
+
5
+ module Skeleton
6
+ class Response < Model
7
+ attr_accessor :description
8
+ attr_reader :headers, :schema
9
+ attr_presence :descriptions, :examples
10
+ attr_not_empty :headers, :schema
11
+
12
+ def headers=(value)
13
+ case value
14
+ when Hash
15
+ @headers = Skeleton::Headers.new(value)
16
+ else
17
+ @headers = value
18
+ end
19
+ end
20
+
21
+ def schema=(value)
22
+ case value
23
+ when Hash
24
+ @schema = Skeleton::Schema.new(value)
25
+ else
26
+ @schema = value
27
+ end
28
+ end
29
+
30
+ def examples=(value)
31
+ case value
32
+ when Hash
33
+ @examples = Skeleton::Example.new(value)
34
+ else
35
+ @examples = value
36
+ end
37
+ end
38
+
39
+ def to_h
40
+ hash = {}
41
+ hash[:description] = description if description?
42
+ hash[:examples] = examples.to_h if examples?
43
+ hash[:headers] = headers.to_h if headers?
44
+ hash[:schema] = schema.to_h if schema?
45
+ hash[:examples] = examples.to_h if examples?
46
+ hash
47
+ end
48
+
49
+ def to_swagger_hash
50
+ hash = {}
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
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,59 @@
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
@@ -0,0 +1,70 @@
1
+ require 'skeleton/model'
2
+
3
+ module Skeleton
4
+ class Schema < Model
5
+ attr_accessor :ref, :type, :format, :title, :description, :default,
6
+ :multiple_of, :maximum, :exclusive_maximum, :minimum,
7
+ :exclusive_minimum, :max_length, :min_length, :pattern,
8
+ :max_items, :min_items, :unique_items, :max_properties,
9
+ :min_properties, :required, :enum, :discriminator, :read_only,
10
+ :xml, :external_docs, :example
11
+
12
+ attr_presence :required, :exclusive_maximum, :exclusive_minimum,
13
+ :unique_items, :discriminator, :read_only, :xml,
14
+ :external_docs, :example
15
+
16
+ def to_h
17
+ hash = {}
18
+ hash[:type] = type if type?
19
+ hash[:format] = format if format?
20
+
21
+ hash[:items] = items.to_hash if items?
22
+
23
+ hash[:title] = title if title?
24
+ hash[:description] = description if description?
25
+ hash[:default] = default if default?
26
+ hash[:multiple_of] = multiple_of if multiple_of?
27
+ hash[:maximum] = maximum if maximum?
28
+ hash[:exclusive_maximum] = exclusive_maximum if exclusive_maximum?
29
+ hash[:minimum] = minimum if minimum?
30
+ hash[:exclusive_minimum] = exclusive_minimum if exclusive_minimum?
31
+ hash[:max_length] = max_length if max_length?
32
+ hash[:min_length] = min_length if min_length?
33
+ hash[:pattern] = pattern if pattern?
34
+ hash[:max_items] = max_items if max_items?
35
+ hash[:min_items] = min_items if min_items?
36
+ hash[:unique_items] = unique_items if unique_items?
37
+ hash[:max_properties] = max_properties if max_properties?
38
+ hash[:min_properties] = min_properties if min_properties?
39
+ hash[:enum] = enum if enum?
40
+ hash
41
+ end
42
+
43
+ def to_swagger_hash
44
+ hash = {}
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
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,24 @@
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
@@ -0,0 +1,46 @@
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
@@ -0,0 +1,29 @@
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
@@ -0,0 +1,47 @@
1
+ require 'skeleton/model'
2
+ require 'skeleton/scopes'
3
+
4
+ module Skeleton
5
+ class SecurityScheme < Model
6
+ attr_accessor :type, :description, :name, :location, :flow, :authorization_url,
7
+ :token_url, :scopes
8
+
9
+ attr_presence :type, :description, :name, :location, :flow, :authorization_url,
10
+ :token_url, :scopes
11
+
12
+ def scopes=(value)
13
+ case value
14
+ when Hash
15
+ @scopes = Skeleton::Scopes.new(value)
16
+ else
17
+ @scopes = value
18
+ end
19
+ end
20
+
21
+ def to_h
22
+ hash = {}
23
+ hash[:type] = type if type?
24
+ hash[:description] = description if description?
25
+ hash[:name] = name if name?
26
+ hash[:location] = location if location?
27
+ hash[:flow] = flow if flow?
28
+ hash[:authorization_url] = authorization_url if authorization_url?
29
+ hash[:token_url] = token_url if token_url?
30
+ hash[:scopes] = scopes.to_h if scopes?
31
+ hash
32
+ end
33
+
34
+ def to_swagger_hash
35
+ hash = {}
36
+ hash[:type] = type if type?
37
+ hash[:description] = description if description?
38
+ hash[:name] = name if name?
39
+ hash[:location] = location if location?
40
+ hash[:flow] = flow if flow?
41
+ hash[:authorizationUrl] = authorization_url if authorization_url?
42
+ hash[:tokenUrl] = token_url if token_url?
43
+ hash[:scopes] = scopes.to_swagger_hash if scopes?
44
+ hash
45
+ end
46
+ end
47
+ end