Class: RailsOpenapiGen::AstNodes::PropertyNode

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

SimplePropertyNode

Instance Attribute Summary collapse

Attributes inherited from BaseNode

#children, #metadata, #parent

Instance Method Summary collapse

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_dataObject (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_nameObject (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_refObject (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_conditionalObject (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_nameObject (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

Parameters:

  • visitor (Object)

    Visitor object

Returns:

  • (Object)

    Result from visitor



69
70
71
# File 'lib/rails-openapi-gen/ast_nodes/property_node.rb', line 69

def accept(visitor)
  visitor.visit_property(self)
end

#descriptionString?

Get the description for this property

Returns:

  • (String, nil)

    Property description



38
39
40
# File 'lib/rails-openapi-gen/ast_nodes/property_node.rb', line 38

def description
  @comment_data.description
end

#enum_valuesArray?

Get enum values if specified

Returns:

  • (Array, nil)

    Enum values



44
45
46
# File 'lib/rails-openapi-gen/ast_nodes/property_node.rb', line 44

def enum_values
  @comment_data.enum
end

#openapi_typeString

Get the OpenAPI type for this property

Returns:

  • (String)

    OpenAPI type



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

Returns:

  • (Boolean)

    True if property is optional



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

Returns:

  • (Boolean)

    True if property is required



20
21
22
# File 'lib/rails-openapi-gen/ast_nodes/property_node.rb', line 20

def required?
  @comment_data.required? && !@is_conditional
end

#to_hHash

Convert to hash representation

Returns:

  • (Hash)

    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