Class: SpecForge::Documentation::OpenAPI::V30::Response
- Inherits:
-
Object
- Object
- SpecForge::Documentation::OpenAPI::V30::Response
- Defined in:
- lib/spec_forge/documentation/openapi/v3_0/response.rb
Overview
Represents an OpenAPI 3.0 Response object
Handles response definitions including status descriptions, content types, headers, and links for OpenAPI specifications.
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
The document object containing structured API data.
Instance Method Summary collapse
-
#content ⇒ Hash?
Returns content definitions for the response.
-
#headers ⇒ Hash?
Returns header definitions for the response.
-
#initialize(document) ⇒ Response
constructor
Creates a new Response from a document.
-
#to_h ⇒ Hash
Converts the response to an OpenAPI-compliant hash.
Constructor Details
#initialize(document) ⇒ Response
Creates a new Response from a document
28 29 30 |
# File 'lib/spec_forge/documentation/openapi/v3_0/response.rb', line 28 def initialize(document) @document = document end |
Instance Attribute Details
#document ⇒ Object (readonly)
The document object containing structured API data
21 22 23 |
# File 'lib/spec_forge/documentation/openapi/v3_0/response.rb', line 21 def document @document end |
Instance Method Details
#content ⇒ Hash?
Returns content definitions for the response
Creates media type objects with schemas and merges with any documentation-provided content definitions.
59 60 61 62 63 64 65 66 67 |
# File 'lib/spec_forge/documentation/openapi/v3_0/response.rb', line 59 def content return nil if document.content_type.blank? schema = Schema.new(type: document.body.type, content: document.body.content).to_h { document.content_type => MediaType.new(schema:).to_h } end |
#headers ⇒ Hash?
Returns header definitions for the response
Transforms document headers into OpenAPI format with schema wrappers.
76 77 78 79 80 81 82 |
# File 'lib/spec_forge/documentation/openapi/v3_0/response.rb', line 76 def headers return nil if document.headers.blank? document.headers.transform_values do |header| {schema: header} end end |
#to_h ⇒ Hash
Converts the response to an OpenAPI-compliant hash
Builds the complete response object with required description and optional content, headers, and links.
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/spec_forge/documentation/openapi/v3_0/response.rb', line 40 def to_h { # Required description: "", content: }.compact_merge( # Optional headers: ) end |