Expand description
UCP Schema Resolver
Runtime resolution of ucp_request and ucp_response annotations.
This library transforms JSON Schemas with UCP annotations into standard JSON Schemas based on direction (request/response) and operation (create, read, update, etc.).
§Example
use ucp_schema::{resolve, Direction, ResolveOptions};
use serde_json::json;
let schema = json!({
"type": "object",
"properties": {
"id": {
"type": "string",
"ucp_request": {
"create": "omit",
"update": "required"
}
},
"name": { "type": "string" }
}
});
let options = ResolveOptions::new(Direction::Request, "create");
let resolved = resolve(&schema, &options).unwrap();
// In the resolved schema, "id" is omitted for create requests
assert!(resolved["properties"].get("id").is_none());
assert!(resolved["properties"].get("name").is_some());§Visibility Rules
| Visibility | Effect on properties | Effect on required |
|---|---|---|
"omit" | Remove field | Remove from required |
"required" | Keep field | Add to required |
"optional" | Keep field | Remove from required |
| (none) | Keep field | Preserve original |
§Annotation Format
Annotations can be shorthand (applies to all operations):
{ "ucp_request": "omit" }Or per-operation:
{ "ucp_request": { "create": "omit", "update": "required" } }Structs§
- Capability
- Capability declaration extracted from UCP metadata.
- Diagnostic
- A single diagnostic message from linting.
- File
Result - Result of linting a single file.
- Lint
Result - Result of linting a directory or set of files.
- Requires
- Extension schema version requirements (
requiresfield). - Resolve
Options - Options for schema resolution.
- Schema
Base Config - Configuration for mapping schema URLs to local paths.
- Schema
Error - Single validation error with path context.
- Version
Constraint - Version range: minimum (required) and optional maximum, both inclusive.
- Version
Violation - A version constraint violation found during composition.
Enums§
- Compose
Error - Errors during schema composition from UCP capability metadata.
- Detected
Direction - Detected payload direction based on UCP metadata structure.
- Direction
- Direction of the schema transformation.
- File
Status - Status of a linted file.
- Resolve
Error - Errors during schema resolution.
- Severity
- Severity level for diagnostics.
- Validate
Error - Errors during validation.
- Visibility
- Visibility of a field after resolution.
Functions§
- bundle_
refs - Recursively resolve and inline external $ref pointers.
- bundle_
refs_ remote - Bundle external $ref pointers by fetching from remote URLs.
- bundle_
refs_ with_ url_ mapping - Bundle external $ref pointers with URL-to-local-path mapping.
- capability_
short_ name - Derive short name from a capability name.
- check_
version_ constraints - Check an extension schema’s
requiresconstraints against the available versions. - compose_
from_ payload - Convenience: extract capabilities and compose schema in one call.
- compose_
schema - Compose schema from capability declarations.
- detect_
direction - Detect direction from payload structure.
- extract_
capabilities - Extract capabilities from a self-describing payload.
- extract_
capabilities_ from_ profile - Extract capabilities from a profile URL.
- extract_
jsonrpc_ payload - Extract the actual payload from a JSONRPC request envelope.
- is_
container_ schema - Returns true if a capability schema is “container-shaped”.
- is_url
- Check if a string looks like a URL (starts with http:// or https://).
- lint
- Lint a file or directory.
- lint_
file - Lint a single schema file.
- load_
schema - Load a schema from a file path.
- load_
schema_ auto - Load a schema from a file path or URL.
- load_
schema_ str - Load a schema from a JSON string.
- load_
schema_ url - Load a schema from an HTTP/HTTPS URL.
- navigate_
fragment - Navigate a JSON Pointer fragment (e.g., “#/$defs/foo” or “#/properties/bar”).
- resolve
- Resolve a schema for a specific direction and operation.
- select_
operation_ schema - Resolve a (possibly container-shaped) schema to its validation target.
- strip_
annotations - Strip all UCP annotations from a schema.
- validate
- Validate a payload against a UCP schema.
- validate_
against_ schema - Validate a payload against an already-resolved schema.