Skip to content

Commit 5d02917

Browse files
authored
Merge pull request #85 from networktocode/psi/updates-per-jason-review
Documentation Updates
2 parents ecca386 + 55c745c commit 5d02917

File tree

1 file changed

+46
-9
lines changed

1 file changed

+46
-9
lines changed

README.md

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Schema Enforcer
22

3-
Schema Enforcer provides a framework for testing structured data against schema definitions. Right now, [JSONSchema](https://json-schema.org/understanding-json-schema/index.html) is the only schema definition language supported, but we intend to add support for YANG and other schema definition languages at some point in the future.
3+
Schema Enforcer provides a framework for testing structured data against schema definitions. Right now, [JSONSchema](https://json-schema.org/understanding-json-schema/index.html) is the only schema definition language supported, but we are thinking about adding other schema definition languages at some point in the future.
44

55
## Getting Started
66

@@ -67,7 +67,7 @@ dns_servers:
6767
- address: "10.1.1.1"
6868
- address: "10.2.2.2"
6969
```
70-
> Note: The line `# jsonschema: schemas/dns_servers` tells `schema-enforcer` the ID of the schema which the structured data defined in the file should be validated against. More information on how the structured data is mapped to a schema ID to which it should adhere can be found in the [docs/mapping_schemas.md README](./docs/mapping_schemas.md)
70+
> Note: The line `# jsonschema: schemas/dns_servers` tells `schema-enforcer` the ID of the schema which the structured data defined in the file should be validated against. The schema ID is defined by the `$id` top level key in a schema definition. More information on how the structured data is mapped to a schema ID to which it should adhere can be found in the [mapping_schemas README](./docs/mapping_schemas.md)
7171

7272
The file `schema/schemas/dns.yml` is a schema definition file. It contains a schema definition for ntp servers written in JSONSchema. The data in `chi-beijing-rt1/dns.yml` and `eng-london-rt1/dns.yml` should adhere to the schema defined in this schema definition file.
7373

@@ -104,7 +104,7 @@ required:
104104

105105
Once schema-enforcer has been installed, the `schema-enforcer validate` command can be used run schema validations of YAML/JSON instance files against the defined schema.
106106

107-
```cli
107+
```shell
108108
bash$ schema-enforcer --help
109109
Usage: schema-enforcer [OPTIONS] COMMAND [ARGS]...
110110
@@ -119,15 +119,15 @@ Commands:
119119

120120
To run the schema validations, the command `schema-enforcer validate` can be run.
121121

122-
```cli
122+
```shell
123123
bash$ schema-enforcer validate
124124
schema-enforcer validate
125125
ALL SCHEMA VALIDATION CHECKS PASSED
126126
```
127127

128128
To acquire more context regarding what files specifically passed schema validation, the `--show-pass` flag can be passed in.
129129

130-
```cli
130+
```shell
131131
bash$ schema-enforcer validate --show-pass
132132
PASS [FILE] ./eng-london-rt1/ntp.yml
133133
PASS [FILE] ./eng-london-rt1/dns.yml
@@ -138,13 +138,15 @@ ALL SCHEMA VALIDATION CHECKS PASSED
138138

139139
If we modify one of the addresses in the `chi-beijing-rt1/dns.yml` file so that it's value is the boolean `true` instead of an IP address string, then run the `schema-enforcer` tool, the validation will fail with an error message.
140140

141-
```cli
141+
```yaml
142142
bash$ cat chi-beijing-rt1/dns.yml
143143
# jsonschema: schemas/dns_servers
144144
---
145145
dns_servers:
146146
- address: true
147147
- address: "10.2.2.2"
148+
```
149+
```shell
148150
bash$ test-schema validate
149151
FAIL | [ERROR] True is not of type 'string' [FILE] ./chi-beijing-rt1/dns.yml [PROPERTY] dns_servers:0:address
150152
bash$ echo $?
@@ -153,11 +155,46 @@ bash$ echo $?
153155

154156
When a structured data file fails schema validation, `schema-enforcer` exits with a code of 1.
155157

158+
### Configuration Settings
159+
160+
Schema enforcer will work with default settings, however, a `pyproject.toml` file can be placed at the root of the path in which `schema-enforcer` is run in order to override default settings or declare configuration for more advanced features. Inside of this `pyproject.toml` file, `tool.schema_enfocer` sections can be used to declare settings for schema enforcer. Take for example the `pyproject.toml` file in example 2.
161+
162+
```shell
163+
bash$ cd examples/example2 && tree -L 2
164+
.
165+
├── README.md
166+
├── hostvars
167+
│ ├── chi-beijing-rt1
168+
│ ├── eng-london-rt1
169+
│ └── ger-berlin-rt1
170+
├── invalid
171+
├── pyproject.toml
172+
└── schema
173+
├── definitions
174+
└── schemas
175+
176+
8 directories, 2 files
177+
```
178+
179+
In this toml file, a schema mapping is declared which tells schema enforcer which structured data files should be checked by which schema IDs.
180+
181+
182+
```shell
183+
bash$ cat pyproject.toml
184+
[tool.schema_enforcer.schema_mapping]
185+
# Map structured data filename to schema IDs
186+
'dns_v1.yml' = ['schemas/dns_servers']
187+
'dns_v2.yml' = ['schemas/dns_servers_v2']
188+
'syslog.yml' = ['schemas/syslog_servers']
189+
```
190+
191+
> More information on available configuration settings can be found in the [configuration README](docs/configuration.md)
156192
### Where To Go Next
157193

158-
More detailed documentation can be found inside of README.md files inside of the `docs/` directory.
194+
Detailed documentation can be found in the README.md files inside of the `docs/` directory.
195+
- ["Introducing Schema Enforcer" blog post](https://blog.networktocode.com/post/introducing_schema_enforcer/)
159196
- [Using a pyproject.toml file for configuration](docs/configuration.md)
160-
- [Mapping Structured Data Files to Schema Files](docs/mapping_schemas.md)
197+
- [The `ansible` command](docs/ansible_command.md)
161198
- [The `validate` command](docs/validate_command.md)
199+
- [Mapping Structured Data Files to Schema Files](docs/mapping_schemas.md)
162200
- [The `schema` command](docs/schema_command.md)
163-
- [The Ansible command](docs/ansible_command.md)

0 commit comments

Comments
 (0)