Class: GrapeOAS::ApiModel::Node Abstract
- Inherits:
-
Object
- Object
- GrapeOAS::ApiModel::Node
- Defined in:
- lib/grape_oas/api_model/node.rb
Overview
This class is abstract.
Base class for all DTO (intermediate) nodes used in OpenAPI v2/v3 conversion. Provides a unique ID and helper methods for referencing and bucketing. All DTO classes for OpenAPIv2 and OpenAPIv3 inherit from Node.
Constant Summary collapse
- BUCKET_NAMES =
OpenAPI component bucket names per spec (some are irregular plurals)
{ "Schema" => "schemas", "Parameter" => "parameters", "RequestBody" => "requestBodies", "Response" => "responses", "Header" => "headers", "SecurityScheme" => "securitySchemes", "Link" => "links", "Callback" => "callbacks", "Example" => "examples", "PathItem" => "pathItems" }.freeze
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
-
.bucket ⇒ Object
Returns the pluralized bucket name for this class (e.g., “schemas”, “parameters”).
Instance Method Summary collapse
-
#initialize(node_id: nil) ⇒ Node
constructor
A new instance of Node.
- #ref ⇒ Object
Constructor Details
#initialize(node_id: nil) ⇒ Node
Returns a new instance of Node.
42 43 44 |
# File 'lib/grape_oas/api_model/node.rb', line 42 def initialize(node_id: nil) @id = node_id || generate_id end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
40 41 42 |
# File 'lib/grape_oas/api_model/node.rb', line 40 def id @id end |
Class Method Details
.bucket ⇒ Object
Returns the pluralized bucket name for this class (e.g., “schemas”, “parameters”). Uses OpenAPI spec-compliant names for irregular plurals (e.g., “requestBodies”). Memoized at the class level to avoid repeated string manipulation.
32 33 34 35 36 37 |
# File 'lib/grape_oas/api_model/node.rb', line 32 def bucket @bucket ||= begin class_name = name.split("::").last BUCKET_NAMES.fetch(class_name, "#{class_name.downcase}s") end end |
Instance Method Details
#ref ⇒ Object
46 47 48 |
# File 'lib/grape_oas/api_model/node.rb', line 46 def ref "#/components/#{self.class.bucket}/#{id}" end |