ucp_schema/lib.rs
1//! UCP Schema Resolver
2//!
3//! Runtime resolution of `ucp_request` and `ucp_response` annotations.
4//!
5//! This library transforms JSON Schemas with UCP annotations into standard JSON Schemas
6//! based on direction (request/response) and operation (create, read, update, etc.).
7//!
8//! # Example
9//!
10//! ```
11//! use ucp_schema::{resolve, Direction, ResolveOptions};
12//! use serde_json::json;
13//!
14//! let schema = json!({
15//! "type": "object",
16//! "properties": {
17//! "id": {
18//! "type": "string",
19//! "ucp_request": {
20//! "create": "omit",
21//! "update": "required"
22//! }
23//! },
24//! "name": { "type": "string" }
25//! }
26//! });
27//!
28//! let options = ResolveOptions::new(Direction::Request, "create");
29//! let resolved = resolve(&schema, &options).unwrap();
30//!
31//! // In the resolved schema, "id" is omitted for create requests
32//! assert!(resolved["properties"].get("id").is_none());
33//! assert!(resolved["properties"].get("name").is_some());
34//! ```
35//!
36//! # Visibility Rules
37//!
38//! | Visibility | Effect on `properties` | Effect on `required` |
39//! |------------|------------------------|----------------------|
40//! | `"omit"` | Remove field | Remove from required |
41//! | `"required"` | Keep field | Add to required |
42//! | `"optional"` | Keep field | Remove from required |
43//! | (none) | Keep field | Preserve original |
44//!
45//! # Annotation Format
46//!
47//! Annotations can be shorthand (applies to all operations):
48//! ```json
49//! { "ucp_request": "omit" }
50//! ```
51//!
52//! Or per-operation:
53//! ```json
54//! { "ucp_request": { "create": "omit", "update": "required" } }
55//! ```
56
57mod compose;
58mod error;
59mod linter;
60mod loader;
61mod resolver;
62mod types;
63mod validator;
64
65pub use compose::{
66 capability_short_name, check_version_constraints, compose_from_payload, compose_schema,
67 detect_direction, extract_capabilities, extract_capabilities_from_profile,
68 extract_jsonrpc_payload, is_container_schema, Capability, DetectedDirection, SchemaBaseConfig,
69 VersionViolation,
70};
71pub use error::{ComposeError, ResolveError, SchemaError, ValidateError};
72pub use linter::{lint, lint_file, Diagnostic, FileResult, FileStatus, LintResult, Severity};
73pub use loader::{
74 bundle_refs, bundle_refs_with_url_mapping, is_url, load_schema, load_schema_auto,
75 load_schema_str, navigate_fragment,
76};
77pub use resolver::{resolve, strip_annotations};
78pub use types::{Direction, Requires, ResolveOptions, VersionConstraint, Visibility};
79pub use validator::{select_operation_schema, validate, validate_against_schema};
80
81#[cfg(feature = "remote")]
82pub use loader::{bundle_refs_remote, load_schema_url};