Class: OpenapiRuby::DSL::ResponseContext
- Inherits:
-
Object
- Object
- OpenapiRuby::DSL::ResponseContext
- Defined in:
- lib/openapi_ruby/dsl/response_context.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#examples ⇒ Object
readonly
Returns the value of attribute examples.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#links ⇒ Object
readonly
Returns the value of attribute links.
-
#schema_definition ⇒ Object
readonly
Returns the value of attribute schema_definition.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
Instance Method Summary collapse
- #example(content_type, value:, name: "example", summary: nil, description: nil) ⇒ Object
- #header(name, attributes = {}) ⇒ Object
-
#initialize(status_code, description) ⇒ ResponseContext
constructor
A new instance of ResponseContext.
- #produces(*content_types) ⇒ Object
- #schema(definition) ⇒ Object
- #to_openapi ⇒ Object
Constructor Details
#initialize(status_code, description) ⇒ ResponseContext
Returns a new instance of ResponseContext.
8 9 10 11 12 13 14 15 16 |
# File 'lib/openapi_ruby/dsl/response_context.rb', line 8 def initialize(status_code, description) @status_code = status_code.to_s @description = description @schema_definition = nil @headers = {} @examples = {} @links = {} @content_types = nil end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
6 7 8 |
# File 'lib/openapi_ruby/dsl/response_context.rb', line 6 def description @description end |
#examples ⇒ Object (readonly)
Returns the value of attribute examples.
6 7 8 |
# File 'lib/openapi_ruby/dsl/response_context.rb', line 6 def examples @examples end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
6 7 8 |
# File 'lib/openapi_ruby/dsl/response_context.rb', line 6 def headers @headers end |
#links ⇒ Object (readonly)
Returns the value of attribute links.
6 7 8 |
# File 'lib/openapi_ruby/dsl/response_context.rb', line 6 def links @links end |
#schema_definition ⇒ Object (readonly)
Returns the value of attribute schema_definition.
6 7 8 |
# File 'lib/openapi_ruby/dsl/response_context.rb', line 6 def schema_definition @schema_definition end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
6 7 8 |
# File 'lib/openapi_ruby/dsl/response_context.rb', line 6 def status_code @status_code end |
Instance Method Details
#example(content_type, value:, name: "example", summary: nil, description: nil) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/openapi_ruby/dsl/response_context.rb', line 26 def example(content_type, value:, name: "example", summary: nil, description: nil) @examples[content_type] ||= {} entry = {"value" => value} entry["summary"] = summary if summary entry["description"] = description if description @examples[content_type][name.to_s] = entry end |
#header(name, attributes = {}) ⇒ Object
22 23 24 |
# File 'lib/openapi_ruby/dsl/response_context.rb', line 22 def header(name, attributes = {}) @headers[name.to_s] = normalize(attributes) end |
#produces(*content_types) ⇒ Object
34 35 36 |
# File 'lib/openapi_ruby/dsl/response_context.rb', line 34 def produces(*content_types) @content_types = content_types.flatten end |
#schema(definition) ⇒ Object
18 19 20 |
# File 'lib/openapi_ruby/dsl/response_context.rb', line 18 def schema(definition) @schema_definition = normalize(definition) end |
#to_openapi ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/openapi_ruby/dsl/response_context.rb', line 38 def to_openapi result = {"description" => @description} if @schema_definition types = @content_types || ["application/json"] result["content"] = {} types.each do |ct| media = {"schema" => @schema_definition} media["examples"] = @examples[ct] if @examples.key?(ct) result["content"][ct] = media end end result["headers"] = build_headers if @headers.any? result["links"] = @links unless @links.empty? result end |