Skip to content

Commit 9ba9957

Browse files
Merge pull request #2 from commitconfirmed/dev
0.2.1 release
2 parents c1482f9 + 35ec611 commit 9ba9957

27 files changed

+1019
-572
lines changed

.coverage

0 Bytes
Binary file not shown.

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
tox:
77
strategy:
88
matrix:
9-
python-version: [ '3.10', '3.11', '3.12' ]
9+
python-version: [ '3.10', '3.11', '3.12', '3.13' ]
1010
platform: [ubuntu-latest]
1111
runs-on: ${{ matrix.platform }}
1212
steps:

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@ htmlcov/
1818
docs/build/
1919

2020
# JSNAC default output file
21-
jsnac.schema.json
21+
jsnac.schema.json
22+
23+
# Release notes
24+
release.txt

.readthedocs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ version: 2
99
build:
1010
os: ubuntu-22.04
1111
tools:
12-
python: "3.12"
12+
python: "3.13"
1313
# You can also specify other tool versions:
1414
# nodejs: "19"
1515
# rust: "1.64"

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Will use this argument eventually to specify the python version so we can test against multiple versions
2-
ARG PYTHON=3.11
2+
ARG PYTHON=3.13
33
FROM python:${PYTHON}-slim-bookworm
44

55
ENV PATH="/root/.local/bin:$PATH" \

