json_utils/schema/
schema_node_into_compiled.rs1use super::SchemaNode;
2
3use serde_json::Error as SerializeError;
4use valico::json_schema::Scope;
5use valico::json_schema::SchemaError;
6
7use super::SchemaCompiled;
8
9#[derive(Debug, Fail)]
10pub enum CompileError {
11 #[fail(display = "CompileError::SerializeError: {:?}", _0)]
12 SerializeError(#[cause] SerializeError),
13
14 #[fail(display = "CompileError::SchemaError: {:?}", _0)]
15 SchemaError(SchemaError),
16}
17
18enum_variant_from!(CompileError, SerializeError, SerializeError);
19enum_variant_from!(CompileError, SchemaError, SchemaError);
20
21impl SchemaNode {
22 pub fn into_compiled(self) -> Result<SchemaCompiled, CompileError> {
23 let json = serde_json::to_value(self)?;
24
25 let schema = {
26 let mut scope = Scope::new();
27 scope.compile_with_id(SchemaCompiled::root_url(), json, false)
28 .map(|_url| scope)
29 .map(SchemaCompiled)
30 }?;
31
32 Ok(schema)
33 }
34}