Skip to main content

Crate ucp_schema

Crate ucp_schema 

Source
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

VisibilityEffect on propertiesEffect on required
"omit"Remove fieldRemove from required
"required"Keep fieldAdd to required
"optional"Keep fieldRemove from required
(none)Keep fieldPreserve 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.
FileResult
Result of linting a single file.
LintResult
Result of linting a directory or set of files.
Requires
Extension schema version requirements (requires field).
ResolveOptions
Options for schema resolution.
SchemaBaseConfig
Configuration for mapping schema URLs to local paths.
SchemaError
Single validation error with path context.
VersionConstraint
Version range: minimum (required) and optional maximum, both inclusive.
VersionViolation
A version constraint violation found during composition.

Enums§

ComposeError
Errors during schema composition from UCP capability metadata.
DetectedDirection
Detected payload direction based on UCP metadata structure.
Direction
Direction of the schema transformation.
FileStatus
Status of a linted file.
ResolveError
Errors during schema resolution.
Severity
Severity level for diagnostics.
ValidateError
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 requires constraints 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.