Skip to content

Commit a60933d

Browse files
committed
Merge remote-tracking branch 'aadi/aadi/oas3' into oas3
2 parents bd393ba + 5749585 commit a60933d

26 files changed

+279
-194
lines changed

lib/rspec_api_documentation.rb

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,27 @@ module Writers
5454
module OpenApi
5555
extend ActiveSupport::Autoload
5656

57+
autoload :Components
58+
autoload :Contact
59+
autoload :ExternalDocs
60+
autoload :Flow
61+
autoload :Header
5762
autoload :Helper
58-
autoload :Node
59-
autoload :Root
6063
autoload :Info
61-
autoload :Contact
6264
autoload :License
63-
autoload :Paths
64-
autoload :Path
65-
autoload :Tag
65+
autoload :Media
66+
autoload :Node
6667
autoload :Operation
6768
autoload :Parameter
68-
autoload :Responses
69+
autoload :Path
70+
autoload :RequestBody
6971
autoload :Response
70-
autoload :Example
71-
autoload :Headers
72-
autoload :Header
72+
autoload :Root
7373
autoload :Schema
74-
autoload :SecurityDefinitions
75-
autoload :SecuritySchema
74+
autoload :SecurityScheme
75+
autoload :Server
76+
autoload :Tag
77+
autoload :Variable
7678
end
7779

7880
module Views
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module RspecApiDocumentation
2+
module OpenApi
3+
class Components < Node
4+
add_setting :schemas, :schema => { '' => Schema }
5+
add_setting :responses, :schema => { '' => Response }
6+
add_setting :parameters, :schema => { '' => Parameter }
7+
add_setting :headers, :schema => { '' => Header }
8+
add_setting :securitySchemes, :schema => { '' => SecurityScheme }
9+
add_setting :links
10+
add_setting :callbacks
11+
end
12+
end
13+
end

lib/rspec_api_documentation/open_api/example.rb

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module RspecApiDocumentation
2+
module OpenApi
3+
class ExternalDocs < Node
4+
add_setting :description
5+
add_setting :url, :required => true
6+
end
7+
end
8+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module RspecApiDocumentation
2+
module OpenApi
3+
class Flow < Node
4+
add_setting :authorizationUrl, :required => true
5+
add_setting :tokenUrl, :required => true
6+
add_setting :refreshUrl
7+
add_setting :scopes, :required => true
8+
end
9+
end
10+
end

lib/rspec_api_documentation/open_api/header.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ module RspecApiDocumentation
22
module OpenApi
33
class Header < Node
44
add_setting :description
5-
add_setting :type, :required => true, :default => lambda { |header|
6-
Helper.extract_type(header.public_send('x-example-value'))
7-
}
8-
add_setting :format
9-
add_setting 'x-example-value'
5+
add_setting :required
6+
add_setting :deprecated
7+
# add_setting :allowEmptyValue
8+
# add_setting :style
9+
# add_setting :explode
10+
# add_setting :allowReserved
11+
add_setting :schema, :schema => Schema
12+
add_setting :example
13+
# add_setting :examples, :schema => { '' => Example }
14+
# add_setting :content, :schema => { '' => Media }
1015
end
1116
end
1217
end

lib/rspec_api_documentation/open_api/headers.rb

Lines changed: 0 additions & 7 deletions
This file was deleted.

lib/rspec_api_documentation/open_api/helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def extract_type(value)
1616
end
1717

1818
def extract_items(value, opts = {})
19-
result = {type: extract_type(value)}
19+
result = { type: extract_type(value) }
2020
if result[:type] == :array
2121
result[:items] = extract_items(value[0], opts)
2222
else
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module RspecApiDocumentation
2+
module OpenApi
3+
class Media < Node
4+
add_setting :schema, :schema => Schema
5+
add_setting :example
6+
# add_setting :examples, :schema => { '' => Example }
7+
# add_setting :encoding, :schema => { '' => Encoding }
8+
end
9+
end
10+
end

lib/rspec_api_documentation/open_api/node.rb

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
module RspecApiDocumentation
22
module OpenApi
33
class Node
4-
# this is used to define class of incoming option attribute
5-
# If +false+ then do not create new setting
6-
# If +true+ then create new setting with raw passed value
7-
# If RspecApiDocumentation::OpenApi::Node then create new setting and wrap it in this class
8-
CHILD_CLASS = false
9-
104
# This attribute allow us to hide some of children through configuration file
115
attr_accessor :hide
126

@@ -36,14 +30,15 @@ def initialize(opts = {})
3630
opts.each do |name, value|
3731
if name.to_s == 'hide'
3832
self.hide = value
39-
elsif self.class::CHILD_CLASS
40-
add_setting name, :value => self.class::CHILD_CLASS === true ? value : self.class::CHILD_CLASS.new(value)
4133
elsif setting_exist?(name.to_sym)
4234
schema = setting_schema(name)
4335
converted =
44-
case
45-
when schema.is_a?(Array) && schema[0] <= Node then value.map { |v| v.is_a?(schema[0]) ? v : schema[0].new(v) }
46-
when schema <= Node then value.is_a?(schema) ? value : schema.new(value)
36+
if schema.is_a?(Hash) && schema.values[0] <= Node
37+
Hash[value.map { |k, v| [k, v.is_a?(schema.values[0]) ? v : schema.values[0].new(v)] }]
38+
elsif schema.is_a?(Array) && schema[0] <= Node
39+
value.map { |v| v.is_a?(schema[0]) ? v : schema[0].new(v) }
40+
elsif schema <= Node
41+
value.is_a?(schema) ? value : schema.new(value)
4742
else
4843
value
4944
end
@@ -69,7 +64,13 @@ def add_setting(name, opts = {})
6964
settings[name] = opts[:value] if opts[:value]
7065

7166
define_singleton_method("#{name}_schema") { opts[:schema] || NilClass }
72-
define_singleton_method("#{name}=") { |value| settings[name] = value }
67+
define_singleton_method("#{name}=") do |value|
68+
if setting[name].is_a?(Hash) && value.is_a?(Hash)
69+
value.each { |k, v| setting[name][k] = setting[name][k] ? setting[name][k].merge(v) : v }
70+
else
71+
settings[name] = value
72+
end
73+
end
7374
define_singleton_method("#{name}") do
7475
if settings.has_key?(name)
7576
settings[name]
@@ -94,6 +95,8 @@ def as_json
9495
when value.is_a?(Array) && value[0].is_a?(Node)
9596
tmp = value.select { |v| !v.hide }.map { |v| v.as_json }
9697
hash[name] = tmp unless tmp.empty?
98+
when value.is_a?(Hash) && value.values[0].is_a?(Node)
99+
hash[name] = Hash[value.select { |k, v| !v.hide }.map { |k, v| [k, v.as_json] }]
97100
else
98101
hash[name] = value
99102
end unless value.nil?

0 commit comments

Comments
 (0)