Class: SpecForge::Documentation::OpenAPI::V30::Schema
- Inherits:
-
Object
- Object
- SpecForge::Documentation::OpenAPI::V30::Schema
- Defined in:
- lib/spec_forge/documentation/openapi/v3_0/schema.rb
Overview
Represents an OpenAPI 3.0 Schema object
Handles schema definitions for data types, converting internal type representations to OpenAPI-compliant schema objects.
Instance Attribute Summary collapse
-
#content ⇒ Object?
readonly
The schema content (for arrays/objects).
-
#format ⇒ String?
readonly
The schema format (date-time, int64, etc.).
-
#type ⇒ String?
readonly
The schema type (string, integer, object, etc.).
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Schema
constructor
Creates a new OpenAPI schema object.
-
#to_h ⇒ Hash
Converts the schema to an OpenAPI-compliant hash.
Constructor Details
#initialize(options = {}) ⇒ Schema
Creates a new OpenAPI schema object
46 47 48 49 |
# File 'lib/spec_forge/documentation/openapi/v3_0/schema.rb', line 46 def initialize( = {}) @type, @format = transform_type([:type]) @content = [:content] end |
Instance Attribute Details
#content ⇒ Object? (readonly)
The schema content (for arrays/objects)
35 36 37 |
# File 'lib/spec_forge/documentation/openapi/v3_0/schema.rb', line 35 def content @content end |
#format ⇒ String? (readonly)
The schema format (date-time, int64, etc.)
28 29 30 |
# File 'lib/spec_forge/documentation/openapi/v3_0/schema.rb', line 28 def format @format end |
#type ⇒ String? (readonly)
The schema type (string, integer, object, etc.)
21 22 23 |
# File 'lib/spec_forge/documentation/openapi/v3_0/schema.rb', line 21 def type @type end |
Instance Method Details
#to_h ⇒ Hash
Converts the schema to an OpenAPI-compliant hash
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/spec_forge/documentation/openapi/v3_0/schema.rb', line 56 def to_h base = { type:, format: }.compact_blank! # Add items for arrays if type == "array" && content.present? # Content is an array like [{type: "string"}], take first element as items schema items_type = content.first&.dig(:type) || "object" base[:items] = {type: items_type} end base end |