class R2OAS::Schema::V3::PathItemObject
Constants
- SUPPORT_FIELD_NAME
reference github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#path-item-object Support Field Name: get, put, post, delete, patch
Public Class Methods
new(route_data, path, opts = {})
click to toggle source
Calls superclass method
R2OAS::Schema::V3::BaseObject::new
# File lib/r2-oas/schema/v3/object/from_routes/path_item_object.rb, line 21 def initialize(route_data, path, opts = {}) super(opts) @path_comp = Routing::PathComponent.new(path) @path = @path_comp.symbol_to_brace @route_data = route_data @verb = route_data[:verb] @tag_name = route_data[:tag_name] @schema_name = route_data[:schema_name] @required_parameters = route_data[:required_parameters] @format_name = create_format_name @http_status_manager = HttpStatusManager.new(@path, @verb, http_statuses_when_http_method) @components_schema_object = Components::SchemaObject.new(route_data, path, opts) @components_request_body_object = Components::RequestBodyObject.new(route_data, path, opts) support_field_name? if route_data.key?(:verb) end
Public Instance Methods
create_doc()
click to toggle source
# File lib/r2-oas/schema/v3/object/from_routes/path_item_object.rb, line 42 def create_doc result = { @verb.to_s => data_when_verb } attach_request_body!(result) attach_media_type!(result) attach_parameters!(result) doc.merge!(result) end
to_doc()
click to toggle source
# File lib/r2-oas/schema/v3/object/from_routes/path_item_object.rb, line 37 def to_doc create_doc doc end
Private Instance Methods
_components_request_body_name()
click to toggle source
# File lib/r2-oas/schema/v3/object/from_routes/path_item_object.rb, line 94 def _components_request_body_name @components_request_body_object.send(:_components_request_body_name) end
_components_schema_name(http_status)
click to toggle source
# File lib/r2-oas/schema/v3/object/from_routes/path_item_object.rb, line 90 def _components_schema_name(http_status) @components_schema_object.send(:_components_schema_name, http_status) end
attach_media_type!(schema)
click to toggle source
# File lib/r2-oas/schema/v3/object/from_routes/path_item_object.rb, line 118 def attach_media_type!(schema) return schema if @format_name.blank? merge_schema = { '200' => { 'description' => 'responses description', 'content' => { @format_name.to_s => {} } } } schema[@verb.to_s]['responses'].deep_merge!(merge_schema) schema end
attach_parameters!(schema)
click to toggle source
# File lib/r2-oas/schema/v3/object/from_routes/path_item_object.rb, line 133 def attach_parameters!(schema) return schema if @required_parameters.blank? content = @required_parameters.each_with_object([]) do |(parameter_name, parameter_data), result| result.push( 'name' => parameter_name.to_s, 'in' => 'path', 'description' => parameter_name.to_s, 'required' => true, 'schema' => { 'type' => parameter_data[:type] } ) end merge_schema = { 'parameters' => content } schema[@verb.to_s].deep_merge!(merge_schema) schema end
attach_request_body!(schema)
click to toggle source
# File lib/r2-oas/schema/v3/object/from_routes/path_item_object.rb, line 107 def attach_request_body!(schema) return schema unless @components_request_body_object.generate? merge_schema = { '$ref' => "#/components/requestBodies/#{_components_request_body_name}" } schema[@verb.to_s]['requestBody'] = {} schema[@verb.to_s]['requestBody'].deep_merge!(merge_schema) schema end
create_format_name()
click to toggle source
# File lib/r2-oas/schema/v3/object/from_routes/path_item_object.rb, line 98 def create_format_name format_name = @route_data[:format_name] if format_name.blank? '' else "application/#{format_name}" end end
data_when_verb()
click to toggle source
# File lib/r2-oas/schema/v3/object/from_routes/path_item_object.rb, line 52 def data_when_verb result = { 'tags' => [@tag_name.to_s], 'summary' => "#{@verb} summary", 'description' => "#{@verb} description", # Response Object 'responses' => {}, 'deprecated' => false } result['responses'].deep_merge!(responses_when_http_status) result end
responses_when_http_status()
click to toggle source
# File lib/r2-oas/schema/v3/object/from_routes/path_item_object.rb, line 65 def responses_when_http_status http_statuses.each_with_object({}) do |http_status, result| if ignored_http_statuses_when_generate_component_schema.include?(http_status) result.deep_merge!( http_status => { 'description' => "#{@tag_name} description" } ) else result.deep_merge!( http_status => { 'description' => "#{@tag_name} description", 'content' => { 'application/json' => { 'schema' => { '$ref' => "#/components/schemas/#{_components_schema_name(http_status)}" } } } } ) end end end
support_field_name?()
click to toggle source
# File lib/r2-oas/schema/v3/object/from_routes/path_item_object.rb, line 156 def support_field_name? raise "Invalid filed name #{field_name}" unless SUPPORT_FIELD_NAME.include?(@verb) end