aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 02fcf1d8a524dacb96f78f065c4b59fe143cfd96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# kdl-schema

[KDL Schema](https://github.com/kdl-org/kdl/blob/1.0.0/SCHEMA-SPEC.md) types and parsing.

## examples

### building a schema

```rust
use kdl_schema::*;
let schema = Schema {
    document: Document {
        info: Info {
            title: vec![TextValue {
                text: "Sample Schema".to_string(),
                lang: Some("en".to_string()),
            }],
            ..Info::default()
        },
        nodes: vec![Node {
            name: Some("name".to_string()),
            values: vec![Value {
                validations: vec![Validation::Type("string".to_string())],
                ..Value::default()
            }],
            ..Node::default()
        }]
    }
};
println!("{:?}", schema);
```

### parsing a schema KDL

```rust
#[cfg(feature = "parse-knuffel")] {
    let schema_kdl = r#"
document {
    info {
        title "Sample Schema" lang="en"
        description "An example schema" lang="en"
        author "boringcactus"
    }
    node "name" {
        value {
            type "string"
        }
    }
    node "age" {
        value {
            type "number"
        }
    }
}
"#;
    let _matching_document = r#"
name "Joe"
age 69
"#;
    let schema = kdl_schema::Schema::parse(schema_kdl).unwrap();
    assert_eq!(schema.document.info.title[0].text, "Sample Schema");
}
```

### referencing the schema schema

```rust
assert_eq!(kdl_schema::SCHEMA_SCHEMA.document.info.title[0].text, "KDL Schema");
```

## cargo features

- `parse-knuffel` - expose `Schema::parse`, powered by [the `knuffel` crate](https://crates.io/crates/knuffel)

## conditions blocking version 1.0.0

- good API for parsing from a file
- good API for resolving refs (as long as the ref is a simple global query by ID because using anything other than that as a ref is a weird lifehack and not idiomatic)
- types actually match the schema (currently I'm omitting several things because the schema schema doesn't use them)
- ergonomic builder API to define a schema in Rust in a non-ugly way
- can generate KDL from schema object in Rust
- can choose kdl or knuffel as parser

## license

[Blue Oak Model License 1.0.0](https://blueoakcouncil.org/license/1.0.0).