class WarpEngine::AdminApi::Operation
One Admin API operation: an HTTP route, an MCP tool and an OpenAPI operation at once. Declared through Resource; run by Runner.
Constants
- PREFIX
-
The URL prefix of every operation route.
Attributes
The declaration: owning Resource, name, HTTP verb, path (with :param segments), summary, description, query and body schemas, required body fields, path param schemas, response shape ({ kind:, item: }), handler, success status, sort key to column map and default sort key.
The declaration: owning Resource, name, HTTP verb, path (with :param segments), summary, description, query and body schemas, required body fields, path param schemas, response shape ({ kind:, item: }), handler, success status, sort key to column map and default sort key.
The declaration: owning Resource, name, HTTP verb, path (with :param segments), summary, description, query and body schemas, required body fields, path param schemas, response shape ({ kind:, item: }), handler, success status, sort key to column map and default sort key.
The declaration: owning Resource, name, HTTP verb, path (with :param segments), summary, description, query and body schemas, required body fields, path param schemas, response shape ({ kind:, item: }), handler, success status, sort key to column map and default sort key.
The declaration: owning Resource, name, HTTP verb, path (with :param segments), summary, description, query and body schemas, required body fields, path param schemas, response shape ({ kind:, item: }), handler, success status, sort key to column map and default sort key.
The declaration: owning Resource, name, HTTP verb, path (with :param segments), summary, description, query and body schemas, required body fields, path param schemas, response shape ({ kind:, item: }), handler, success status, sort key to column map and default sort key.
The declaration: owning Resource, name, HTTP verb, path (with :param segments), summary, description, query and body schemas, required body fields, path param schemas, response shape ({ kind:, item: }), handler, success status, sort key to column map and default sort key.
The declaration: owning Resource, name, HTTP verb, path (with :param segments), summary, description, query and body schemas, required body fields, path param schemas, response shape ({ kind:, item: }), handler, success status, sort key to column map and default sort key.
The declaration: owning Resource, name, HTTP verb, path (with :param segments), summary, description, query and body schemas, required body fields, path param schemas, response shape ({ kind:, item: }), handler, success status, sort key to column map and default sort key.
The declaration: owning Resource, name, HTTP verb, path (with :param segments), summary, description, query and body schemas, required body fields, path param schemas, response shape ({ kind:, item: }), handler, success status, sort key to column map and default sort key.
The declaration: owning Resource, name, HTTP verb, path (with :param segments), summary, description, query and body schemas, required body fields, path param schemas, response shape ({ kind:, item: }), handler, success status, sort key to column map and default sort key.
The declaration: owning Resource, name, HTTP verb, path (with :param segments), summary, description, query and body schemas, required body fields, path param schemas, response shape ({ kind:, item: }), handler, success status, sort key to column map and default sort key.
The declaration: owning Resource, name, HTTP verb, path (with :param segments), summary, description, query and body schemas, required body fields, path param schemas, response shape ({ kind:, item: }), handler, success status, sort key to column map and default sort key.
The declaration: owning Resource, name, HTTP verb, path (with :param segments), summary, description, query and body schemas, required body fields, path param schemas, response shape ({ kind:, item: }), handler, success status, sort key to column map and default sort key.
Public Class Methods
# File lib/warp_engine/admin_api/operation.rb, line 24 def initialize(resource:, name:, verb:, path:, summary:, handler:, description: nil, query: {}, body: nil, body_required: [], path_params: {}, response: { kind: :none }, status: 200, multipart: false, mcp: true, destructive: false, idempotent: false, scope: nil, tool_name: nil, sort: {}, default_sort: nil) @resource = resource @name = name.to_sym @verb = verb.to_sym @path = path @summary = summary @description = description @handler = handler @query = query @body = body @body_required = body_required.map(&:to_s) @path_params = path_params @response = response @status = status @multipart = multipart @mcp = mcp @destructive = destructive @idempotent = idempotent @scope = scope @tool_name = tool_name @sort_columns = sort.transform_keys(&:to_s) @default_sort = default_sort end
Takes the declaration as keywords; besides the readers’ values:
- multipart
-
the body is multipart form data (not offered over MCP)
- mcp
-
offer it as an MCP tool
- destructive
-
mark it destructive for MCP (deletes always are)
- idempotent
-
mark it idempotent for MCP (GET, PUT, PATCH, DELETE always are)
- scope
-
the scope it needs, overriding the resource’s
tool_name-
the MCP tool name, overriding the default
Public Instance Methods
Source
# File lib/warp_engine/admin_api/operation.rb, line 60 def destructive? = @destructive || verb == :delete
Whether it destroys data.
Source
# File lib/warp_engine/admin_api/operation.rb, line 62 def idempotent? = @idempotent || %i[get put patch delete].include?(verb)
Whether repeating it changes nothing further.
Source
# File lib/warp_engine/admin_api/operation.rb, line 102 def input_schema Schema.object(inputs.transform_keys(&:to_sym), required: required_inputs) end
The JSON schema object of all inputs, the MCP tool input schema.
Source
# File lib/warp_engine/admin_api/operation.rb, line 89 def inputs props = path_param_names.to_h { |param| [ param, path_param_schema(param) ] } props.merge!(query.transform_keys(&:to_s)) props.merge!(body[:properties].transform_keys(&:to_s)) if body props end
Every input schema by name: path params, query params and body properties.
Source
# File lib/warp_engine/admin_api/operation.rb, line 52 def key = "#{resource.name}.#{name}"
The unique key: resource.name, a dot, then name.
Source
# File lib/warp_engine/admin_api/operation.rb, line 58 def mcp? = @mcp && !multipart?
Whether it is offered as an MCP tool.
Source
# File lib/warp_engine/admin_api/operation.rb, line 56 def multipart? = @multipart
Whether the body is multipart form data.
Source
# File lib/warp_engine/admin_api/operation.rb, line 73 def openapi_path = path.gsub(/:(\w+)/) { "{#{Regexp.last_match(1)}}" }
The path with {param} segments, as OpenAPI writes it.
Source
# File lib/warp_engine/admin_api/operation.rb, line 75 def path_param_names = path.scan(/:(\w+)/).flatten
The names of the path params.
Source
# File lib/warp_engine/admin_api/operation.rb, line 83 def path_param_schema(param) schema = path_params[param.to_sym] || Schema.id schema.respond_to?(:call) ? schema.call : schema end
The schema of path param param, an id by default.
Source
# File lib/warp_engine/admin_api/operation.rb, line 54 def read? = verb == :get
Whether it is a GET.
Source
# File lib/warp_engine/admin_api/operation.rb, line 97 def required_inputs path_param_names + body_required end
The names of the required inputs: the path params and the required body fields.
Source
# File lib/warp_engine/admin_api/operation.rb, line 66 def required_scope @scope || resource.scope || (read? ? Scopes::READ : Scopes::WRITE) end
The scope the caller needs: its own, the resource’s, or Scopes::READ for reads and Scopes::WRITE for writes. :any means any admin caller.
Source
# File lib/warp_engine/admin_api/operation.rb, line 71 def route_path = "#{PREFIX}#{path}"
The full route path, with PREFIX.
Source
# File lib/warp_engine/admin_api/operation.rb, line 78 def tool_name @tool_name || "#{resource.singular}_#{name}" end
The MCP tool name and OpenAPI operationId: its own, or singular_name.