Class: Fictium::OpenApi::V3Exporter::ExampleFormatter
- Inherits:
-
Object
- Object
- Fictium::OpenApi::V3Exporter::ExampleFormatter
- Defined in:
- lib/fictium/exporters/open_api/v3_exporter/example_formatter.rb
Instance Method Summary collapse
- #content_formatter ⇒ Object
- #default_response_content_type ⇒ Object
- #extract_headers(example) ⇒ Object
- #format(example) ⇒ Object
- #format_default(operation, responses, default_example) ⇒ Object
- #header_formatter ⇒ Object
Instance Method Details
#content_formatter ⇒ Object
36 37 38 |
# File 'lib/fictium/exporters/open_api/v3_exporter/example_formatter.rb', line 36 def content_formatter @content_formatter ||= ContentFormatter.new end |
#default_response_content_type ⇒ Object
24 25 26 |
# File 'lib/fictium/exporters/open_api/v3_exporter/example_formatter.rb', line 24 def default_response_content_type Fictium.configuration.default_response_content_type end |
#extract_headers(example) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/fictium/exporters/open_api/v3_exporter/example_formatter.rb', line 28 def extract_headers(example) {}.tap do |headers| example.headers.each do |name, value| headers[name] = header_formatter.format(name, :header, value) end end end |
#format(example) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/fictium/exporters/open_api/v3_exporter/example_formatter.rb', line 15 def format(example) { description: example.summary }.tap do |format| content = content_formatter.format(example.response, default_response_content_type) format[:content] = content if content.present? headers = extract_headers(example) format[:headers] = headers if headers.present? end end |
#format_default(operation, responses, default_example) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/fictium/exporters/open_api/v3_exporter/example_formatter.rb', line 5 def format_default(operation, responses, default_example) responses[:default] = format(default_example) return if default_example.request[:content_type].blank? operation[:requestBody] = { content: content_formatter.format(default_example.request) } operation[:requestBody][:required] = true if default_example.request[:required] end |
#header_formatter ⇒ Object
40 41 42 |
# File 'lib/fictium/exporters/open_api/v3_exporter/example_formatter.rb', line 40 def header_formatter @header_formatter ||= ParamFormatter.new(ignore_name: true, ignore_in: true) end |