README.md

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ interfaces:
4747
ipv4: "10.1.0.20/24"
4848
```
4949
50-
You can simply write out how you would like to document & validate this data in YAML using kinds, and this program will write out a JSON schema you can use.
50+
You can simply write out how you would like to document & validate this data in a YAML file, and this program will generate a JSON schema you can use.
5151
5252
```yaml
5353
header:
@@ -59,33 +59,33 @@ schema:
5959
type: "object"
6060
properties:
6161
hostname:
62-
kind: { name: "string" }
62+
js_kind: { name: "string" }
6363
model:
64-
kind: { name: "string" }
64+
js_kind: { name: "string" }
6565
device_type:
66-
kind: { name: "choice", choices: [ "router", "switch", "firewall", "load-balancer" ] }
66+
js_kind: { name: "choice", choices: [ "router", "switch", "firewall", "load-balancer" ] }
6767
system:
6868
type: "object"
6969
properties:
7070
domain_name:
71-
kind: { name: "string" }
71+
js_kind: { name: "string" }
7272
ntp_servers:
7373
type: "array"
7474
items:
75-
kind: { name: "ipv4" }
75+
js_kind: { name: "ipv4" }
7676
interfaces:
7777
type: "array"
7878
items:
7979
type: "object"
8080
properties:
8181
if:
82-
kind: { name: "string" }
82+
js_kind: { name: "string" }
8383
desc:
84-
kind: { name: "string" }
84+
js_kind: { name: "string" }
8585
ipv4:
86-
kind: { name: "ipv4_cidr" }
86+
js_kind: { name: "ipv4_cidr" }
8787
ipv6:
88-
kind: { name: "ipv6_cidr" }
88+
js_kind: { name: "ipv6_cidr" }
8989
```
9090
9191
```bash
@@ -112,7 +112,7 @@ Which language server you use is specific to your environment and editor that yo
112112
113113
## Detailed Example
114114
115-
We also have full support for writing your own titles, descriptions, kinds (sub-schemas), objects that are required, etc. A more fleshed out example of the same schema is below:
115+
We also have full support for writing your own titles, descriptions, js_kinds (sub-schemas), objects that are required, etc. A more fleshed out example of the same schema is below:
116116
117117
```yaml
118118
header:
@@ -124,7 +124,7 @@ header:
124124
- system
125125
- interfaces
126126
127-
kinds:
127+
js_kinds:
128128
hostname:
129129
title: "Hostname"
130130
description: "Hostname of the device"
@@ -142,15 +142,15 @@ schema:
142142
type: "object"
143143
properties:
144144
hostname:
145-
kind: { name: "hostname" }
145+
js_kind: { name: "hostname" }
146146
model:
147-
kind: { name: "string" }
147+
js_kind: { name: "string" }
148148
device_type:
149149
title: "Device Type"
150150
description: |
151151
Device Type options are:
152152
router, switch, firewall, load-balancer
153-
kind: { name: "choice", choices: [ "router", "switch", "firewall", "load-balancer" ] }
153+
js_kind: { name: "choice", choices: [ "router", "switch", "firewall", "load-balancer" ] }
154154
required: [ "hostname", "model", "device_type" ]
155155
system:
156156
title: "System"
@@ -161,13 +161,13 @@ schema:
161161
type: "object"
162162
properties:
163163
domain_name:
164-
kind: { name: "string" }
164+
js_kind: { name: "string" }
165165
ntp_servers:
166166
title: "NTP Servers"
167167
description: "List of NTP servers"
168168
type: "array"
169169
items:
170-
kind: { name: "ipv4" }
170+
js_kind: { name: "ipv4" }
171171
required: [ "domain_name", "ntp_servers" ]
172172
interfaces:
173173
title: "Device Interfaces"
@@ -182,17 +182,17 @@ schema:
182182
type: "object"
183183
properties:
184184
if:
185-
kind: { name: "string" }
185+
js_kind: { name: "string" }
186186
desc:
187-
kind: { name: "string" }
187+
js_kind: { name: "string" }
188188
ipv4:
189-
kind: { name: "ipv4_cidr" }
189+
js_kind: { name: "ipv4_cidr" }
190190
ipv6:
191-
kind: { name: "ipv6_cidr" }
191+
js_kind: { name: "ipv6_cidr" }
192192
required: [ "if" ]
193193
```
194194
195-
A full list of kinds are available in the [documentation](https://jsnac.readthedocs.io/en/latest/)
195+
A full list of js_kinds are available in the [documentation](https://jsnac.readthedocs.io/en/latest/)
196196
197197
## Usage
198198
@@ -215,14 +215,15 @@ jsnac -f data/example-jsnac.yml -v
215215
### Library
216216
```python
217217
"""
218-
This example demonstrates how to use the jsnac library to build a JSON schema from a YAML file in a Python script.
219-
Example yml file is available here: <https://www.github.com/commitconfirmed/jsnac/blob/main/data/example-jsnac.yml>
218+
This example demonstrates how to use the jsnac library to build a JSON schema
219+
from a YAML file in a Python script. An example YAML file is available below:
220+
<https://www.github.com/commitconfirmed/jsnac/blob/main/data/example-jsnac.yml>
220221
"""
221-
from jsnac.core.infer import SchemaInferer
222+
from jsnac.core.build import SchemaBuilder
222223

223224
def main():
224225
# Create a SchemaInferer object
225-
jsnac = SchemaInferer()
226+
jsnac = SchemaBuilder()
226227

227228
# Load the YAML data however you like into the SchemaInferer object
228229
with open('data/example-jsnac.yml', 'r') as file:

data/example-jsnac.json

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"title": "Example Schema",
66
"description": "Ansible host vars for my networking device. Requires the below objects:\n- chassis\n- system\n- interfaces\n"
77
},
8-
"kinds": {
8+
"js_kinds": {
99
"hostname": {
1010
"title": "Hostname",
1111
"description": "Hostname of the device",
@@ -17,22 +17,22 @@
1717
"chassis": {
1818
"title": "Chassis",
1919
"description": "Object containing Chassis information. Has the below properties: \nhostname [required]: hostname\nmodel [required]: string\ndevice_type [required]: choice (router, switch, firewall, load-balancer)\n",
20-
"type": "object",
2120
"properties": {
2221
"hostname": {
23-
"kind": {
22+
"js_kind": {
2423
"name": "hostname"
2524
}
2625
},
2726
"model": {
28-
"kind": {
27+
"description": "Model of the device",
28+
"js_kind": {
2929
"name": "string"
3030
}
3131
},
3232
"device_type": {
3333
"title": "Device Type",
3434
"description": "Device Type options are:\nrouter, switch, firewall, load-balancer\n",
35-
"kind": {
35+
"js_kind": {
3636
"name": "choice",
3737
"choices": [
3838
"router",
@@ -52,19 +52,17 @@
5252
"system": {
5353
"title": "System",
5454
"description": "Object containing System information. Has the below properties:\ndomain_name [required]: string\nntp_servers [required]: list of ipv4 addresses\n",
55-
"type": "object",
5655
"properties": {
5756
"domain_name": {
58-
"kind": {
57+
"js_kind": {
5958
"name": "string"
6059
}
6160
},
6261
"ntp_servers": {
6362
"title": "NTP Servers",
6463
"description": "List of NTP servers",
65-
"type": "array",
6664
"items": {
67-
"kind": {
65+
"js_kind": {
6866
"name": "ipv4"
6967
}
7068
}
@@ -78,27 +76,25 @@
7876
"interfaces": {
7977
"title": "Device Interfaces",
8078
"description": "List of device interfaces. Each interface has the below properties:\nif [required]: string\ndesc: string\nipv4: ipv4_cidr\nipv6: ipv6_cidr\n",
81-
"type": "array",
8279
"items": {
83-
"type": "object",
8480
"properties": {
8581
"if": {
86-
"kind": {
82+
"js_kind": {
8783
"name": "string"
8884
}
8985
},
9086
"desc": {
91-
"kind": {
87+
"js_kind": {
9288
"name": "string"
9389
}
9490
},
9591
"ipv4": {
96-
"kind": {
92+
"js_kind": {
9793
"name": "ipv4_cidr"
9894
}
9995
},
10096
"ipv6": {
101-
"kind": {
97+
"js_kind": {
10298
"name": "ipv6_cidr"
10399
}
104100
}

data/example-jsnac.yml

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ header:
99
- system
1010
- interfaces
1111
12-
kinds:
12+
js_kinds:
1313
hostname:
1414
title: "Hostname"
1515
description: "Hostname of the device"
@@ -24,35 +24,33 @@ schema:
2424
hostname [required]: hostname
2525
model [required]: string
2626
device_type [required]: choice (router, switch, firewall, load-balancer)
27-
type: "object"
2827
properties:
2928
hostname:
30-
kind: { name: "hostname" }
29+
js_kind: { name: "hostname" }
3130
model:
32-
kind: { name: "string" }
31+
description: "Model of the device"
32+
js_kind: { name: "string" }
3333
device_type:
3434
title: "Device Type"
3535
description: |
3636
Device Type options are:
3737
router, switch, firewall, load-balancer
38-
kind: { name: "choice", choices: [ "router", "switch", "firewall", "load-balancer" ] }
38+
js_kind: { name: "choice", choices: [ "router", "switch", "firewall", "load-balancer" ] }
3939
required: [ "hostname", "model", "device_type" ]
4040
system:
4141
title: "System"
4242
description: |
4343
Object containing System information. Has the below properties:
4444
domain_name [required]: string
4545
ntp_servers [required]: list of ipv4 addresses
46-
type: "object"
4746
properties:
4847
domain_name:
49-
kind: { name: "string" }
48+
js_kind: { name: "string" }
5049
ntp_servers:
5150
title: "NTP Servers"
5251
description: "List of NTP servers"
53-
type: "array"
5452
items:
55-
kind: { name: "ipv4" }
53+
js_kind: { name: "ipv4" }
5654
required: [ "domain_name", "ntp_servers" ]
5755
interfaces:
5856
title: "Device Interfaces"
@@ -62,16 +60,14 @@ schema:
6260
desc: string
6361
ipv4: ipv4_cidr
6462
ipv6: ipv6_cidr
65-
type: "array"
6663
items:
67-
type: "object"
6864
properties:
6965
if:
70-
kind: { name: "string" }
66+
js_kind: { name: "string" }
7167
desc:
72-
kind: { name: "string" }
68+
js_kind: { name: "string" }
7369
ipv4:
74-
kind: { name: "ipv4_cidr" }
70+
js_kind: { name: "ipv4_cidr" }
7571
ipv6:
76-
kind: { name: "ipv6_cidr" }
72+
js_kind: { name: "ipv6_cidr" }
7773
required: [ "if" ]

0 commit comments

Comments
 (0)