Class: RailsOpenapiGen::AstNodes::PropertyNode
- Defined in:
- lib/rails-openapi-gen/ast_nodes/property_node.rb
Overview
Represents a property node in Jbuilder template (json.property_name)
Direct Known Subclasses
Instance Attribute Summary collapse
-
#comment_data ⇒ Object
readonly
json.xxx # @openapi comments # if/else # whether this is a component reference # name of referenced component.
-
#component_name ⇒ Object
readonly
json.xxx # @openapi comments # if/else # whether this is a component reference # name of referenced component.
-
#is_component_ref ⇒ Object
readonly
json.xxx # @openapi comments # if/else # whether this is a component reference # name of referenced component.
-
#is_conditional ⇒ Object
readonly
json.xxx # @openapi comments # if/else # whether this is a component reference # name of referenced component.
-
#property_name ⇒ Object
readonly
json.xxx # @openapi comments # if/else # whether this is a component reference # name of referenced component.
Attributes inherited from BaseNode
Instance Method Summary collapse
-
#accept(visitor) ⇒ Object
Accept visitor for visitor pattern.
-
#description ⇒ String?
Get the description for this property.
-
#enum_values ⇒ Array?
Get enum values if specified.
-
#initialize(property_name:, comment_data: nil, is_conditional: false, is_component_ref: false, component_name: nil, parent: nil, metadata: {}) ⇒ PropertyNode
constructor
A new instance of PropertyNode.
-
#openapi_type ⇒ String
Get the OpenAPI type for this property.
-
#optional? ⇒ Boolean
Check if this property is optional in OpenAPI schema.
-
#required? ⇒ Boolean
Check if this property is required in OpenAPI schema.
-
#to_h ⇒ Hash
Convert to hash representation.
Methods inherited from BaseNode
#add_child, #debug_line, #descendants, #leaf?, #pretty_print, #remove_child, #root, #root?, #summary_attributes
Constructor Details
#initialize(property_name:, comment_data: nil, is_conditional: false, is_component_ref: false, component_name: nil, parent: nil, metadata: {}) ⇒ PropertyNode
Returns a new instance of PropertyNode.
9 10 11 12 13 14 15 16 |
# File 'lib/rails-openapi-gen/ast_nodes/property_node.rb', line 9 def initialize(property_name:, comment_data: nil, is_conditional: false, is_component_ref: false, component_name: nil, parent: nil, metadata: {}) super(parent: parent, metadata: ) @property_name = property_name @comment_data = comment_data || CommentData.new @is_conditional = is_conditional @is_component_ref = is_component_ref @component_name = component_name end |
Instance Attribute Details
#comment_data ⇒ Object (readonly)
json.xxx # @openapi comments # if/else # whether this is a component reference # name of referenced component
7 8 9 |
# File 'lib/rails-openapi-gen/ast_nodes/property_node.rb', line 7 def comment_data @comment_data end |
#component_name ⇒ Object (readonly)
json.xxx # @openapi comments # if/else # whether this is a component reference # name of referenced component
7 8 9 |
# File 'lib/rails-openapi-gen/ast_nodes/property_node.rb', line 7 def component_name @component_name end |
#is_component_ref ⇒ Object (readonly)
json.xxx # @openapi comments # if/else # whether this is a component reference # name of referenced component
7 8 9 |
# File 'lib/rails-openapi-gen/ast_nodes/property_node.rb', line 7 def is_component_ref @is_component_ref end |
#is_conditional ⇒ Object (readonly)
json.xxx # @openapi comments # if/else # whether this is a component reference # name of referenced component
7 8 9 |
# File 'lib/rails-openapi-gen/ast_nodes/property_node.rb', line 7 def is_conditional @is_conditional end |
#property_name ⇒ Object (readonly)
json.xxx # @openapi comments # if/else # whether this is a component reference # name of referenced component
7 8 9 |
# File 'lib/rails-openapi-gen/ast_nodes/property_node.rb', line 7 def property_name @property_name end |
Instance Method Details
#accept(visitor) ⇒ Object
Accept visitor for visitor pattern
69 70 71 |
# File 'lib/rails-openapi-gen/ast_nodes/property_node.rb', line 69 def accept(visitor) visitor.visit_property(self) end |
#description ⇒ String?
Get the description for this property
38 39 40 |
# File 'lib/rails-openapi-gen/ast_nodes/property_node.rb', line 38 def description @comment_data.description end |
#enum_values ⇒ Array?
Get enum values if specified
44 45 46 |
# File 'lib/rails-openapi-gen/ast_nodes/property_node.rb', line 44 def enum_values @comment_data.enum end |
#openapi_type ⇒ String
Get the OpenAPI type for this property
32 33 34 |
# File 'lib/rails-openapi-gen/ast_nodes/property_node.rb', line 32 def openapi_type @comment_data.type || 'string' end |
#optional? ⇒ Boolean
Check if this property is optional in OpenAPI schema
26 27 28 |
# File 'lib/rails-openapi-gen/ast_nodes/property_node.rb', line 26 def optional? !required? end |
#required? ⇒ Boolean
Check if this property is required in OpenAPI schema
20 21 22 |
# File 'lib/rails-openapi-gen/ast_nodes/property_node.rb', line 20 def required? @comment_data.required? && !@is_conditional end |
#to_h ⇒ Hash
Convert to hash representation
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rails-openapi-gen/ast_nodes/property_node.rb', line 50 def to_h super.merge( property_name: @property_name, comment_data: @comment_data&.to_h, is_conditional: @is_conditional, is_component_ref: @is_component_ref, component_name: @component_name, required: required?, openapi_type: openapi_type, description: description, enum: enum_values, # Backward compatibility - also provide property for Generator property: @property_name ).compact end |