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 17 |
# 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] || [], openapi_version: spec_config[:openapi_version] || Document::DEFAULT_OPENAPI_VERSION ) @paths = {} @components = {} @security = [] @tags = [] end |
Instance Method Details
#add_path(template, operations) ⇒ Object
19 20 21 22 |
# File 'lib/openapi_ruby/core/document_builder.rb', line 19 def add_path(template, operations) @paths[template] ||= {} @paths[template].deep_merge!(operations) end |
#add_security(security) ⇒ Object
28 29 30 |
# File 'lib/openapi_ruby/core/document_builder.rb', line 28 def add_security(security) @security.concat(Array(security)) end |
#add_tag(tag) ⇒ Object
32 33 34 |
# File 'lib/openapi_ruby/core/document_builder.rb', line 32 def add_tag(tag) @tags << tag unless @tags.any? { |t| t["name"] == tag["name"] } end |
#build ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/openapi_ruby/core/document_builder.rb', line 36 def build inject_validation_error_responses! if OpenapiRuby.configuration.auto_validation_error_response @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
24 25 26 |
# File 'lib/openapi_ruby/core/document_builder.rb', line 24 def merge_components(components_hash) @components.deep_merge!(components_hash) end |
#to_h ⇒ Object
45 46 47 |
# File 'lib/openapi_ruby/core/document_builder.rb', line 45 def to_h build.to_h end |