Skip to content

0.2.1 release #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .coverage
Binary file not shown.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
tox:
strategy:
matrix:
python-version: [ '3.10', '3.11', '3.12' ]
python-version: [ '3.10', '3.11', '3.12', '3.13' ]
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}
steps:
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ htmlcov/
docs/build/

# JSNAC default output file
jsnac.schema.json
jsnac.schema.json

# Release notes
release.txt
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ version: 2
build:
os: ubuntu-22.04
tools:
python: "3.12"
python: "3.13"
# You can also specify other tool versions:
# nodejs: "19"
# rust: "1.64"
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Will use this argument eventually to specify the python version so we can test against multiple versions
ARG PYTHON=3.11
ARG PYTHON=3.13
FROM python:${PYTHON}-slim-bookworm

ENV PATH="/root/.local/bin:$PATH" \
Expand Down
53 changes: 27 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ interfaces:
ipv4: "10.1.0.20/24"
```

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.
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.

```yaml
header:
Expand All @@ -59,33 +59,33 @@ schema:
type: "object"
properties:
hostname:
kind: { name: "string" }
js_kind: { name: "string" }
model:
kind: { name: "string" }
js_kind: { name: "string" }
device_type:
kind: { name: "choice", choices: [ "router", "switch", "firewall", "load-balancer" ] }
js_kind: { name: "choice", choices: [ "router", "switch", "firewall", "load-balancer" ] }
system:
type: "object"
properties:
domain_name:
kind: { name: "string" }
js_kind: { name: "string" }
ntp_servers:
type: "array"
items:
kind: { name: "ipv4" }
js_kind: { name: "ipv4" }
interfaces:
type: "array"
items:
type: "object"
properties:
if:
kind: { name: "string" }
js_kind: { name: "string" }
desc:
kind: { name: "string" }
js_kind: { name: "string" }
ipv4:
kind: { name: "ipv4_cidr" }
js_kind: { name: "ipv4_cidr" }
ipv6:
kind: { name: "ipv6_cidr" }
js_kind: { name: "ipv6_cidr" }
```

```bash
Expand All @@ -112,7 +112,7 @@ Which language server you use is specific to your environment and editor that yo

## Detailed Example

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:
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:

```yaml
header:
Expand All @@ -124,7 +124,7 @@ header:
- system
- interfaces

kinds:
js_kinds:
hostname:
title: "Hostname"
description: "Hostname of the device"
Expand All @@ -142,15 +142,15 @@ schema:
type: "object"
properties:
hostname:
kind: { name: "hostname" }
js_kind: { name: "hostname" }
model:
kind: { name: "string" }
js_kind: { name: "string" }
device_type:
title: "Device Type"
description: |
Device Type options are:
router, switch, firewall, load-balancer
kind: { name: "choice", choices: [ "router", "switch", "firewall", "load-balancer" ] }
js_kind: { name: "choice", choices: [ "router", "switch", "firewall", "load-balancer" ] }
required: [ "hostname", "model", "device_type" ]
system:
title: "System"
Expand All @@ -161,13 +161,13 @@ schema:
type: "object"
properties:
domain_name:
kind: { name: "string" }
js_kind: { name: "string" }
ntp_servers:
title: "NTP Servers"
description: "List of NTP servers"
type: "array"
items:
kind: { name: "ipv4" }
js_kind: { name: "ipv4" }
required: [ "domain_name", "ntp_servers" ]
interfaces:
title: "Device Interfaces"
Expand All @@ -182,17 +182,17 @@ schema:
type: "object"
properties:
if:
kind: { name: "string" }
js_kind: { name: "string" }
desc:
kind: { name: "string" }
js_kind: { name: "string" }
ipv4:
kind: { name: "ipv4_cidr" }
js_kind: { name: "ipv4_cidr" }
ipv6:
kind: { name: "ipv6_cidr" }
js_kind: { name: "ipv6_cidr" }
required: [ "if" ]
```

