Class: TypeSpecFromSerializers::Operation

Inherits:
Struct
  • Object
show all
Defined in:
lib/typespec_from_serializers/generator.rb

Overview

Internal: Represents a TypeSpec operation within a resource

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#actionObject

Returns the value of attribute action

Returns:

  • (Object)

    the current value of action



473
474
475
# File 'lib/typespec_from_serializers/generator.rb', line 473

def action
  @action
end

#body_paramsObject

Returns the value of attribute body_params

Returns:

  • (Object)

    the current value of body_params



473
474
475
# File 'lib/typespec_from_serializers/generator.rb', line 473

def body_params
  @body_params
end

#docObject

Returns the value of attribute doc

Returns:

  • (Object)

    the current value of doc



473
474
475
# File 'lib/typespec_from_serializers/generator.rb', line 473

def doc
  @doc
end

#methodObject

Returns the value of attribute method

Returns:

  • (Object)

    the current value of method



473
474
475
# File 'lib/typespec_from_serializers/generator.rb', line 473

def method
  @method
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



473
474
475
# File 'lib/typespec_from_serializers/generator.rb', line 473

def path
  @path
end

#path_paramsObject

Returns the value of attribute path_params

Returns:

  • (Object)

    the current value of path_params



473
474
475
# File 'lib/typespec_from_serializers/generator.rb', line 473

def path_params
  @path_params
end

#response_typeObject

Returns the value of attribute response_type

Returns:

  • (Object)

    the current value of response_type



473
474
475
# File 'lib/typespec_from_serializers/generator.rb', line 473

def response_type
  @response_type
end

Instance Method Details

#as_typespec(resource_path: nil) ⇒ Object



474
475
476
477
478
479
480
481
482
483
484
485
486
# File 'lib/typespec_from_serializers/generator.rb', line 474

def as_typespec(resource_path: nil)
  tsp_method = method.downcase
  operation_name = TypeSpecFromSerializers.config.action_to_operation_mapping[action] || action
  route_line = build_route_decorator(resource_path)
  doc_line = doc ? "@doc(\"#{escape_doc(doc)}\")\n  " : ""

  # Check if we need multiline formatting
  single_line = build_single_line(tsp_method, operation_name)

  too_long_for_single_line?(single_line) ?
    "#{doc_line}#{multiline_format(route_line, tsp_method, operation_name)}" :
    "#{doc_line}#{route_line}#{single_line}"
end