golem_schema/lib.rs
1// Copyright 2024-2026 Golem Cloud
2//
3// Licensed under the Golem Source License v1.1 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://license.golem.cloud/LICENSE
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Schema representation, canonical encoding, and validation.
16//!
17//! `regex` enables the Rust `regex` crate's complete existing dialect for text
18//! restrictions and union discriminators. `url` enables WHATWG URL validation
19//! (including IDNA) and conversions for `url::Url`. `rich-validation` enables
20//! both; it is included by default and by `host` and `full`.
21//!
22//! With default features disabled, the schema representation and fixed MIME,
23//! quantity-unit, and tool-identifier grammars remain available. Validation
24//! requiring a disabled feature returns an explicit unsupported-feature error;
25//! it never accepts a value by skipping its regex or URL restriction. Regex
26//! union rendering also fails explicitly. Enable the needed features in guests
27//! that validate these rich values. URL schema structure and canonical encoding
28//! do not require URL parsing; value validation does.
29
30#[cfg(all(feature = "host", feature = "guest"))]
31compile_error!("golem-schema features `host` and `guest` are mutually exclusive");
32
33// Allows the `IntoSchema` / `FromSchema` derive macros to be used on types
34// defined inside this crate when proc-macro-crate resolves this package as a
35// regular crate name.
36extern crate self as golem_schema;
37
38#[cfg(test)]
39test_r::enable!();
40
41pub mod http;
42pub mod model;
43pub mod schema;
44
45/// Protobuf messages of the schema and tool model, generated from this crate's `proto` directory.
46#[cfg(feature = "protobuf")]
47#[allow(clippy::large_enum_variant)]
48pub mod proto {
49 use uuid::Uuid;
50
51 include!(concat!(env!("OUT_DIR"), "/mod.rs"));
52
53 impl From<Uuid> for golem::common::Uuid {
54 fn from(value: Uuid) -> Self {
55 let (high_bits, low_bits) = value.as_u64_pair();
56 golem::common::Uuid {
57 high_bits,
58 low_bits,
59 }
60 }
61 }
62
63 impl From<golem::common::Uuid> for Uuid {
64 fn from(value: golem::common::Uuid) -> Self {
65 let high_bits = value.high_bits;
66 let low_bits = value.low_bits;
67 Uuid::from_u64_pair(high_bits, low_bits)
68 }
69 }
70}
71
72pub use model::*;
73pub use schema::*;