A full list of kinds are available in the [documentation](https://jsnac.readthedocs.io/en/latest/)
A full list of js_kinds are available in the [documentation](https://jsnac.readthedocs.io/en/latest/)

## Usage

Expand All @@ -215,14 +215,15 @@ jsnac -f data/example-jsnac.yml -v
### Library
```python
"""
This example demonstrates how to use the jsnac library to build a JSON schema from a YAML file in a Python script.
Example yml file is available here: <https://www.github.com/commitconfirmed/jsnac/blob/main/data/example-jsnac.yml>
This example demonstrates how to use the jsnac library to build a JSON schema
from a YAML file in a Python script. An example YAML file is available below:
<https://www.github.com/commitconfirmed/jsnac/blob/main/data/example-jsnac.yml>
"""
from jsnac.core.infer import SchemaInferer
from jsnac.core.build import SchemaBuilder

def main():
# Create a SchemaInferer object
jsnac = SchemaInferer()
jsnac = SchemaBuilder()

# Load the YAML data however you like into the SchemaInferer object
with open('data/example-jsnac.yml', 'r') as file:
Expand Down
26 changes: 11 additions & 15 deletions data/example-jsnac.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"title": "Example Schema",
"description": "Ansible host vars for my networking device. Requires the below objects:\n- chassis\n- system\n- interfaces\n"
},
"kinds": {
"js_kinds": {
"hostname": {
"title": "Hostname",
"description": "Hostname of the device",
Expand All @@ -17,22 +17,22 @@
"chassis": {
"title": "Chassis",
"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",
"type": "object",
"properties": {
"hostname": {
"kind": {
"js_kind": {
"name": "hostname"
}
},
"model": {
"kind": {
"description": "Model of the device",
"js_kind": {
"name": "string"
}
},
"device_type": {
"title": "Device Type",
"description": "Device Type options are:\nrouter, switch, firewall, load-balancer\n",
"kind": {
"js_kind": {
"name": "choice",
"choices": [
"router",
Expand All @@ -52,19 +52,17 @@
"system": {
"title": "System",
"description": "Object containing System information. Has the below properties:\ndomain_name [required]: string\nntp_servers [required]: list of ipv4 addresses\n",
"type": "object",
"properties": {
"domain_name": {
"kind": {
"js_kind": {
"name": "string"
}
},
"ntp_servers": {
"title": "NTP Servers",
"description": "List of NTP servers",
"type": "array",
"items": {
"kind": {
"js_kind": {
"name": "ipv4"
}
}
Expand All @@ -78,27 +76,25 @@
"interfaces": {
"title": "Device Interfaces",
"description": "List of device interfaces. Each interface has the below properties:\nif [required]: string\ndesc: string\nipv4: ipv4_cidr\nipv6: ipv6_cidr\n",
"type": "array",
"items": {
"type": "object",
"properties": {
"if": {
"kind": {
"js_kind": {
"name": "string"
}
},
"desc": {
"kind": {
"js_kind": {
"name": "string"
}
},
"ipv4": {
"kind": {
"js_kind": {
"name": "ipv4_cidr"
}
},
"ipv6": {
"kind": {
"js_kind": {
"name": "ipv6_cidr"
}
}
Expand Down
26 changes: 11 additions & 15 deletions data/example-jsnac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ header:
- system
- interfaces

kinds:
js_kinds:
hostname:
title: "Hostname"
description: "Hostname of the device"
Expand All @@ -24,35 +24,33 @@ schema:
hostname [required]: hostname
model [required]: string
device_type [required]: choice (router, switch, firewall, load-balancer)
type: "object"
properties:
hostname:
kind: { name: "hostname" }
js_kind: { name: "hostname" }
model:
kind: { name: "string" }
description: "Model of the device"
js_kind: { name: "string" }
device_type:
title: "Device Type"
description: |
Device Type options are:
router, switch, firewall, load-balancer
kind: { name: "choice", choices: [ "router", "switch", "firewall", "load-balancer" ] }
js_kind: { name: "choice", choices: [ "router", "switch", "firewall", "load-balancer" ] }
required: [ "hostname", "model", "device_type" ]
system:
title: "System"
description: |
Object containing System information. Has the below properties:
domain_name [required]: string
ntp_servers [required]: list of ipv4 addresses
type: "object"
properties:
domain_name:
kind: { name: "string" }
js_kind: { name: "string" }
ntp_servers:
title: "NTP Servers"
description: "List of NTP servers"
type: "array"
items:
kind: { name: "ipv4" }
js_kind: { name: "ipv4" }
required: [ "domain_name", "ntp_servers" ]
interfaces:
title: "Device Interfaces"
Expand All @@ -62,16 +60,14 @@ schema:
desc: string
ipv4: ipv4_cidr
ipv6: ipv6_cidr
type: "array"
items:
type: "object"
properties:
if:
kind: { name: "string" }
js_kind: { name: "string" }
desc:
kind: { name: "string" }
js_kind: { name: "string" }
ipv4:
kind: { name: "ipv4_cidr" }
js_kind: { name: "ipv4_cidr" }
ipv6:
kind: { name: "ipv6_cidr" }
js_kind: { name: "ipv6_cidr" }
required: [ "if" ]
Loading
Loading