Class: SpecForge::Documentation::OpenAPI::V30::Response

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(document) ⇒ Response

Creates a new Response from a document

Parameters:

  • document (Object)

    The document containing response data



28
29
30
# File 'lib/spec_forge/documentation/openapi/v3_0/response.rb', line 28

def initialize(document)
  @document = document
end

Instance Attribute Details

#documentObject (readonly)

The document object containing structured API data

Returns:

  • (Object)

    The document with endpoint information



21
22
23
# File 'lib/spec_forge/documentation/openapi/v3_0/response.rb', line 21

def document
  @document
end

Instance Method Details

#contentHash?

Returns content definitions for the response

Creates media type objects with schemas and merges with any documentation-provided content definitions.

Returns:

  • (Hash, nil)

    Content definitions by media type



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

#headersHash?

Returns header definitions for the response

Transforms document headers into OpenAPI format with schema wrappers.

Returns:

  • (Hash, nil)

    Header definitions



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_hHash

Converts the response to an OpenAPI-compliant hash

Builds the complete response object with required description and optional content, headers, and links.

Returns:

  • (Hash)

    OpenAPI-formatted response object



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