Class: OpenapiRuby::Core::DocumentBuilder
- Inherits:
-
Object
- Object
- OpenapiRuby::Core::DocumentBuilder
- Defined in:
- lib/openapi_ruby/core/document_builder.rb
Instance Method Summary collapse
- #add_path(template, operations) ⇒ Object
- #add_security(security) ⇒ Object
- #add_tag(tag) ⇒ Object
- #build ⇒ Object
-
#initialize(spec_config = {}) ⇒ DocumentBuilder
constructor
A new instance of DocumentBuilder.
- #merge_components(components_hash) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(spec_config = {}) ⇒ DocumentBuilder
Returns a new instance of DocumentBuilder.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/openapi_ruby/core/document_builder.rb', line 6 def initialize(spec_config = {}) @spec_config = spec_config @document = Document.new( info: spec_config[:info] || {}, servers: spec_config[:servers] || [] ) @paths = {} @components = {} @security = [] @tags = [] end |
Instance Method Details
#add_path(template, operations) ⇒ Object
18 19 20 21 |
# File 'lib/openapi_ruby/core/document_builder.rb', line 18 def add_path(template, operations) @paths[template] ||= {} @paths[template].deep_merge!(operations) end |
#add_security(security) ⇒ Object
27 28 29 |
# File 'lib/openapi_ruby/core/document_builder.rb', line 27 def add_security(security) @security.concat(Array(security)) end |
#add_tag(tag) ⇒ Object
31 32 33 |
# File 'lib/openapi_ruby/core/document_builder.rb', line 31 def add_tag(tag) @tags << tag unless @tags.any? { |t| t["name"] == tag["name"] } end |
#build ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/openapi_ruby/core/document_builder.rb', line 35 def build @paths.each { |template, path_item| @document.add_path(template, path_item) } @document.set_components(@components) @document.set_security(@security) @document.(@tags) @document end |
#merge_components(components_hash) ⇒ Object
23 24 25 |
# File 'lib/openapi_ruby/core/document_builder.rb', line 23 def merge_components(components_hash) @components.deep_merge!(components_hash) end |
#to_h ⇒ Object
43 44 45 |
# File 'lib/openapi_ruby/core/document_builder.rb', line 43 def to_h build.to_h end |