File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # .readthedocs.yaml
2+ # Read the Docs configuration file
3+ # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
4+
5+ # Required
6+ version : 2
7+
8+ # Set the OS, Python version and other tools you might need
9+ build :
10+ os : ubuntu-22.04
11+ tools :
12+ python : " 3.12"
13+ # You can also specify other tool versions:
14+ # nodejs: "19"
15+ # rust: "1.64"
16+ # golang: "1.19"
17+
18+ # Build documentation in the "docs/" directory with Sphinx
19+ sphinx :
20+ configuration : docs/conf.py
21+
22+ # Optionally build your docs in additional formats such as PDF and ePub
23+ # formats:
24+ # - pdf
25+ # - epub
26+
27+ # Optional but recommended, declare the Python requirements required
28+ # to build your documentation
29+ # See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
30+ # python:
31+ # install:
32+ # - requirements: docs/requirements.txt
Original file line number Diff line number Diff line change @@ -85,8 +85,50 @@ interfaces:
8585 ipv6 : { jsnac_type: ipv6_cidr }
8686` ` `
8787
88- A full list of jsnac_types is available in the documentation
88+ A full list of jsnac_types is available in the documentation (readthedocs coming soon)
8989
9090## Usage
9191
92- You can use jsnac from the command line or by importing it and calling InferSchema?
92+ ### CLI
93+
94+ ` ` ` bash
95+ # Print the help message
96+ jsnac -h
97+
98+ # Build a JSON schema from a YAML file (default file is jsnac.schema.json)
99+ jsnac -f data/example-jsnac.yml
100+
101+ # Build a JSON schema from a YAML file and save it to a custom file
102+ jsnac -f data/example-jsnac.yml -o my.schema.json
103+
104+ # Increase the verbosity of the output
105+ jsnac -f data/example-jsnac.yml -v
106+ ```
107+
108+ ### Library
109+ ``` python
110+ """
111+ This example demonstrates how to use the jsnac library to build a JSON schema from a YAML file in a Python script.
112+ Example yml file is available here: <https://www.github.com/commitconfirmed/jsnac/blob/main/data/example-jsnac.yml>
113+ """
114+ from jsnac.core.infer import SchemaInferer
115+
116+ def main ():
117+ # Create a SchemaInferer object
118+ jsnac = SchemaInferer()
119+
120+ # Load the YAML data however you like into the SchemaInferer object
121+ with open (' data/example-jsnac.yml' , ' r' ) as file :
122+ data = file .read()
123+ jsnac.add_yaml(data)
124+
125+ # Loading from JSON directly is also supported if needed
126+ # jsnac.add_json(json_data)
127+
128+ # Build the JSON schema
129+ schema = jsnac.build()
130+ print (schema)
131+
132+ if __name__ == ' __main__' :
133+ main()
134+ ```
Original file line number Diff line number Diff line change @@ -7,11 +7,10 @@ name = "jsnac"
77version = " 0.1.0"
88description = " JSON Schema (for) Network as Code: Build JSON schemas from (un)modified YAML files"
99authors = [" Andrew Jones <jsnac@commitconfirmed.com>" ]
10- license = " Apache 2.0 "
10+ license = " MIT "
1111readme = " README.md"
1212repository = " https://github.com/commitconfirmed/jsnac"
1313classifiers = [
14- " License :: OSI Approved :: Apache Software License" ,
1514 " Programming Language :: Python :: 3.10" ,
1615 " Programming Language :: Python :: 3.11" ,
1716 " Programming Language :: Python :: 3.12" ,
You can’t perform that action at this time.
0 commit comments