Skip to content

Commit b6becb9

Browse files
0.2.0 development
1 parent 2c38e0c commit b6becb9

File tree

11 files changed

+407
-250
lines changed

11 files changed

+407
-250
lines changed

data/example-jsnac.json

Lines changed: 102 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,111 @@
11
{
2-
"chassis": {
2+
"header": {
3+
"id": "example-schema.json",
4+
"schema": "http://json-schema.org/draft-07/schema",
5+
"title": "JSNAC Created Schema",
6+
"description": "The below schema was created by JSNAC (https://github.com/commitconfirmed/jsnac)"
7+
},
8+
"kinds": {
39
"hostname": {
4-
"jsnac_type": "pattern",
5-
"jsnac_pattern": "^ceos-[a-zA-Z]{1,16}[0-9]$"
6-
},
7-
"model": "ceos",
8-
"type": {
9-
"jsnac_type": "choice",
10-
"jsnac_choices": [
11-
"router",
12-
"switch",
13-
"spine",
14-
"leaf"
15-
]
10+
"title": "Hostname",
11+
"description": "Hostname of the device",
12+
"type": "pattern",
13+
"regex": "^[a-zA-Z0-9-]{1,63}$"
1614
}
1715
},
18-
"system": {
19-
"domain_name": {
20-
"jsnac_type": "domain"
21-
},
22-
"ntp_servers": [
23-
{
24-
"jsnac_type": "ipv4"
25-
}
26-
]
27-
},
28-
"interfaces": [
29-
{
30-
"if": {
31-
"jsnac_type": "string"
16+
"schema": {
17+
"chassis": {
18+
"title": "Chassis",
19+
"description": "Chassis information",
20+
"type": "object",
21+
"properties": {
22+
"hostname": {
23+
"kind": {
24+
"name": "hostname"
25+
}
26+
},
27+
"model": {
28+
"kind": {
29+
"name": "string"
30+
}
31+
},
32+
"device_type": {
33+
"title": "Type",
34+
"description": "Type of the device",
35+
"kind": {
36+
"name": "choice",
37+
"choices": [
38+
"router",
39+
"switch",
40+
"firewall",
41+
"load-balancer"
42+
]
43+
}
44+
}
3245
},
33-
"desc": {
34-
"jsnac_type": "string"
35-
},
36-
"ipv4": {
37-
"jsnac_type": "ipv4_cidr"
46+
"required": [
47+
"hostname",
48+
"model",
49+
"type"
50+
]
51+
},
52+
"system": {
53+
"title": "System",
54+
"description": "System information",
55+
"type": "object",
56+
"properties": {
57+
"domain_name": {
58+
"kind": {
59+
"name": "string"
60+
}
61+
},
62+
"ntp_servers": {
63+
"title": "NTP Servers",
64+
"description": "List of NTP servers",
65+
"type": "array",
66+
"items": {
67+
"kind": {
68+
"name": "ipv4"
69+
}
70+
}
71+
}
3872
},
39-
"ipv6": {
40-
"jsnac_type": "ipv6_cidr"
73+
"required": [
74+
"domain_name",
75+
"ntp_servers"
76+
]
77+
},
78+
"interfaces": {
79+
"title": "Interfaces",
80+
"type": "array",
81+
"items": {
82+
"type": "object",
83+
"properties": {
84+
"if": {
85+
"kind": {
86+
"name": "string"
87+
}
88+
},
89+
"desc": {
90+
"kind": {
91+
"name": "string"
92+
}
93+
},
94+
"ipv4": {
95+
"kind": {
96+
"name": "ipv4_cidr"
97+
}
98+
},
99+
"ipv6": {
100+
"kind": {
101+
"name": "ipv6_cidr"
102+
}
103+
}
104+
},
105+
"required": [
106+
"if"
107+
]
41108
}
42109
}
43-
]
110+
}
44111
}

data/example-jsnac.yml

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,58 @@
1-
chassis:
2-
hostname: { jsnac_type: pattern, jsnac_pattern: "^ceos-[a-zA-Z]{1,16}[0-9]$" }
3-
model: "ceos"
4-
type: { jsnac_type: choice, jsnac_choices: ["router", "switch", "spine", "leaf"] }
1+
---
2+
header:
3+
id: "example-schema.json"
4+
schema: "http://json-schema.org/draft-07/schema"
5+
title: "JSNAC Created Schema"
6+
description: "The below schema was created by JSNAC (https://github.com/commitconfirmed/jsnac)"
57

6-
system:
7-
domain_name: { jsnac_type: domain }
8-
ntp_servers: [ { jsnac_type: ipv4 } ]
9-
10-
interfaces:
11-
- if: { jsnac_type: string }
12-
desc: { jsnac_type: string }
13-
ipv4: { jsnac_type: ipv4_cidr }
14-
ipv6: { jsnac_type: ipv6_cidr }
8+
kinds:
9+
hostname:
10+
title: "Hostname"
11+
description: "Hostname of the device"
12+
type: "pattern"
13+
regex: "^[a-zA-Z0-9-]{1,63}$"
14+
15+
schema:
16+
chassis:
17+
title: "Chassis"
18+
description: "Chassis information"
19+
type: "object"
20+
properties:
21+
hostname:
22+
kind: { name: "hostname" }
23+
model:
24+
kind: { name: "string" }
25+
device_type:
26+
title: "Type"
27+
description: "Type of the device"
28+
kind: { name: "choice", choices: [ "router", "switch", "firewall", "load-balancer" ] }
29+
required: [ "hostname", "model", "type" ]
30+
system:
31+
title: "System"
32+
description: "System information"
33+
type: "object"
34+
properties:
35+
domain_name:
36+
kind: { name: "string" }
37+
ntp_servers:
38+
title: "NTP Servers"
39+
description: "List of NTP servers"
40+
type: "array"
41+
items:
42+
kind: { name: "ipv4" }
43+
required: [ "domain_name", "ntp_servers" ]
44+
interfaces:
45+
title: "Interfaces"
46+
type: "array"
47+
items:
48+
type: "object"
49+
properties:
50+
if:
51+
kind: { name: "string" }
52+
desc:
53+
kind: { name: "string" }
54+
ipv4:
55+
kind: { name: "ipv4_cidr" }
56+
ipv6:
57+
kind: { name: "ipv6_cidr" }
58+
required: [ "if" ]

data/example.schema.json

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema",
33
"title": "JSNAC Created Schema",
4+
"$id": "example-schema.json",
45
"description": "The below schema was created by JSNAC (https://github.com/commitconfirmed/jsnac)",
56
"$defs": {
67
"ipv4": {
@@ -50,42 +51,49 @@
5051
"pattern": "^[a-zA-Z0-9!@#$%^&*()_+-\\{\\}|:;\"'<>,.?/ ]{1,255}$",
5152
"title": "String",
5253
"description": "Alphanumeric string with special characters (String) \n Max length: 255"
54+
},
55+
"hostname": {
56+
"title": "Hostname",
57+
"description": "Hostname of the device",
58+
"type": "string",
59+
"pattern": "^[a-zA-Z0-9-]{1,63}$"
5360
}
5461
},
5562
"type": "object",
5663
"additionalProperties": false,
5764
"properties": {
5865
"chassis": {
66+
"title": "Chassis",
67+
"description": "Chassis information",
5968
"type": "object",
6069
"properties": {
6170
"hostname": {
62-
"type": "string",
63-
"pattern": "^ceos-[a-zA-Z]{1,16}[0-9]$",
64-
"title": "Custom Pattern",
65-
"description": "Custom Pattern (regex) \n Pattern: ^ceos-[a-zA-Z]{1,16}[0-9]$"
71+
"$ref": "#/$defs/hostname"
6672
},
6773
"model": {
6874
"type": "string"
6975
},
70-
"type": {
76+
"device_type": {
7177
"enum": [
7278
"router",
7379
"switch",
74-
"spine",
75-
"leaf"
76-
],
77-
"title": "Custom Choice",
78-
"description": "Custom Choice (enum) \n Choices: router, switch, spine, leaf"
80+
"firewall",
81+
"load-balancer"
82+
]
7983
}
8084
}
8185
},
8286
"system": {
87+
"title": "System",
88+
"description": "System information",
8389
"type": "object",
8490
"properties": {
8591
"domain_name": {
86-
"$ref": "#/$defs/domain"
92+
"type": "string"
8793
},
8894
"ntp_servers": {
95+
"title": "NTP Servers",
96+
"description": "List of NTP servers",
8997
"type": "array",
9098
"items": {
9199
"$ref": "#/$defs/ipv4"
@@ -94,15 +102,17 @@
94102
}
95103
},
96104
"interfaces": {
105+
"title": "Interfaces",
106+
"description": "Object: interfaces",
97107
"type": "array",
98108
"items": {
99109
"type": "object",
100110
"properties": {
101111
"if": {
102-
"$ref": "#/$defs/string"
112+
"type": "string"
103113
},
104114
"desc": {
105-
"$ref": "#/$defs/string"
115+
"type": "string"
106116
},
107117
"ipv4": {
108118
"$ref": "#/$defs/ipv4_cidr"

data/example.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# yaml-language-server: $schema=example.schema.json
2-
2+
---
33
chassis:
44
hostname: "ceos-spine1"
55
model: "ceos"

data/regenerate_test_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def main() -> None: # noqa: D103
5757
with example_jsnac_file.open() as f:
5858
jsnac = SchemaInferer()
5959
jsnac.add_yaml(f.read())
60-
schema = jsnac.build()
60+
schema = jsnac.build_schema()
6161
f.close()
6262
with output_schema_file.open(mode="w") as f:
6363
f.write(schema)
File renamed without changes.

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
project = "JSNAC"
1010
copyright = "2024, Andrew Jones"
1111
author = "Andrew Jones"
12-
release = "0.1.0"
12+
release = "0.2.0"
1313

1414
# -- General configuration ---------------------------------------------------
1515
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

0 commit comments

Comments
 (0)