Decorators¶
All action and route decorators are importable from xcore.sdk.
@action¶
Registers an async method as a dispatchable action.
Parameters
| Name | Type | Description |
|---|---|---|
name |
str |
Action identifier used in handle(name, payload) |
The decorated method must be async, accept self and payload: dict, and return a dict.
@route¶
Registers an async method as a FastAPI route, exposed under the plugin's URL prefix.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
path |
str |
— | URL path, supports FastAPI path parameters |
method |
str |
"GET" |
HTTP method |
tags |
list[str] |
[] |
OpenAPI tags |
summary |
str |
"" |
OpenAPI summary |
status_code |
int |
200 |
Default response status code |
permissions |
list[str] |
[] |
Required permission strings |
Path parameters become method arguments by name. Request bodies are body: dict.
@schema¶
Declares a versioned schema for an action — stores it on fn._xcore_schema for the SchemaRegistry — and optionally applies @validate_payload automatically.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
version |
str |
— | Schema version string (semver recommended) |
input |
dict \| None |
None |
Input field definitions (see field syntax below) |
output |
dict \| None |
None |
Output field definitions (documentation only) |
deprecated_fields |
dict[str, str] \| None |
None |
Map of deprecated field name → migration message |
breaking_since |
str \| None |
None |
Version at which a breaking change was introduced |
description |
str |
"" |
Human-readable description stored in the schema |
validate |
bool |
True |
Whether to apply @validate_payload automatically |
type_response |
"dict", "model", "_" |
"_" |
Controls what the handler receives (see below) |
unset |
bool |
False |
If True, excludes unset fields from model_dump() |
Input field syntax¶
Follows Pydantic create_model conventions:
type_response values¶
| Value | Validation applied? | Handler receives |
|---|---|---|
"_" |
No | original payload: dict unchanged |
"dict" |
Yes | validated.model_dump(exclude_unset=unset) |
"model" |
Yes | Pydantic model instance |
When type_response="dict" or "model", @schema internally applies @validate_payload — you do not need both decorators.
When type_response="_" (default), validation is skipped; @schema only stores the schema metadata. Use this to annotate schema without enforcing it.
Schema metadata¶
The schema is stored on the function as fn._xcore_schema:
Deprecation tracking¶
Replacing @validate_payload¶
@schema with type_response="dict" is a strict superset of @validate_payload:
Use @schema when you need versioning or deprecation tracking; use @validate_payload when you just need runtime validation.
@validate_payload¶
Validates payload against a Pydantic v2 model before calling the handler. On failure, returns an error response automatically.
Parameters
| Name | Type | Description |
|---|---|---|
schema |
type[BaseModel] |
Pydantic model class |
On validation failure, returns error("Validation error: ...", "validation_error").
Decorator position
@validate_payload should appear above @require_service in source code so validation runs before service checks.
@require_service¶
Guards a handler behind a service availability check. Raises KeyError (or returns an error response) if the named service is not registered in self.ctx.services.
Parameters
| Name | Type | Description |
|---|---|---|
service_name |
str |
Key in self.ctx.services |
@trusted¶
Restricts the action to plugins running in trusted execution mode. Returns a permission-denied response for sandboxed callers.
No parameters.
@sandboxed¶
Marks an action as safe to call from sandboxed plugins. Does not restrict trusted callers.
No parameters.
Stacking order reference¶
Decorators execute bottom-up at call time. The order above ensures: cache check → tracing → service check → validation → mode enforcement → action dispatch.
Tip
Use either @schema(type_response="dict") or @validate_payload — not both. @schema wraps @validate_payload internally when type_response != "_".