Skip to main content

specmock_core/
lib.rs

1//! Shared contract types, schema validation, and deterministic data generation.
2
3pub mod contract;
4pub mod error;
5pub mod faker;
6pub mod ref_resolver;
7pub mod schema;
8pub mod validate;
9
10pub use contract::{MockMode, Protocol, ValidationDirection};
11pub use error::{PROBLEM_JSON_CONTENT_TYPE, ProblemDetails, SpecMockCoreError, ValidationIssue};
12
13#[cfg(test)]
14mod tests {
15    use serde_json::json;
16
17    #[test]
18    fn faker_generates_value_that_validates() {
19        let schema = json!({
20            "type": "object",
21            "required": ["id", "name"],
22            "properties": {
23                "id": {"type": "integer", "minimum": 1},
24                "name": {"type": "string", "minLength": 1}
25            }
26        });
27
28        let value =
29            crate::faker::generate_json_value(&schema, 7).expect("faker should generate a value");
30        let errors = crate::validate::validate_instance(&schema, &value)
31            .expect("validator should compile schema");
32
33        assert!(errors.is_empty(), "expected no validation errors: {errors:?}");
34    }
35}