Class: TypeSpecFromSerializers::Resource

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

Overview

Internal: Represents a TypeSpec resource interface

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



445
446
447
# File 'lib/typespec_from_serializers/generator.rb', line 445

def name
  @name
end

#operationsObject

Returns the value of attribute operations

Returns:

  • (Object)

    the current value of operations



445
446
447
# File 'lib/typespec_from_serializers/generator.rb', line 445

def operations
  @operations
end

#parent_namespaceObject

Returns the value of attribute parent_namespace

Returns:

  • (Object)

    the current value of parent_namespace



445
446
447
# File 'lib/typespec_from_serializers/generator.rb', line 445

def parent_namespace
  @parent_namespace
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



445
446
447
# File 'lib/typespec_from_serializers/generator.rb', line 445

def path
  @path
end

Instance Method Details

#as_typespecObject



446
447
448
449
450
451
452
453
454
455
456
457
458
# File 'lib/typespec_from_serializers/generator.rb', line 446

def as_typespec
  operations_str = operations.map { |op| "  #{op.as_typespec(resource_path: path)}" }.join("\n")

  interface_block = <<~TSP.strip
    @route("#{path}")
    interface #{name} {
    #{operations_str}
    }
  TSP

  # Wrap in namespace if this is a nested resource
  parent_namespace ? wrap_in_namespace(interface_block) : interface_block
end