├── .flake8
├── .github
└── workflows
│ ├── deploy.yml
│ └── test.yaml
├── .gitignore
├── .pre-commit-config.yaml
├── LICENSE
├── README.md
├── build.sh
├── json_to_pydantic
├── __init__.py
└── static
│ ├── .nojekyll
│ ├── index.html
│ ├── js
│ └── color_modes.js
│ ├── main.py
│ └── wheels
│ └── genson-1.2.2-py2.py3-none-any.whl
├── pyproject.toml
├── requirements.txt
├── requirements_dev.txt
└── tests
├── __init__.py
└── test_json_to_pydantic.py
/.flake8:
--------------------------------------------------------------------------------
1 | [flake8]
2 | max-line-length = 88
3 | extend-ignore = E203 E501
4 | exclude = .venv
5 |
--------------------------------------------------------------------------------
/.github/workflows/deploy.yml:
--------------------------------------------------------------------------------
1 | name: Deploy
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 |
8 | jobs:
9 | deploy:
10 | runs-on: ubuntu-latest
11 |
12 | steps:
13 | - uses: actions/checkout@v3
14 |
15 | - name: Deploy 🚀
16 | uses: JamesIves/github-pages-deploy-action@v4
17 | with:
18 | folder: json_to_pydantic/static
19 |
--------------------------------------------------------------------------------
/.github/workflows/test.yaml:
--------------------------------------------------------------------------------
1 | name: Test json_to_pydantic
2 |
3 | on:
4 | push:
5 |
6 | jobs:
7 | test:
8 | runs-on: ubuntu-latest
9 | timeout-minutes: 10
10 |
11 | steps:
12 | - uses: actions/checkout@v3
13 |
14 | - name: Setup Python
15 | uses: actions/setup-python@v4
16 | with:
17 | python-version: "3.10"
18 | cache: "pip"
19 | cache-dependency-path: "**/requirements_dev.txt"
20 |
21 | - name: Install dev dependencies
22 | run: |
23 | pip install ".[dev]" -r requirements.txt -r requirements_dev.txt
24 |
25 | - name: pytest
26 | run: pytest
27 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | build/
12 | develop-eggs/
13 | dist/
14 | downloads/
15 | eggs/
16 | .eggs/
17 | lib/
18 | lib64/
19 | parts/
20 | sdist/
21 | var/
22 | wheels/
23 | share/python-wheels/
24 | *.egg-info/
25 | .installed.cfg
26 | *.egg
27 | MANIFEST
28 |
29 | # PyInstaller
30 | # Usually these files are written by a python script from a template
31 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
32 | *.manifest
33 | *.spec
34 |
35 | # Installer logs
36 | pip-log.txt
37 | pip-delete-this-directory.txt
38 |
39 | # Unit test / coverage reports
40 | htmlcov/
41 | .tox/
42 | .nox/
43 | .coverage
44 | .coverage.*
45 | .cache
46 | nosetests.xml
47 | coverage.xml
48 | *.cover
49 | *.py,cover
50 | .hypothesis/
51 | .pytest_cache/
52 | cover/
53 |
54 | # Translations
55 | *.mo
56 | *.pot
57 |
58 | # Django stuff:
59 | *.log
60 | local_settings.py
61 | db.sqlite3
62 | db.sqlite3-journal
63 |
64 | # Flask stuff:
65 | instance/
66 | .webassets-cache
67 |
68 | # Scrapy stuff:
69 | .scrapy
70 |
71 | # Sphinx documentation
72 | docs/_build/
73 |
74 | # PyBuilder
75 | .pybuilder/
76 | target/
77 |
78 | # Jupyter Notebook
79 | .ipynb_checkpoints
80 |
81 | # IPython
82 | profile_default/
83 | ipython_config.py
84 |
85 | # pyenv
86 | # For a library or package, you might want to ignore these files since the code is
87 | # intended to run in multiple environments; otherwise, check them in:
88 | # .python-version
89 |
90 | # pipenv
91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
94 | # install all needed dependencies.
95 | #Pipfile.lock
96 |
97 | # poetry
98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99 | # This is especially recommended for binary packages to ensure reproducibility, and is more
100 | # commonly ignored for libraries.
101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102 | #poetry.lock
103 |
104 | # pdm
105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106 | #pdm.lock
107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108 | # in version control.
109 | # https://pdm.fming.dev/#use-with-ide
110 | .pdm.toml
111 |
112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113 | __pypackages__/
114 |
115 | # Celery stuff
116 | celerybeat-schedule
117 | celerybeat.pid
118 |
119 | # SageMath parsed files
120 | *.sage.py
121 |
122 | # Environments
123 | .env
124 | .venv
125 | env/
126 | venv/
127 | ENV/
128 | env.bak/
129 | venv.bak/
130 |
131 | # Spyder project settings
132 | .spyderproject
133 | .spyproject
134 |
135 | # Rope project settings
136 | .ropeproject
137 |
138 | # mkdocs documentation
139 | /site
140 |
141 | # mypy
142 | .mypy_cache/
143 | .dmypy.json
144 | dmypy.json
145 |
146 | # Pyre type checker
147 | .pyre/
148 |
149 | # pytype static type analyzer
150 | .pytype/
151 |
152 | # Cython debug symbols
153 | cython_debug/
154 |
155 | # PyCharm
156 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158 | # and can be added to the global gitignore or merged into this file. For a more nuclear
159 | # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160 | #.idea/
161 |
162 | # include the static/wheels
163 | !/json_to_pydantic/static/wheels/
164 |
--------------------------------------------------------------------------------
/.pre-commit-config.yaml:
--------------------------------------------------------------------------------
1 | repos:
2 | - repo: https://github.com/pre-commit/pre-commit-hooks
3 | rev: v4.4.0
4 | hooks:
5 | - id: trailing-whitespace
6 | - id: end-of-file-fixer
7 | - id: check-yaml
8 | - id: check-added-large-files
9 | - repo: https://github.com/PyCQA/isort
10 | rev: 5.12.0
11 | hooks:
12 | - id: isort
13 | - repo: https://github.com/psf/black
14 | rev: 23.3.0
15 | hooks:
16 | - id: black
17 | - repo: https://github.com/PyCQA/flake8
18 | rev: 6.0.0
19 | hooks:
20 | - id: flake8
21 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023, Benjamin Falk
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # json-to-pydantic
2 |
3 | JSON to [pydantic](https://docs.pydantic.dev/) generator
4 |
5 | [](https://falkben.github.io/json-to-pydantic/)
6 |
7 | Page at [falkben.github.io/json-to-pydantic/](https://falkben.github.io/json-to-pydantic/)
8 |
9 | ## About
10 |
11 | Inspired by [@brokenloop's](https://github.com/brokenloop) [`jsontopydantic`](https://github.com/brokenloop/jsontopydantic), this project implements the same conversion (using [`datamodel-code-generator`](https://github.com/koxudaxi/datamodel-code-generator)), but does the conversion entirely in the browser, using [PyScript](https://pyscript.net/) & [Pyodide](https://pyodide.org/en/stable/).
12 |
13 | ## Developer Notes
14 |
15 | ### Install
16 |
17 | 1. Create virtual environment and activate:
18 |
19 | `python -m venv .venv && source .venv/bin/activate`
20 |
21 | 2. Install package
22 |
23 | `pip install -e . -r requirements.txt`
24 |
25 | Or with optional dev dependencies:
26 |
27 | `pip install -e ".[dev]" -r requirements.txt -r requirements_dev.txt`
28 |
29 | ### Dependencies
30 |
31 | Dependencies are specified in `pyproject.toml` and managed with [pip-tools](https://github.com/jazzband/pip-tools/).
32 |
33 | 1. Install `pip-tools` (globally with [pipx](https://github.com/pypa/pipx) or in local virtual environment with pip)
34 |
35 | 2. Generate lock files:
36 |
37 | ```sh
38 | pip-compile pyproject.toml --quiet && \
39 | pip-compile --extra=dev --output-file=requirements_dev.txt pyproject.toml --quiet
40 | ```
41 |
42 | To upgrade a dependency, pass the `--upgrade-package` flag along with the name of the package, or to upgrade all packages, pass the `--upgrade` flag to the command.
43 |
44 | More information at:
45 |
--------------------------------------------------------------------------------
/build.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | set -euo pipefail
4 |
5 | python -m pip install --upgrade build
6 |
7 | # genson
8 | rm -rf /tmp/GenSON
9 | git clone --depth 1 --branch v1.2.2 git@github.com:wolverdude/GenSON.git /tmp/GenSON
10 | python -m build /tmp/GenSON
11 | cp /tmp/GenSON/dist/*.whl json_to_pydantic/static/wheels
12 |
13 | # Other packages have pre-build wheels on pypi so we use those instead
14 |
--------------------------------------------------------------------------------
/json_to_pydantic/__init__.py:
--------------------------------------------------------------------------------
1 | """Top-level package for json-to-pydantic."""
2 |
3 | __version__ = "0.0.1"
4 |
--------------------------------------------------------------------------------
/json_to_pydantic/static/.nojekyll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/falkben/json-to-pydantic/29dd52025b56e83a322dd50a2eb0df3c4be7d7d9/json_to_pydantic/static/.nojekyll
--------------------------------------------------------------------------------
/json_to_pydantic/static/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
14 |
19 |
20 |
21 |
26 |
27 |
28 |
29 |
30 |
34 |
35 |
36 |
37 |
38 |
39 |
40 | packages = [
41 | "pyyaml",
42 | "Jinja2",
43 | "pydantic",
44 | "https://files.pythonhosted.org/packages/ad/e7/4642b7f462381799393fbad894ba4b32db00870a797f0616c197b07129a9/black-23.3.0-py3-none-any.whl",
45 | "https://files.pythonhosted.org/packages/35/f0/f3f36d0a87d4f2e3ceb9ba273cac9ad6fb0924f078e51c94803f10b55dbf/PySnooper-1.1.1-py2.py3-none-any.whl",
46 | "https://files.pythonhosted.org/packages/0a/63/4036ae70eea279c63e2304b91ee0ac182f467f24f86394ecfe726092340b/isort-5.12.0-py3-none-any.whl",
47 | "https://files.pythonhosted.org/packages/44/6f/7120676b6d73228c96e17f1f794d8ab046fc910d781c8d151120c3f1569e/toml-0.10.2-py2.py3-none-any.whl",
48 | "https://files.pythonhosted.org/packages/df/d8/3e1a32d305215166f5c32652c473aa766bd7809cd10b34c544dbc31facb5/inflect-5.6.2-py3-none-any.whl",
49 | "wheels/genson-1.2.2-py2.py3-none-any.whl",
50 | ]
51 |
52 | terminal=false
53 |
54 |
55 |
56 |
57 |
58 |
59 |
62 |
74 |
75 |
76 |
77 |
78 |
90 |
91 |
92 |
93 | JSON to Pydantic
94 |
95 |
96 | Enter JSON to convert to a
97 | pydantic model!
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
129 |
130 |
131 |
132 |
161 |
162 |
179 |
180 |
181 |
187 |
188 |
189 |
190 |
--------------------------------------------------------------------------------
/json_to_pydantic/static/js/color_modes.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Light Switch @version v0.1.4
3 | */
4 |
5 | (function () {
6 | let lightSwitch = document.getElementById("lightSwitch");
7 | if (!lightSwitch) {
8 | return;
9 | }
10 |
11 | /**
12 | * @function darkmode
13 | * @summary: changes the theme to 'dark mode' and save settings to local stroage.
14 | * Basically, replaces/toggles every CSS class that has '-light' class with '-dark'
15 | */
16 | function darkMode() {
17 | // sets the attribute: data-bs-theme
18 | document.documentElement.setAttribute("data-bs-theme", "dark");
19 |
20 | // sets the head element href that styles the code-input
21 | document
22 | .querySelector("#import-theme")
23 | .setAttribute(
24 | "href",
25 | "https://cdnjs.cloudflare.com/ajax/libs/prism/1.23.0/themes/prism-tomorrow.css"
26 | );
27 |
28 | if (!lightSwitch.checked) {
29 | lightSwitch.checked = true;
30 | }
31 | localStorage.setItem("lightSwitch", "dark");
32 | }
33 |
34 | /**
35 | * @function lightmode
36 | * @summary: changes the theme to 'light mode' and save settings to local stroage.
37 | */
38 | function lightMode() {
39 | // sets the attribute: data-bs-theme
40 | document.documentElement.setAttribute("data-bs-theme", "light");
41 |
42 | // sets the head element href that styles the code-input
43 | document
44 | .querySelector("#import-theme")
45 | .setAttribute(
46 | "href",
47 | "https://cdnjs.cloudflare.com/ajax/libs/prism/1.23.0/themes/prism.css"
48 | );
49 |
50 | if (lightSwitch.checked) {
51 | lightSwitch.checked = false;
52 | }
53 | localStorage.setItem("lightSwitch", "light");
54 | }
55 |
56 | /**
57 | * @function onToggleMode
58 | * @summary: the event handler attached to the switch. calling @darkMode or @lightMode depending on the checked state.
59 | */
60 | function onToggleMode() {
61 | if (lightSwitch.checked) {
62 | darkMode();
63 | } else {
64 | lightMode();
65 | }
66 | }
67 |
68 | /**
69 | * @function getSystemDefaultTheme
70 | * @summary: get system default theme by media query
71 | */
72 | function getSystemDefaultTheme() {
73 | const darkThemeMq = window.matchMedia("(prefers-color-scheme: dark)");
74 | if (darkThemeMq.matches) {
75 | return "dark";
76 | }
77 | return "light";
78 | }
79 |
80 | function setup() {
81 | var settings = localStorage.getItem("lightSwitch");
82 | if (settings == null) {
83 | settings = getSystemDefaultTheme();
84 | }
85 |
86 | if (settings == "dark") {
87 | lightSwitch.checked = true;
88 | }
89 |
90 | lightSwitch.addEventListener("change", onToggleMode);
91 | onToggleMode();
92 | }
93 |
94 | setup();
95 | })();
96 |
--------------------------------------------------------------------------------
/json_to_pydantic/static/main.py:
--------------------------------------------------------------------------------
1 | import asyncio
2 | import json
3 |
4 | import micropip
5 |
6 |
7 | def convert_to_schema(input_text: str, all_optional: bool, snake_case_field: bool):
8 | from datamodel_code_generator.parser.jsonschema import JsonSchemaParser
9 | from genson import SchemaBuilder
10 |
11 | builder = SchemaBuilder()
12 | input = json.loads(input_text)
13 | builder.add_object(input)
14 | schema = builder.to_schema()
15 | if all_optional:
16 | schema["required"] = []
17 |
18 | parser = JsonSchemaParser(
19 | source=json.dumps(schema),
20 | base_class="pydantic.BaseModel",
21 | snake_case_field=snake_case_field,
22 | )
23 |
24 | return parser.parse()
25 |
26 |
27 | def convert():
28 | from js import document
29 |
30 | # todo: set button to disabled and show loading spinner
31 |
32 | input_text = document.querySelector("#json-ta").value
33 |
34 | all_optional = document.querySelector("#all_optional_checkbox").checked
35 |
36 | snake_case_field = document.querySelector("#snake_case_field_checkbox").checked
37 |
38 | try:
39 | model = convert_to_schema(input_text, all_optional, snake_case_field)
40 | except Exception as e:
41 | print(e)
42 | return None
43 |
44 | document.querySelector("#pydantic-ta").value = model
45 |
46 | return model
47 |
48 |
49 | async def load_deps():
50 | # install without deps using micropip to avoid several deps
51 | await micropip.install(
52 | "https://files.pythonhosted.org/packages/a3/44/bd5baa652b4d57853fc71c45bc0d25e1e28c92c54fcc6da07510fdd31ed7/datamodel_code_generator-0.21.1-py3-none-any.whl",
53 | deps=False,
54 | )
55 |
56 |
57 | async def setup():
58 | await load_deps()
59 | convert()
60 |
61 |
62 | if __name__ == "__main__":
63 | asyncio.create_task(setup())
64 |
--------------------------------------------------------------------------------
/json_to_pydantic/static/wheels/genson-1.2.2-py2.py3-none-any.whl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/falkben/json-to-pydantic/29dd52025b56e83a322dd50a2eb0df3c4be7d7d9/json_to_pydantic/static/wheels/genson-1.2.2-py2.py3-none-any.whl
--------------------------------------------------------------------------------
/pyproject.toml:
--------------------------------------------------------------------------------
1 | [build-system]
2 | requires = ["hatchling"]
3 | build-backend = "hatchling.build"
4 |
5 | [project]
6 | name = "json_to_pydantic"
7 | version = "0.0.1"
8 | authors = [
9 | { name="Benjamin Falk", email="falk.ben@gmail.com" },
10 | ]
11 | description = "JSON to pydantic generator"
12 | readme = "README.md"
13 | requires-python = ">=3.10"
14 | classifiers = [
15 | "Programming Language :: Python :: 3",
16 | "License :: OSI Approved :: MIT License",
17 | "Operating System :: OS Independent",
18 | ]
19 | dependencies = [
20 | "datamodel-code-generator",
21 | "pyodide-build",
22 | "micropip",
23 | "build",
24 | "genson",
25 | ]
26 |
27 | [project.optional-dependencies]
28 | dev = [
29 | "pytest",
30 | ]
31 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | #
2 | # This file is autogenerated by pip-compile with Python 3.10
3 | # by the following command:
4 | #
5 | # pip-compile pyproject.toml
6 | #
7 | argcomplete==2.0.0
8 | # via datamodel-code-generator
9 | attrs==22.2.0
10 | # via
11 | # jsonschema
12 | # openapi-schema-validator
13 | auditwheel-emscripten==0.0.9
14 | # via pyodide-build
15 | black==22.12.0
16 | # via datamodel-code-generator
17 | build==0.7.0
18 | # via
19 | # json_to_pydantic (pyproject.toml)
20 | # pyodide-build
21 | certifi==2022.12.7
22 | # via requests
23 | chardet==4.0.0
24 | # via prance
25 | charset-normalizer==3.0.1
26 | # via requests
27 | click==8.1.3
28 | # via
29 | # black
30 | # typer
31 | cmake==3.25.0
32 | # via pyodide-build
33 | colorama==0.4.6
34 | # via typer
35 | commonmark==0.9.1
36 | # via rich
37 | cython==0.29.33
38 | # via pyodide-build
39 | datamodel-code-generator==0.16.0
40 | # via json_to_pydantic (pyproject.toml)
41 | distlib==0.3.6
42 | # via virtualenv
43 | dnspython==2.3.0
44 | # via email-validator
45 | email-validator==1.3.0
46 | # via pydantic
47 | filelock==3.9.0
48 | # via virtualenv
49 | genson==1.2.2
50 | # via
51 | # datamodel-code-generator
52 | # json_to_pydantic (pyproject.toml)
53 | idna==3.4
54 | # via
55 | # email-validator
56 | # requests
57 | importlib-resources==5.10.2
58 | # via openapi-spec-validator
59 | inflect==5.6.2
60 | # via datamodel-code-generator
61 | isort==5.11.4
62 | # via datamodel-code-generator
63 | jinja2==3.1.2
64 | # via datamodel-code-generator
65 | jsonschema==4.17.3
66 | # via
67 | # jsonschema-spec
68 | # openapi-schema-validator
69 | # openapi-spec-validator
70 | jsonschema-spec==0.1.2
71 | # via openapi-spec-validator
72 | lazy-object-proxy==1.9.0
73 | # via openapi-spec-validator
74 | leb128==1.0.4
75 | # via auditwheel-emscripten
76 | markupsafe==2.1.2
77 | # via jinja2
78 | micropip==0.2.0
79 | # via json_to_pydantic (pyproject.toml)
80 | mypy-extensions==0.4.3
81 | # via black
82 | openapi-schema-validator==0.3.4
83 | # via openapi-spec-validator
84 | openapi-spec-validator==0.5.1
85 | # via datamodel-code-generator
86 | packaging==21.3
87 | # via
88 | # auditwheel-emscripten
89 | # build
90 | # datamodel-code-generator
91 | # micropip
92 | # prance
93 | # pyodide-build
94 | # unearth
95 | pathable==0.4.3
96 | # via jsonschema-spec
97 | pathspec==0.10.3
98 | # via black
99 | pep517==0.13.0
100 | # via build
101 | platformdirs==2.6.2
102 | # via
103 | # black
104 | # virtualenv
105 | prance==0.22.11.4.0
106 | # via datamodel-code-generator
107 | pydantic[email]==1.10.4
108 | # via
109 | # datamodel-code-generator
110 | # pyodide-build
111 | pygments==2.14.0
112 | # via rich
113 | pyodide-build==0.22.0
114 | # via json_to_pydantic (pyproject.toml)
115 | pyodide-cli==0.2.2
116 | # via
117 | # auditwheel-emscripten
118 | # pyodide-build
119 | pyparsing==3.0.9
120 | # via packaging
121 | pyrsistent==0.19.3
122 | # via jsonschema
123 | pysnooper==1.1.1
124 | # via datamodel-code-generator
125 | pyyaml==6.0
126 | # via
127 | # jsonschema-spec
128 | # openapi-spec-validator
129 | # pyodide-build
130 | requests==2.28.2
131 | # via
132 | # prance
133 | # pyodide-build
134 | # unearth
135 | rich==12.6.0
136 | # via pyodide-cli
137 | ruamel-yaml==0.17.21
138 | # via
139 | # prance
140 | # pyodide-build
141 | ruamel-yaml-clib==0.2.7
142 | # via ruamel-yaml
143 | semver==2.13.0
144 | # via prance
145 | shellingham==1.5.0.post1
146 | # via typer
147 | six==1.16.0
148 | # via prance
149 | toml==0.10.2
150 | # via datamodel-code-generator
151 | tomli==2.0.1
152 | # via
153 | # black
154 | # build
155 | # pep517
156 | # pyodide-build
157 | typed-ast==1.5.4
158 | # via datamodel-code-generator
159 | typer[all]==0.4.2
160 | # via
161 | # auditwheel-emscripten
162 | # pyodide-build
163 | # pyodide-cli
164 | types-requests==2.28.11.8
165 | # via pyodide-build
166 | types-urllib3==1.26.25.4
167 | # via types-requests
168 | typing-extensions==4.4.0
169 | # via
170 | # jsonschema-spec
171 | # pydantic
172 | unearth==0.7.2
173 | # via pyodide-build
174 | urllib3==1.26.14
175 | # via requests
176 | virtualenv==20.17.1
177 | # via pyodide-build
178 | wheel==0.38.4
179 | # via
180 | # auditwheel-emscripten
181 | # pyodide-build
182 |
--------------------------------------------------------------------------------
/requirements_dev.txt:
--------------------------------------------------------------------------------
1 | #
2 | # This file is autogenerated by pip-compile with Python 3.10
3 | # by the following command:
4 | #
5 | # pip-compile --extra=dev --output-file=requirements_dev.txt pyproject.toml
6 | #
7 | argcomplete==2.0.0
8 | # via datamodel-code-generator
9 | attrs==22.2.0
10 | # via
11 | # jsonschema
12 | # openapi-schema-validator
13 | # pytest
14 | auditwheel-emscripten==0.0.9
15 | # via pyodide-build
16 | black==22.12.0
17 | # via datamodel-code-generator
18 | build==0.7.0
19 | # via
20 | # json_to_pydantic (pyproject.toml)
21 | # pyodide-build
22 | certifi==2022.12.7
23 | # via requests
24 | chardet==4.0.0
25 | # via prance
26 | charset-normalizer==3.0.1
27 | # via requests
28 | click==8.1.3
29 | # via
30 | # black
31 | # typer
32 | cmake==3.25.0
33 | # via pyodide-build
34 | colorama==0.4.6
35 | # via typer
36 | commonmark==0.9.1
37 | # via rich
38 | cython==0.29.33
39 | # via pyodide-build
40 | datamodel-code-generator==0.16.0
41 | # via json_to_pydantic (pyproject.toml)
42 | distlib==0.3.6
43 | # via virtualenv
44 | dnspython==2.3.0
45 | # via email-validator
46 | email-validator==1.3.0
47 | # via pydantic
48 | exceptiongroup==1.1.0
49 | # via pytest
50 | filelock==3.9.0
51 | # via virtualenv
52 | genson==1.2.2
53 | # via
54 | # datamodel-code-generator
55 | # json_to_pydantic (pyproject.toml)
56 | idna==3.4
57 | # via
58 | # email-validator
59 | # requests
60 | importlib-resources==5.10.2
61 | # via openapi-spec-validator
62 | inflect==5.6.2
63 | # via datamodel-code-generator
64 | iniconfig==2.0.0
65 | # via pytest
66 | isort==5.11.4
67 | # via datamodel-code-generator
68 | jinja2==3.1.2
69 | # via datamodel-code-generator
70 | jsonschema==4.17.3
71 | # via
72 | # jsonschema-spec
73 | # openapi-schema-validator
74 | # openapi-spec-validator
75 | jsonschema-spec==0.1.2
76 | # via openapi-spec-validator
77 | lazy-object-proxy==1.9.0
78 | # via openapi-spec-validator
79 | leb128==1.0.4
80 | # via auditwheel-emscripten
81 | markupsafe==2.1.2
82 | # via jinja2
83 | micropip==0.2.0
84 | # via json_to_pydantic (pyproject.toml)
85 | mypy-extensions==0.4.3
86 | # via black
87 | openapi-schema-validator==0.3.4
88 | # via openapi-spec-validator
89 | openapi-spec-validator==0.5.1
90 | # via datamodel-code-generator
91 | packaging==21.3
92 | # via
93 | # auditwheel-emscripten
94 | # build
95 | # datamodel-code-generator
96 | # micropip
97 | # prance
98 | # pyodide-build
99 | # pytest
100 | # unearth
101 | pathable==0.4.3
102 | # via jsonschema-spec
103 | pathspec==0.10.3
104 | # via black
105 | pep517==0.13.0
106 | # via build
107 | platformdirs==2.6.2
108 | # via
109 | # black
110 | # virtualenv
111 | pluggy==1.0.0
112 | # via pytest
113 | prance==0.22.11.4.0
114 | # via datamodel-code-generator
115 | pydantic[email]==1.10.4
116 | # via
117 | # datamodel-code-generator
118 | # pyodide-build
119 | pygments==2.14.0
120 | # via rich
121 | pyodide-build==0.22.0
122 | # via json_to_pydantic (pyproject.toml)
123 | pyodide-cli==0.2.2
124 | # via
125 | # auditwheel-emscripten
126 | # pyodide-build
127 | pyparsing==3.0.9
128 | # via packaging
129 | pyrsistent==0.19.3
130 | # via jsonschema
131 | pysnooper==1.1.1
132 | # via datamodel-code-generator
133 | pytest==7.2.1
134 | # via json_to_pydantic (pyproject.toml)
135 | pyyaml==6.0
136 | # via
137 | # jsonschema-spec
138 | # openapi-spec-validator
139 | # pyodide-build
140 | requests==2.28.2
141 | # via
142 | # prance
143 | # pyodide-build
144 | # unearth
145 | rich==12.6.0
146 | # via pyodide-cli
147 | ruamel-yaml==0.17.21
148 | # via
149 | # prance
150 | # pyodide-build
151 | ruamel-yaml-clib==0.2.7
152 | # via ruamel-yaml
153 | semver==2.13.0
154 | # via prance
155 | shellingham==1.5.0.post1
156 | # via typer
157 | six==1.16.0
158 | # via prance
159 | toml==0.10.2
160 | # via datamodel-code-generator
161 | tomli==2.0.1
162 | # via
163 | # black
164 | # build
165 | # pep517
166 | # pyodide-build
167 | # pytest
168 | typed-ast==1.5.4
169 | # via datamodel-code-generator
170 | typer[all]==0.4.2
171 | # via
172 | # auditwheel-emscripten
173 | # pyodide-build
174 | # pyodide-cli
175 | types-requests==2.28.11.8
176 | # via pyodide-build
177 | types-urllib3==1.26.25.4
178 | # via types-requests
179 | typing-extensions==4.4.0
180 | # via
181 | # jsonschema-spec
182 | # pydantic
183 | unearth==0.7.2
184 | # via pyodide-build
185 | urllib3==1.26.14
186 | # via requests
187 | virtualenv==20.17.1
188 | # via pyodide-build
189 | wheel==0.38.4
190 | # via
191 | # auditwheel-emscripten
192 | # pyodide-build
193 |
--------------------------------------------------------------------------------
/tests/__init__.py:
--------------------------------------------------------------------------------
1 | """Unit test package for json_to_pydantic."""
2 |
--------------------------------------------------------------------------------
/tests/test_json_to_pydantic.py:
--------------------------------------------------------------------------------
1 | """Tests for `json_to_pydantic` package."""
2 |
3 | from json_to_pydantic.static import main
4 |
5 |
6 | def test_convert():
7 | simple = """{
8 | "a": "b",
9 | "c": 123
10 | }"""
11 | result = main.convert_to_schema(simple, False, False)
12 | print(result)
13 |
--------------------------------------------------------------------------------