Skip to content

Commit

Permalink
0.2.1 development
Browse files Browse the repository at this point in the history
  • Loading branch information
commitconfirmed committed Dec 1, 2024
1 parent c1482f9 commit dabc7eb
Show file tree
Hide file tree
Showing 18 changed files with 115 additions and 110 deletions.
Binary file modified .coverage
Binary file not shown.
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
20 changes: 10 additions & 10 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 @@ -20,19 +20,19 @@
"type": "object",
"properties": {
"hostname": {
"kind": {
"js_kind": {
"name": "hostname"
}
},
"model": {
"kind": {
"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 @@ -55,7 +55,7 @@
"type": "object",
"properties": {
"domain_name": {
"kind": {
"js_kind": {
"name": "string"
}
},
Expand All @@ -64,7 +64,7 @@
"description": "List of NTP servers",
"type": "array",
"items": {
"kind": {
"js_kind": {
"name": "ipv4"
}
}
Expand All @@ -83,22 +83,22 @@
"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
20 changes: 10 additions & 10 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 @@ -27,15 +27,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 @@ -46,13 +46,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 @@ -67,11 +67,11 @@ 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" ]
4 changes: 2 additions & 2 deletions data/regenerate_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import yaml

from jsnac.core.infer import SchemaInferer
from jsnac.core.build import SchemaBuilder


def write_json(file: str) -> None: # noqa: D103
Expand Down Expand Up @@ -55,7 +55,7 @@ def main() -> None: # noqa: D103
write_json(example_jsnac_file)
# Generate a schema for example-jsnac.yml
with example_jsnac_file.open() as f:
jsnac = SchemaInferer()
jsnac = SchemaBuilder()
jsnac.add_yaml(f.read())
schema = jsnac.build_schema()
f.close()
Expand Down
Binary file added dist/jsnac-0.2.1-py3-none-any.whl
Binary file not shown.
Binary file added dist/jsnac-0.2.1.tar.gz
Binary file not shown.
9 changes: 5 additions & 4 deletions docs/source/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ Library usage:
.. code-block:: 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
Loading

0 comments on commit dabc7eb

Please sign in to comment.