class Fictium::OpenApi::V3Exporter::PathFormatter
Public Instance Methods
add_path(paths, action)
click to toggle source
# File lib/fictium/exporters/open_api/v3_exporter/path_formatter.rb, line 5 def add_path(paths, action) return if action.method.blank? path_object = paths[action.full_path] || default_path_object path_object[action.method.to_sym] = create_operation(action) paths[action.full_path] = path_object end
Private Instance Methods
create_operation(action)
click to toggle source
# File lib/fictium/exporters/open_api/v3_exporter/path_formatter.rb, line 19 def create_operation(action) {}.tap do |operation| operation[:tags] = action.combined_tags operation[:description] = action.summary operation[:parameters] = format_parameters(action) operation[:responses] = format_responses(operation, action) operation[:deprecated] = action.deprecated? end end
default_path_object()
click to toggle source
# File lib/fictium/exporters/open_api/v3_exporter/path_formatter.rb, line 15 def default_path_object { description: '' } end
example_formatter()
click to toggle source
# File lib/fictium/exporters/open_api/v3_exporter/path_formatter.rb, line 56 def example_formatter @example_formatter ||= ExampleFormatter.new end
format_example(responses, example)
click to toggle source
# File lib/fictium/exporters/open_api/v3_exporter/path_formatter.rb, line 50 def format_example(responses, example) return if example.response.blank? responses[example.response[:status]] = example_formatter.format(example) end
format_parameters(action)
click to toggle source
# File lib/fictium/exporters/open_api/v3_exporter/path_formatter.rb, line 29 def format_parameters(action) [].tap do |result| action.params.each do |section, values| values.each do |name, data| result << param_formatter.format(name, section, data) end end end end
format_responses(operation, action)
click to toggle source
# File lib/fictium/exporters/open_api/v3_exporter/path_formatter.rb, line 39 def format_responses(operation, action) {}.tap do |responses| default_example = action.default_example break if default_example.blank? example_formatter.format_default(operation, responses, default_example) other_examples = action.examples.reject { |example| example == default_example } other_examples.each { |example| format_example(responses, example) } end end
param_formatter()
click to toggle source
# File lib/fictium/exporters/open_api/v3_exporter/path_formatter.rb, line 60 def param_formatter @param_formatter ||= ParamFormatter.new end