Class: TypeSpecFromSerializers::Operation
- Inherits:
-
Struct
- Object
- Struct
- TypeSpecFromSerializers::Operation
- Defined in:
- lib/typespec_from_serializers/generator.rb
Overview
Internal: Represents a TypeSpec operation within a resource
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#method ⇒ Object
Returns the value of attribute method.
-
#path_params ⇒ Object
Returns the value of attribute path_params.
-
#response_type ⇒ Object
Returns the value of attribute response_type.
Instance Method Summary collapse
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action
234 235 236 |
# File 'lib/typespec_from_serializers/generator.rb', line 234 def action @action end |
#method ⇒ Object
Returns the value of attribute method
234 235 236 |
# File 'lib/typespec_from_serializers/generator.rb', line 234 def method @method end |
#path_params ⇒ Object
Returns the value of attribute path_params
234 235 236 |
# File 'lib/typespec_from_serializers/generator.rb', line 234 def path_params @path_params end |
#response_type ⇒ Object
Returns the value of attribute response_type
234 235 236 |
# File 'lib/typespec_from_serializers/generator.rb', line 234 def response_type @response_type end |
Instance Method Details
#as_typespec ⇒ Object
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/typespec_from_serializers/generator.rb', line 235 def as_typespec method_map = { "GET" => "get", "POST" => "post", "PUT" => "put", "PATCH" => "patch", "DELETE" => "delete", } tsp_method = method_map[method] || method.downcase operation_name = TypeSpecFromSerializers.config.action_to_operation_mapping[action] || action params = params_typespec params_str = params.empty? ? "()" : "(#{params})" "#{" " * 1}@#{tsp_method} #{operation_name}#{params_str}: #{response_type.gsub("::", "")};" end |
#params_typespec ⇒ Object
251 252 253 254 255 256 |
# File 'lib/typespec_from_serializers/generator.rb', line 251 def params_typespec params = [] params += path_params.map { |param| "@path #{param}: string" } if path_params.any? params << "@body body: #{response_type.gsub("::", "")}" if %w[POST PUT PATCH].include?(method) params.join(", ") end |