sbrunner / jsonschema-gentypes Goto Github PK
View Code? Open in Web Editor NEWTool to generate Python types based on TypedDict from a JSON Schema
License: BSD 2-Clause "Simplified" License
Tool to generate Python types based on TypedDict from a JSON Schema
License: BSD 2-Clause "Simplified" License
The list of imports are collected in a set()
(I believe) and so their ordering is not stable. We should either sort them when emitting code or use a stable method of making them unique (e.g. a dict()
). Having the code change every time it is regenerated makes for undesirable diff churn when generated code is checked into a repo and regularly regenerated as part of automated tooling.
All typeddicts do not contain any jsonschema description.
There seems to be a pretty serious confusion as to whether jsonschema_gentypes.Type
is supposed to contain description
property or whether _comments
is supposed to be used.
Actually, the required
is not taken in account.
In Version 3.10 of Python it can be better, see: https://www.python.org/dev/peps/pep-0655/
Note that the workaround doesn't work when we specify the structure in a dict, and the dict is required to thread with the special char.
The README.md example shows python_version
as being set inside the generate
array items, but the way the code's written, it's currently only read from the toplevel.
When setting the root_name
in the generation config, sub types of the root still get the original root name as their prefix. I would expect the prefixes of the sub types to match the provided root_name
.
Example:
{
"title": "MyObject",
"type": "object",
"required": ["child"],
"properties": {
"child": {
"type": "object",
"properties": {
"foo": {"type": "string"},
}
}
}
}
If we set the root_name
to CustomRootName
the generated code looks like this:
from typing import TypedDict
from typing_extensions import Required
class CustomRootName(TypedDict, total=False):
""" MyObject. """
child: Required["_MyobjectChild"]
""" Required property """
class _MyobjectChild(TypedDict, total=False):
foo: str
I was able to hack in a fix by adding this:
if "root_name" in gen:
schema_all["title"] = gen["root_name"]
Right before calling add_type
on this line:
Then the resulting code looks as expected:
from typing import TypedDict
from typing_extensions import Required
class CustomRootName(TypedDict, total=False):
""" CustomRootName. """
child: Required["_CustomRootNameChild"]
""" Required property """
class _CustomRootNameChild(TypedDict, total=False):
foo: str
{"properties": {"foo": {"type": "string"}}, "required": "foo"}
is recognized by json schema validators as being a JSON object, but jsonschema-gentypes converts that into Any
I cannot find any indication in the spec as to why type
can be omitted. Perhaps it is an artifact of older specs?
If you have an enum with duplicate-when-case-folded elements, the generated variables will collide.
Min Repro:
$ cat in.json
{"enum":["a","A"]}
$ jsonschema-gentypes --json-schema=in.json --python=out.py
Processing in.json
$ cat out.py
from typing import Literal, Union
_Root = Union[Literal['a'], Literal['A']]
_ROOT_A: Literal['a'] = "a"
"""The values for the '_Root' enum"""
_ROOT_A: Literal['A'] = "A"
"""The values for the '_Root' enum"""
I get a recursion error. See error and json recursion_error.zip
List of all tags that actually not listed in another limitation issue and is not take in account in the types (a comment is added)
default
readOnly
writeOnly
multipleOf
maximum
exclusiveMaximum
minimum
exclusiveMinimum
maxLength
minLength
pattern
maxItems
minItems
uniqueItems
contains
maxProperties
minProperties
patternProperties
dependencies
propertyNames
format
contentMediaType
contentEncoding
not
oneOf
: thread as Union
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates are awaiting their schedule. Click on a checkbox to get an update now.
asdf
.tool-versions
python 3.8.19
dockerfile
Dockerfile
ubuntu 22.04
github-actions
.github/workflows/backport.yaml
ubuntu 22.04
.github/workflows/clean.yaml
actions/checkout v3
ubuntu 22.04
.github/workflows/main.yaml
actions/checkout v3
actions/upload-artifact v4
ubuntu 22.04
.github/workflows/pull-request-automation.yaml
actions/github-script v7
actions/github-script v7
actions/github-script v6
ubuntu 22.04
pep621
pyproject.toml
poetry-core >=1.0.0
pip_requirements
ci/requirements.txt
c2cciutils ==1.2.18
ruamel.yaml <0.18.0
setuptools >=65.5.1
cryptography >=42.0.8
pyopenssl >=22.1.0
requests >=2.32.2
urllib3 >=1.26.19
requirements.txt
poetry ==1.6.1
poetry-core >=1.1.0a7
cryptography >=42.0.8
requests >=2.32.2
urllib3 >=1.26.19
poetry
pyproject.toml
python >=3.8,<4
jsonschema 4.6.2
requests 2.32.3
ruamel.yaml 0.17.40
PyYAML 6.0.1
pyupgrade 2.37.3
black 24.3.0
isort 5.10.1
pinyin 0.4.0
romkan 0.2.1
romanize 1.0.2
certifi 2023.7.22
urllib3 1.26.19
idna 3.7
prospector 1.7.7
pylint 2.14.5
mypy 0.961
flake8 4.0.1
pytest 7.1.3
pytest-cov 3.0.0
types-requests 2.28.11.17
pre-commit
.pre-commit-config.yaml
pre-commit/mirrors-prettier v2.7.1
pyenv
.python-version
python 3.8
regex
.pre-commit-config.yaml
prettier 2.8.8
ci/config.yaml
camptocamp/c2cciutils 1.2.18
asdf
.tool-versions
python 3.8.19
dockerfile
Dockerfile
ubuntu 22.04
github-actions
.github/workflows/backport.yaml
ubuntu 22.04
.github/workflows/clean.yaml
actions/checkout v3
ubuntu 22.04
.github/workflows/main.yaml
actions/checkout v3
actions/upload-artifact v4
ubuntu 22.04
.github/workflows/pull-request-automation.yaml
actions/github-script v7
actions/github-script v7
actions/github-script v6
ubuntu 22.04
pep621
pyproject.toml
poetry-core >=1.0.0
pip_requirements
ci/requirements.txt
c2cciutils ==1.2.18
ruamel.yaml ==0.17.40
setuptools >=65.5.1
pip ==23.3.2
protobuf >=3.18.3
certifi >=2022.12.7
cryptography >=42.0.8
requests >=2.32.2
requirements.txt
poetry ==1.6.1
cryptography >=42.0.8
requests >=2.32.2
poetry
pyproject.toml
python >=3.8,<4
jsonschema 4.9.1
requests 2.32.3
ruamel.yaml 0.17.40
PyYAML 6.0.1
pyupgrade 2.37.3
black 24.3.0
isort 5.10.1
pinyin 0.4.0
romkan 0.2.1
romanize 1.0.2
certifi 2023.7.22
urllib3 1.26.19
idna 3.7
prospector 1.7.7
pytest 7.1.3
pytest-cov 3.0.0
types-requests 2.28.11.17
pre-commit
.pre-commit-config.yaml
pre-commit/mirrors-prettier v2.7.1
pyenv
.python-version
python 3.8
regex
.pre-commit-config.yaml
prettier 2.8.8
ci/config.yaml
camptocamp/c2cciutils 1.2.18
dockerfile
Dockerfile
ubuntu 22.04
github-actions
.github/workflows/backport.yaml
ubuntu 22.04
.github/workflows/clean.yaml
actions/checkout v3
ubuntu 22.04
.github/workflows/main.yaml
actions/checkout v3
actions/upload-artifact v4
ubuntu 22.04
.github/workflows/pull-request-automation.yaml
actions/github-script v7
actions/github-script v7
actions/github-script v6
ubuntu 22.04
pep621
pyproject.toml
poetry-core >=1.0.0
pip_requirements
ci/requirements.txt
c2cciutils ==1.4.16
setuptools >=65.5.1
certifi >=2022.12.7
cryptography >=41.0.0
requirements.txt
poetry ==1.6.1
poetry-core ==1.7.0
pip ==23.3.2
cryptography >=41.0.0
poetry
pyproject.toml
python >=3.8,<4
jsonschema 4.15.0
requests 2.32.3
ruamel.yaml 0.17.40
PyYAML 6.0.1
pyupgrade 3.0.0
black 24.3.0
isort 5.10.1
pinyin 0.4.0
romkan 0.2.1
romanize 1.0.2
certifi 2023.7.22
urllib3 1.26.19
idna 3.7
prospector 1.7.7
pytest 7.1.3
pytest-cov 4.0.0
types-requests 2.28.11.17
types-pyyaml 6.0.12.20240311
pre-commit
.pre-commit-config.yaml
pre-commit/mirrors-prettier v2.7.1
regex
ci/config.yaml
camptocamp/c2cciutils 1.4.16
dockerfile
Dockerfile
ubuntu 22.04
github-actions
.github/workflows/backport.yaml
ubuntu 22.04
.github/workflows/clean.yaml
actions/checkout v3
ubuntu 22.04
.github/workflows/main.yaml
actions/checkout v3
actions/upload-artifact v4
ubuntu 22.04
.github/workflows/pull-request-automation.yaml
actions/github-script v7
actions/github-script v7
actions/github-script v6
ubuntu 22.04
pep621
pyproject.toml
poetry-core >=1.0.0
pip_requirements
ci/requirements.txt
c2cciutils ==1.5.10
requirements.txt
poetry ==1.6.1
pip ==23.3.2
poetry
pyproject.toml
python >=3.8,<4
jsonschema 4.17.3
typing-extensions 4.5.0
requests 2.32.3
ruamel.yaml 0.17.40
pyupgrade 3.3.2
black 24.3.0
isort 5.12.0
pinyin 0.4.0
romkan 0.2.1
romanize 1.0.2
certifi 2023.7.22
urllib3 1.26.19
idna 3.7
prospector 1.9.0
pytest 7.2.2
pytest-cov 4.0.0
types-requests 2.28.11.17
types-pyyaml 6.0.12.20240311
pre-commit
.pre-commit-config.yaml
pre-commit/mirrors-prettier v2.7.1
regex
.pre-commit-config.yaml
ruamel.yaml 0.17.40
jsonschema 4.17.3
typing-extensions 4.5.0
prettier 2.8.8
ci/config.yaml
camptocamp/c2cciutils 1.5.10
dockerfile
Dockerfile
ubuntu 22.04
github-actions
.github/workflows/backport.yaml
ubuntu 22.04
.github/workflows/clean.yaml
actions/checkout v3
ubuntu 22.04
.github/workflows/main.yaml
actions/checkout v3
actions/cache v3
actions/upload-artifact v4
actions/upload-artifact v4
ubuntu 22.04
.github/workflows/pull-request-automation.yaml
actions/github-script v7
actions/github-script v7
actions/github-script v6
ubuntu 22.04
pep621
pyproject.toml
poetry-core >=1.0.0
pip_requirements
ci/requirements.txt
c2cciutils ==1.5.10
pre-commit ==3.2.2
setuptools >=65.5.1
requirements.txt
poetry ==1.6.1
pip ==23.3.2
poetry
pyproject.toml
python >=3.8,<4
jsonschema 4.17.3
typing-extensions 4.5.0
requests 2.32.3
ruamel.yaml 0.17.40
pinyin 0.4.0
romkan 0.2.1
romanize 1.0.2
pre-commit 3.2.2
certifi 2023.7.22
urllib3 1.26.19
idna 3.7
prospector 1.9.0
pytest 7.2.2
pytest-cov 4.0.0
types-requests 2.28.11.17
types-pyyaml 6.0.12.20240311
pre-commit
.pre-commit-config.yaml
pre-commit/mirrors-prettier v2.7.1
pre-commit/pre-commit-hooks v4.4.0
sbrunner/hooks 0.5.0
codespell-project/codespell v2.2.6
shellcheck-py/shellcheck-py v0.9.0.6
jumanjihouse/pre-commit-hooks 3.0.0
python-jsonschema/check-jsonschema 0.22.0
sirwart/ripsecrets v0.1.8
PyCQA/autoflake v2.0.2
asottile/pyupgrade v3.3.2
PyCQA/isort 5.12.0
psf/black 23.3.0
PyCQA/prospector v1.9.0
regex
.pre-commit-config.yaml
pre-commit 3.2.2
poetry 1.6.1
poetry 1.6.1
pyjson5 1.6.6
ci/config.yaml
camptocamp/c2cciutils 1.5.10
dockerfile
Dockerfile
ubuntu 22.04
github-actions
.github/workflows/backport.yaml
ubuntu 22.04
.github/workflows/clean.yaml
actions/checkout v3
ubuntu 22.04
.github/workflows/main.yaml
actions/checkout v3
actions/cache v3
actions/upload-artifact v4
actions/upload-artifact v4
ubuntu 22.04
.github/workflows/pull-request-automation.yaml
actions/github-script v7
actions/github-script v7
actions/github-script v6
ubuntu 22.04
pep621
pyproject.toml
poetry-core >=1.0.0
pip_requirements
ci/requirements.txt
c2cciutils ==1.5.10
pre-commit ==3.2.2
setuptools >=65.5.1
requirements.txt
poetry ==1.6.1
pip ==23.3.2
poetry
pyproject.toml
python >=3.8,<4
jsonschema 4.17.3
typing-extensions 4.5.0
requests 2.32.3
ruamel.yaml 0.17.40
pinyin 0.4.0
romkan 0.2.1
romanize 1.0.2
pre-commit 3.2.2
certifi 2023.7.22
urllib3 1.26.19
idna 3.7
prospector 1.9.0
pytest 7.2.2
pytest-cov 4.0.0
types-requests 2.28.11.17
types-pyyaml 6.0.12.20240311
pre-commit
.pre-commit-config.yaml
pre-commit/mirrors-prettier v2.7.1
pre-commit/pre-commit-hooks v4.4.0
sbrunner/hooks 0.5.0
codespell-project/codespell v2.2.6
shellcheck-py/shellcheck-py v0.9.0.6
jumanjihouse/pre-commit-hooks 3.0.0
python-jsonschema/check-jsonschema 0.22.0
sirwart/ripsecrets v0.1.8
PyCQA/autoflake v2.0.2
asottile/pyupgrade v3.3.2
PyCQA/isort 5.12.0
psf/black 23.3.0
PyCQA/prospector v1.9.0
regex
.pre-commit-config.yaml
pre-commit 3.2.2
poetry 1.6.1
poetry 1.6.1
pyjson5 1.6.6
ci/config.yaml
camptocamp/c2cciutils 1.5.10
github-actions
.github/workflows/backport.yaml
ubuntu 22.04
.github/workflows/main.yaml
actions/checkout v3
actions/cache v3
actions/upload-artifact v4
actions/upload-artifact v4
ubuntu 22.04
.github/workflows/pull-request-automation.yaml
actions/github-script v7
actions/github-script v7
actions/github-script v6
ubuntu 22.04
pep621
pyproject.toml
poetry-core >=1.0.0
pip_requirements
ci/requirements.txt
c2cciutils ==1.5.10
pre-commit ==3.2.2
setuptools >=65.5.1
requirements.txt
poetry ==1.6.1
pip ==23.3.2
poetry
pyproject.toml
python >=3.8,<4
jsonschema 4.17.3
typing-extensions 4.5.0
requests 2.32.3
PyYAML 6.0.1
pinyin 0.4.0
romkan 0.2.1
romanize 1.0.2
pre-commit 3.2.2
referencing 0.27.4
certifi 2023.7.22
urllib3 1.26.19
idna 3.7
prospector 1.9.0
pytest 7.2.2
pytest-cov 4.0.0
types-requests 2.28.11.17
types-pyyaml 6.0.12.20240311
pre-commit
.pre-commit-config.yaml
pre-commit/mirrors-prettier v2.7.1
pre-commit/pre-commit-hooks v4.4.0
sbrunner/hooks 0.5.0
codespell-project/codespell v2.2.6
shellcheck-py/shellcheck-py v0.9.0.6
jumanjihouse/pre-commit-hooks 3.0.0
python-jsonschema/check-jsonschema 0.22.0
sirwart/ripsecrets v0.1.8
PyCQA/autoflake v2.0.2
asottile/pyupgrade v3.3.2
PyCQA/isort 5.12.0
psf/black 23.3.0
PyCQA/prospector v1.9.0
sbrunner/jsonschema-validator 0.1.0
regex
.pre-commit-config.yaml
pre-commit 3.2.2
poetry 1.6.1
poetry 1.6.1
pyjson5 1.6.6
ci/config.yaml
camptocamp/c2cciutils 1.5.10
github-actions
.github/workflows/backport.yaml
ubuntu 22.04
.github/workflows/main.yaml
actions/checkout v3
actions/cache v3
actions/upload-artifact v4
actions/upload-artifact v4
ubuntu 22.04
.github/workflows/pull-request-automation.yaml
actions/github-script v7
actions/github-script v7
actions/github-script v6
ubuntu 22.04
pep621
pyproject.toml
poetry-core >=1.0.0
pip_requirements
ci/requirements.txt
c2cciutils ==1.5.10
pre-commit ==3.2.2
requirements.txt
poetry ==1.6.1
pip ==23.3.2
poetry
pyproject.toml
python >=3.8,<4
jsonschema 4.17.3
typing-extensions 4.5.0
requests 2.32.3
PyYAML 6.0.1
pinyin 0.4.0
romkan 0.2.1
romanize 1.0.2
pre-commit 3.2.2
referencing 0.27.4
certifi 2023.7.22
urllib3 1.26.19
idna 3.7
prospector 1.9.0
pytest 7.2.2
pytest-cov 4.0.0
types-requests 2.28.11.17
types-pyyaml 6.0.12.20240311
pre-commit
.pre-commit-config.yaml
pre-commit/mirrors-prettier v2.7.1
pre-commit/pre-commit-hooks v4.4.0
sbrunner/hooks 0.5.0
codespell-project/codespell v2.2.6
shellcheck-py/shellcheck-py v0.9.0.6
jumanjihouse/pre-commit-hooks 3.0.0
python-jsonschema/check-jsonschema 0.22.0
sirwart/ripsecrets v0.1.8
PyCQA/autoflake v2.0.2
asottile/pyupgrade v3.3.2
PyCQA/isort 5.12.0
psf/black 23.3.0
PyCQA/prospector v1.9.0
sbrunner/jsonschema-validator 0.1.0
regex
.pre-commit-config.yaml
pre-commit 3.2.2
prettier 2.8.8
poetry 1.6.1
poetry 1.6.1
pyjson5 1.6.6
ci/config.yaml
camptocamp/c2cciutils 1.5.10
github-actions
.github/workflows/backport.yaml
ubuntu 22.04
.github/workflows/main.yaml
actions/checkout v3
actions/cache v3
actions/upload-artifact v4
actions/upload-artifact v4
ubuntu 22.04
.github/workflows/pull-request-automation.yaml
actions/github-script v7
actions/github-script v7
actions/github-script v6
ubuntu 22.04
pep621
pyproject.toml
poetry-core >=1.0.0
pip_requirements
ci/requirements.txt
c2cciutils ==1.5.10
pre-commit ==3.2.2
setuptools >=65.5.1
requirements.txt
poetry ==1.6.1
pip ==23.3.2
poetry
pyproject.toml
python >=3.8,<4
jsonschema 4.17.3
typing-extensions 4.5.0
requests 2.32.3
PyYAML 6.0.1
pinyin 0.4.0
romkan 0.2.1
romanize 1.0.2
pre-commit 3.2.2
referencing 0.27.4
certifi 2023.7.22
urllib3 1.26.19
idna 3.7
prospector 1.9.0
pytest 7.2.2
pytest-cov 4.0.0
types-requests 2.28.11.17
types-pyyaml 6.0.12.20240311
pre-commit
.pre-commit-config.yaml
pre-commit/mirrors-prettier v2.7.1
pre-commit/pre-commit-hooks v4.4.0
sbrunner/hooks 0.5.0
codespell-project/codespell v2.2.6
shellcheck-py/shellcheck-py v0.9.0.6
jumanjihouse/pre-commit-hooks 3.0.0
python-jsonschema/check-jsonschema 0.22.0
sirwart/ripsecrets v0.1.8
PyCQA/autoflake v2.0.2
asottile/pyupgrade v3.3.2
PyCQA/isort 5.12.0
psf/black 23.3.0
PyCQA/prospector v1.9.0
sbrunner/jsonschema-validator 0.1.0
regex
.pre-commit-config.yaml
pre-commit 3.2.2
prettier 2.8.8
poetry 1.6.1
poetry 1.6.1
pyjson5 1.6.6
ci/config.yaml
camptocamp/c2cciutils 1.5.10
github-actions
.github/workflows/backport.yaml
ubuntu 22.04
.github/workflows/main.yaml
actions/checkout v3
actions/cache v3
actions/upload-artifact v4
actions/upload-artifact v4
ubuntu 22.04
.github/workflows/pull-request-automation.yaml
actions/github-script v7
actions/github-script v7
actions/github-script v6
ubuntu 22.04
pep621
pyproject.toml
poetry-core >=1.0.0
pip_requirements
ci/requirements.txt
c2cciutils ==1.5.10
pre-commit ==3.3.3
requirements.txt
poetry ==1.6.1
pip ==23.3.2
poetry
pyproject.toml
python >=3.8,<4
jsonschema 4.18.6
typing-extensions 4.7.1
requests 2.32.3
PyYAML 6.0.1
pinyin 0.4.0
romkan 0.2.1
romanize 1.0.2
pre-commit 3.3.3
referencing 0.30.2
urllib3 2.2.2
idna 3.7
prospector 1.10.3
pytest 7.4.4
pytest-cov 4.1.0
types-requests 2.31.0.20240406
types-pyyaml 6.0.12.20240311
prospector-profile-duplicated 0.1.0
pre-commit
.pre-commit-config.yaml
pre-commit/mirrors-prettier v3.0.3
pre-commit/pre-commit-hooks v4.4.0
sbrunner/hooks 0.5.0
codespell-project/codespell v2.2.6
shellcheck-py/shellcheck-py v0.9.0.6
jumanjihouse/pre-commit-hooks 3.0.0
python-jsonschema/check-jsonschema 0.23.3
sirwart/ripsecrets v0.1.8
PyCQA/autoflake v2.2.1
asottile/pyupgrade v3.10.1
PyCQA/isort 5.12.0
psf/black 23.7.0
PyCQA/prospector v1.10.3
sbrunner/jsonschema-validator 0.1.0
regex
.pre-commit-config.yaml
pre-commit 3.3.3
prettier 3.0.3
poetry 1.6.1
poetry 1.6.1
pyjson5 1.6.6
prospector-profile-duplicated 0.1.0
ci/config.yaml
camptocamp/c2cciutils 1.5.10
github-actions
.github/workflows/backport.yaml
ubuntu 22.04
.github/workflows/main.yaml
actions/checkout v4
actions/cache v3
actions/upload-artifact v4
actions/upload-artifact v4
ubuntu 22.04
.github/workflows/pull-request-automation.yaml
actions/github-script v7
actions/github-script v7
actions/github-script v7
ubuntu 22.04
pep621
pyproject.toml
poetry-core >=1.0.0
pip_requirements
ci/requirements.txt
c2cciutils ==1.6.21
pre-commit ==3.6.2
poetry-plugin-drop-python-upper-constraint ==0.1.0
poetry-plugin-export ==1.6.0
poetry-plugin-tweak-dependencies-version ==1.5.2
poetry-dynamic-versioning ==1.2.0
importlib-metadata <8.0.0
setuptools >=65.5.1
requirements.txt
poetry ==1.7.1
pip ==23.3.2
poetry-dynamic-versioning ==1.2.0
poetry-plugin-export ==1.6.0
poetry-plugin-tweak-dependencies-version ==1.5.2
poetry-plugin-drop-python-upper-constraint ==0.1.0
poetry
pyproject.toml
python >=3.9,<4
jsonschema 4.20.0
typing-extensions 4.9.0
requests 2.32.3
PyYAML 6.0.1
pinyin 0.4.0
romkan 0.2.1
romanize 1.0.2
pre-commit 3.6.2
referencing 0.32.1
idna 3.7
urllib3 2.2.2
prospector 1.10.3
pytest 7.4.4
pytest-cov 4.1.0
types-requests 2.31.0.20240406
types-pyyaml 6.0.12.20240311
prospector-profile-duplicated 0.5.1
pre-commit
.pre-commit-config.yaml
pre-commit/mirrors-prettier v3.1.0
pre-commit/pre-commit-hooks v4.5.0
sbrunner/hooks 0.6.0
codespell-project/codespell v2.2.6
shellcheck-py/shellcheck-py v0.9.0.6
jumanjihouse/pre-commit-hooks 3.0.0
python-jsonschema/check-jsonschema 0.27.4
sirwart/ripsecrets v0.1.8
asottile/pyupgrade v3.15.2
PyCQA/autoflake v2.2.1
PyCQA/isort 5.13.2
psf/black 23.12.1
PyCQA/prospector v1.10.3
sbrunner/jsonschema-validator 0.1.0
regex
.pre-commit-config.yaml
pre-commit 3.6.2
prettier 3.1.1
poetry 1.7.1
poetry 1.7.1
pyjson5 1.6.6
prospector-profile-duplicated 0.5.1
ci/config.yaml
camptocamp/c2cciutils 1.6.21
github-actions
.github/workflows/backport.yaml
ubuntu 22.04
.github/workflows/main.yaml
actions/setup-python v5
actions/checkout v4
actions/checkout v4
actions/cache v4
actions/upload-artifact v4
actions/upload-artifact v4
ubuntu 22.04
ubuntu 22.04
.github/workflows/pull-request-automation.yaml
actions/github-script v7
actions/github-script v7
actions/github-script v7
ubuntu 22.04
pep621
pyproject.toml
poetry-core >=1.0.0
pip_requirements
ci/requirements.txt
c2cciutils ==1.6.21
pre-commit ==3.6.2
poetry-plugin-drop-python-upper-constraint ==0.1.0
poetry-plugin-export ==1.6.0
poetry-plugin-tweak-dependencies-version ==1.5.2
poetry-dynamic-versioning ==1.2.0
importlib-metadata <8.0.0
requirements.txt
poetry ==1.7.1
pip ==23.3.2
poetry-dynamic-versioning ==1.2.0
poetry-plugin-export ==1.6.0
poetry-plugin-tweak-dependencies-version ==1.5.2
poetry-plugin-drop-python-upper-constraint ==0.1.0
poetry
pyproject.toml
python >=3.9,<4
jsonschema 4.21.1
typing-extensions 4.9.0
requests 2.32.3
PyYAML 6.0.1
pinyin 0.4.0
romkan 0.2.1
romanize 1.0.2
pre-commit 3.6.2
referencing 0.33.0
idna 3.7
urllib3 2.2.2
prospector 1.10.3
prospector-profile-duplicated 0.5.1
prospector-profile-utils 1.7.2
pytest 8.0.2
pytest-cov 4.1.0
types-requests 2.31.0.20240406
types-pyyaml 6.0.12.20240311
pre-commit
.pre-commit-config.yaml
pre-commit/mirrors-prettier v3.1.0
pre-commit/pre-commit-hooks v4.5.0
sbrunner/hooks 0.7.0
codespell-project/codespell v2.2.6
shellcheck-py/shellcheck-py v0.9.0.6
jumanjihouse/pre-commit-hooks 3.0.0
python-jsonschema/check-jsonschema 0.27.4
sirwart/ripsecrets v0.1.8
asottile/pyupgrade v3.15.2
PyCQA/autoflake v2.2.1
PyCQA/isort 5.13.2
psf/black 24.1.1
PyCQA/prospector v1.10.3
sbrunner/jsonschema-validator 0.1.0
regex
.pre-commit-config.yaml
pre-commit 3.6.2
prettier 3.2.5
poetry 1.7.1
poetry 1.7.1
pyjson5 1.6.6
prospector-profile-duplicated 0.5.1
prospector-profile-utils 1.7.2
ci/config.yaml
camptocamp/c2cciutils 1.6.21
github-actions
.github/workflows/backport.yaml
ubuntu 22.04
.github/workflows/main.yaml
actions/setup-python v5
actions/checkout v4
actions/checkout v4
actions/cache v4
actions/upload-artifact v4
actions/upload-artifact v4
ubuntu 22.04
ubuntu 22.04
.github/workflows/pull-request-automation.yaml
actions/github-script v7
actions/github-script v7
actions/github-script v7
ubuntu 22.04
pep621
pyproject.toml
poetry-core >=1.0.0
pip_requirements
ci/requirements.txt
c2cciutils ==1.6.21
pre-commit ==3.7.1
poetry-plugin-drop-python-upper-constraint ==0.1.0
poetry-plugin-export ==1.7.1
poetry-plugin-tweak-dependencies-version ==1.5.2
poetry-dynamic-versioning ==1.2.0
importlib-metadata <8.0.0
requirements.txt
poetry ==1.8.3
pip ==24.0
poetry-dynamic-versioning ==1.2.0
poetry-plugin-export ==1.7.1
poetry-plugin-tweak-dependencies-version ==1.5.2
poetry-plugin-drop-python-upper-constraint ==0.1.0
poetry
pyproject.toml
python >=3.9,<4
jsonschema 4.21.1
typing-extensions 4.10.0
requests 2.32.3
PyYAML 6.0.1
pinyin 0.4.0
romkan 0.2.1
romanize 1.0.2
pre-commit 3.7.1
referencing 0.34.0
idna 3.7
urllib3 2.2.2
prospector 1.10.3
prospector-profile-duplicated 1.2.0
prospector-profile-utils 1.7.2
pytest 8.1.2
pytest-cov 5.0.0
types-requests 2.31.0.20240406
types-pyyaml 6.0.12.20240311
pre-commit
.pre-commit-config.yaml
pre-commit/mirrors-prettier v3.1.0
pre-commit/pre-commit-hooks v4.5.0
sbrunner/hooks 1.0.0
codespell-project/codespell v2.2.6
shellcheck-py/shellcheck-py v0.10.0.1
jumanjihouse/pre-commit-hooks 3.0.0
python-jsonschema/check-jsonschema 0.28.6
sirwart/ripsecrets v0.1.8
asottile/pyupgrade v3.15.2
PyCQA/autoflake v2.3.1
PyCQA/isort 5.13.2
psf/black 24.3.0
PyCQA/prospector v1.10.3
sbrunner/jsonschema-validator 0.1.0
regex
.pre-commit-config.yaml
pre-commit 3.7.1
prettier 3.2.5
poetry 1.8.3
poetry 1.8.3
pyjson5 1.6.6
prospector-profile-duplicated 1.2.0
prospector-profile-utils 1.7.2
ci/config.yaml
camptocamp/c2cciutils 1.6.21
github-actions
.github/workflows/audit.yaml
actions/checkout v4
andstor/file-existence-action v3
asdf-vm/actions v3
andstor/file-existence-action v3
ubuntu 22.04
.github/workflows/backport.yaml
ubuntu 22.04
.github/workflows/main.yaml
actions/setup-python v5
actions/checkout v4
actions/checkout v4
actions/cache v4
actions/upload-artifact v4
actions/upload-artifact v4
ubuntu 22.04
ubuntu 22.04
.github/workflows/pull-request-automation.yaml
actions/github-script v7
actions/github-script v7
actions/github-script v7
ubuntu 22.04
pep621
pyproject.toml
poetry-core >=1.0.0
pip_requirements
ci/requirements.txt
c2cciutils ==1.6.21
pre-commit ==3.7.1
poetry-plugin-drop-python-upper-constraint ==0.1.0
poetry-plugin-export ==1.8.0
poetry-plugin-tweak-dependencies-version ==1.5.2
poetry-dynamic-versioning ==1.4.0
importlib-metadata <8.0.0
requirements.txt
poetry ==1.8.3
pip ==24.1.1
poetry-dynamic-versioning ==1.4.0
poetry-plugin-export ==1.8.0
poetry-plugin-tweak-dependencies-version ==1.5.2
poetry-plugin-drop-python-upper-constraint ==0.1.0
poetry
pyproject.toml
python >=3.9,<4
jsonschema 4.22.0
typing-extensions 4.12.2
requests 2.32.3
PyYAML 6.0.1
pinyin 0.4.0
romkan 0.2.1
romanize 1.0.2
pre-commit 3.7.1
referencing 0.35.1
prospector 1.10.3
prospector-profile-duplicated 1.5.0
prospector-profile-utils 1.7.2
pytest 8.2.2
pytest-cov 5.0.0
types-requests 2.32.0.20240622
types-pyyaml 6.0.12.20240311
pre-commit
.pre-commit-config.yaml
pre-commit/mirrors-prettier v3.1.0
pre-commit/pre-commit-hooks v4.6.0
sbrunner/hooks 1.0.0
codespell-project/codespell v2.3.0
shellcheck-py/shellcheck-py v0.10.0.1
jumanjihouse/pre-commit-hooks 3.0.0
python-jsonschema/check-jsonschema 0.28.6
sirwart/ripsecrets v0.1.8
asottile/pyupgrade v3.16.0
PyCQA/autoflake v2.3.1
PyCQA/isort 5.13.2
psf/black 24.4.2
PyCQA/prospector v1.10.3
sbrunner/jsonschema-validator 0.1.0
regex
.pre-commit-config.yaml
pre-commit 3.7.1
prettier 3.3.2
poetry 1.8.3
poetry 1.8.3
pyjson5 1.6.6
prospector-profile-duplicated 1.5.0
prospector-profile-utils 1.7.2
ci/config.yaml
camptocamp/c2cciutils 1.6.21
I am using jsconschema-gentypes for synchronizing types between a rust codebase and python ( very usefull!)
However, currenctly struggling since jsonschema-gentypes seems to ignored required shared fields on objects that are also "onOf" (enums).
For example, the following schema should generate a "Deal" type that also has a "agio" (required) field - but it's completely missing in the generated python code:
{ "$schema": "http://json-schema.org/draft-07/schema#", "title": "Both", "type": "object", "required": [ "input", "output" ], "properties": { "input": { "$ref": "#/definitions/Deal" }, "output": { "$ref": "#/definitions/Deal" } }, "definitions": { "Deal": { "type": "object", "oneOf": [ { "type": "object", "required": [ "maturity" ], "properties": { "maturity": { "type": "string", "format": "date" } } } ], "required": [ "agio" ], "properties": { "agio": { "type": "number", "format": "double" } } } } }
I. the floowing is a valid object:
{ "input": { "maturity": "2022-12-02", "agio": 1 }, "output": { "maturity": "2022-12-02", "agio": 1 }, }
First of all, great work. The idea of generating type definitions from a jsonschema is exciting, and I'd like to be able to put this to good use.
I noticed two bugs, and as well as some other issues that are likely less impactful right now.
When I feed this schema to jsonschema-gentypes, it produces invalid Python.
If I work around 1), one of the schema keys is defined as a variable rather than a type alias, which introduces lots of noisy warnings when used with mypy.
For the first issue, I noticed that the invalid Python is on lines that are whitespace with a comment. I'm not sure what the issue is, but it goes away when I delete the line.
For the second issue, mypy produced a convenient warning message which hinted at the issue with this link: https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
When I checked the line that it was complaining about I noticed that it was just a variable definition something = None
. Once I redefined this variable as a TypeAlias, those issues went away.
Reproducer:
git clone https://github.com/canonical/cloud-init.git
cd cloud-init
python3 -m venv .venv
. .venv/bin/activate
pip3 install jsonschema-gentypes tox -r test-requirements.txt
jsonschema-gentypes --json-schema=./cloudinit/config/schemas/schema-cloud-config-v1.json --python=cloudinit/config/config_type.py
echo "from cloudinit.config.config_type import _Root as Config" > cloudinit/config/__init__.py
tox -e mypy
The syntax failure:
$ tox -e mypy
mypy: commands[0]> .tox/mypy/bin/python -m mypy cloudinit/ tests/ tools/
cloudinit/config/config_type.py:1329: error: invalid syntax
Found 1 error in 1 file (errors prevented further checking)
mypy: exit 2 (0.35 seconds) /home/holmanb/ci> .tox/mypy/bin/python -m mypy cloudinit/ tests/ tools/ pid=561085
mypy: FAIL code 2 (0.39=setup[0.04]+cmd[0.35] seconds)
evaluation failed :( (0.50 seconds)
When I delete all comment lines it gets a little further:
$ sed -i 's/^\s*#.*//' cloudinit/config/config_type.py
$ tox -e mypy
cloudinit/config/config_type.py:1762: SyntaxWarning: invalid escape sequence '\w'
"""
cloudinit/config/config_type.py:2136: SyntaxWarning: invalid escape sequence '\$'
"""
cloudinit/config/config_type.py:3049: SyntaxWarning: invalid escape sequence '\+'
"""
cloudinit/config/config_type.py:3660: SyntaxWarning: invalid escape sequence '\.'
""" pattern: ^([0-9]+)?\.?[0-9]+[BKMGT]$ """
cloudinit/config/config_type.py:3671: SyntaxWarning: invalid escape sequence '\.'
""" pattern: ^([0-9]+)?\.?[0-9]+[BKMGT]$ """
cloudinit/config/config_type.py:1: error: Module "typing" has no attribute "Required"
cloudinit/config/config_type.py:9: error: Name "_DEFSALLMODULES_APK_CONFIGURE" already defined on line 7
...
cloudinit/config/config_type.py:589: error: Variable "cloudinit.config.config_type._DefsUsersGroupsFullStopUserObjectGroupsOneof2Type" is not valid as a type
cloudinit/config/config_type.py:589: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
...
...
cloudinit/config/config_type.py:589: error: Variable "cloudinit.config.config_type._DefsUsersGroupsFullStopUserObjectGroupsOneof2Type" is not valid as a type
cloudinit/config/config_type.py:589: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
cloudinit/config/cc_zypper_add_repo.py:589: error: Name "_DefsUsersGroupsFullStopUserObjectGroupsOneof2Type" is not defined
...
cloudinit/config/cc_yum_add_repo.py:589: error: Name "_DefsUsersGroupsFullStopUserObjectGroupsOneof2Type" is not defined
...
I'm running 3.12, which probably explains the syntax warnings.
The "has no attribute" error has me puzzled, I can't reproduce it just by running that import inside of the venv.
The "already defined on line" error is due to some keys that we have which are duplicates, we might be able to change this but I know that there was a good reason to add them when those were introduced.
The is not valid as a type
error is due to a line which contains:
_DefsUsersGroupsFullStopUserObjectGroupsOneof2Type = None
It goes away if I redefine it as a TypeAlias
_DefsUsersGroupsFullStopUserObjectGroupsOneof2Type: TypeAlias = str
With that issue resolved, I think that most if the issues I see are due mypy reporting valid issues.
I'll be happy to test a fix if you figure out the issues here. My project could potentially even use jsonschema-gentypes as part of a CI job for my project if these issues get resolved.
Thanks for jsonschema-gentypes
!
I'm interested in re-packaging jsonschema-gentypes
on conda-forge
. Typically, that ecosystem prefers to source upstreams from canonical upstreams, in this case a .tar.gz
on PyPI. This is hopefully a single-line change!
Further on the wishlist would that it included the test suite.
In the meantime, will continue with the github tarball, but these have the shortcoming of being changeable, either due to the underlying tag changing, or Github changing how it does its packing.
This issue is the dashboard used by GHCI modules.
Perhaps I'm missing an option, but could the types generated use a class and docstings, instead of the constructor and comments, which don't show up in intellisense.
E.g. instead of:
# A Widget is a blah blah blah.
# @see https://google.com
Hello = TypedDict(
"Hello",
{
# The ID of the tenant this event is associated with and will be delivered to. For more on tenants @see https://apptrail.com/docs/applications/guide/working-with-tenants.
#
# pattern: ^[A-Za-z0-9_\-+=]*$
#
# required
"id": str,
}
)
generate:
class Hello(TypedDict):
"""
A Widget is a blah blah blah.
@see https://google.com
"""
a: str
"""
The ID of the widget, blah blah.
pattern: ^[A-Za-z0-9_\-+=]*$
required
"""
which enables:
When we have properties
and additionalProperties
like:
{
"propterites": {
"id": {"type": "number"}
},
"additionalProperties": {"type": "string"}
}
It is interpreted as:
TypeTyped = TypedDict(
"TypeTyped",
{
"type": Union[int, float]
},
totaf=False,
)
Type = Union[TypeTyped, Dict[str, str]]
But it's not entirely correct.
See also: python/mypy#6131
I found, that looking up $defs in a file referenced by another file uses the original resolver and the uri designator does not get prefixed.
Attached a minimal example.
Here the most usefull part of the exception:
referencing.exceptions.PointerToNowhere: '/$defs/def_child' does not exist within {'$schema': 'https://json-schema.org/draft/2019-09/schema', 'type': 'object', 'properties': {'child': {'$schema': 'https://json-schema.org/draft/2019-09/schema', '$defs': {'def_child': {'type': 'object'}}, 'allOf': [{}]}}, 'required': ['child']}
It seems like resolving $ref
s in file's other than the root crashes in odd ways. The RefResolver.resolver
base_url
is always seems to be that of the root schema. I created a minimal reproducible example where the local anchor of "#/$defs/bar"
is attempted to be resolved in foo.schema.json
(which crashes) instead of being resolved in bar.schema.json
.
foo.schema.json:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$ref": "./bar.schema.json"
}
bar.schema.json:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"bar": {
"$ref": "#/$defs/bar"
}
},
"$defs": {
"bar": {
"type": "string"
}
}
}
# ok!
$ jsonschema-gentypes --json-schema=bar.schema.json --python=bar.py
# errors
$ jsonschema-gentypes --json-schema=foo.schema.json --python=foo.py
Processing foo.schema.json
Traceback (most recent call last):
File "/opt/python/3.10.8/lib/python3.10/site-packages/referencing/_core.py", line 186, in pointer
contents = contents[segment] # type: ignore[reportUnknownArgumentType] # noqa: E501
KeyError: '$defs'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/workspaces/jsonschema-gentypes/jsonschema_gentypes/resolver.py", line 174, in lookup
return self.resolver.lookup(uri).contents
File "/opt/python/3.10.8/lib/python3.10/site-packages/referencing/_core.py", line 594, in lookup
return retrieved.value.pointer(pointer=fragment, resolver=resolver)
File "/opt/python/3.10.8/lib/python3.10/site-packages/referencing/_core.py", line 188, in pointer
raise exceptions.PointerToNowhere(ref=pointer, resource=self)
referencing.exceptions.PointerToNowhere: '/$defs/bar' does not exist within {'$schema': 'https://json-schema.org/draft/2020-12/schema', '$ref': './bar.schema.json'}
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/codespace/.python/current/bin/jsonschema-gentypes", line 8, in <module>
sys.exit(main())
File "/workspaces/jsonschema-gentypes/jsonschema_gentypes/cli.py", line 105, in main
process_config(config)
File "/workspaces/jsonschema-gentypes/jsonschema_gentypes/cli.py", line 322, in process_config
add_type(schema_all, gen.get("root_name", "Root"), force_name="root_name" in gen)
File "/workspaces/jsonschema-gentypes/jsonschema_gentypes/cli.py", line 135, in __call__
base_type = self.api.get_type(self.resolver.auto_resolve(schema), name)
File "/workspaces/jsonschema-gentypes/jsonschema_gentypes/api.py", line 163, in get_type
the_type = self.build_type(schema, proposed_name)
File "/workspaces/jsonschema-gentypes/jsonschema_gentypes/api_draft_06.py", line 68, in build_type
return super().build_type(schema, proposed_name)
File "/workspaces/jsonschema-gentypes/jsonschema_gentypes/api.py", line 428, in build_type
return self._get_type(schema, schema_type, proposed_name)
File "/workspaces/jsonschema-gentypes/jsonschema_gentypes/api.py", line 463, in _get_type
return handler(schema, proposed_name)
File "/workspaces/jsonschema-gentypes/jsonschema_gentypes/api_draft_04.py", line 127, in object
struct = {
File "/workspaces/jsonschema-gentypes/jsonschema_gentypes/api_draft_04.py", line 128, in <dictcomp>
prop: self.get_type(sub_schema, proposed_name + " " + prop, auto_alias=False)
File "/workspaces/jsonschema-gentypes/jsonschema_gentypes/api.py", line 163, in get_type
the_type = self.build_type(schema, proposed_name)
File "/workspaces/jsonschema-gentypes/jsonschema_gentypes/api_draft_06.py", line 68, in build_type
return super().build_type(schema, proposed_name)
File "/workspaces/jsonschema-gentypes/jsonschema_gentypes/api.py", line 310, in build_type
return self.ref(schema_core, proposed_name)
File "/workspaces/jsonschema-gentypes/jsonschema_gentypes/api_draft_2020_12.py", line 71, in ref
return super().ref(schema, proposed_name)
File "/workspaces/jsonschema-gentypes/jsonschema_gentypes/api_draft_2019_09.py", line 105, in ref
return super().ref(schema, proposed_name)
File "/workspaces/jsonschema-gentypes/jsonschema_gentypes/api_draft_04.py", line 373, in ref
resolved = self.resolver.lookup(ref)
File "/workspaces/jsonschema-gentypes/jsonschema_gentypes/resolver.py", line 185, in lookup
raise UnRedolvedException(f"Ref '{uri}' not found") from exception
jsonschema_gentypes.resolver.UnRedolvedException: Ref '#/$defs/bar' not found
jsonschema-gentypes attempts to import requests, but pip install jsonschema-gentypes
won't install it
I would also like to disable all network access of this tool via CLI flag
We have a schema definition with two fields, foo_required
and foo_optional
.
{"properties": {"foo_required": {}, "foo_optional": {}}, "required": ["foo_required"]}
Now consider this code:
x["foo_optional"]
VSCode/pyright does error on the above line because it might crash. Unfortunately, mypy does not.
This issue is tracked in python/mypy#12094 -- unfortunately the issue is open for more than a year.
In a comment I came up with an idea for a workaround where we actually construct multiple TypedDicts and combine them with a Union
. This contraption will also cause mypy to find the problem in the above code snippet.
class MyDict(TypedDict, total=False):
foo_required: Required[int]
foo_optional: NotRequired[int]
class MinimalDict(TypedDict, total=False):
foo_required: Required[int]
MyDict2 = Union[MyDict, MinimalDict]
Do you think this would be reasonable to emit by default from jsonschema-gentypes? Or is it too hacky?
We are also considering running pyright in CI to catch those errors, but it would be a bigger project for us.
I am working on a project where the JSON schema describes an object that has a single pattern property of type object. This property key is roughly the identifier for the sub-object. In this case the type structure is very similar to when additionalProperties
is a dictionary. I've written a simple proof-of-concept and it appears to work nicely in the happy path and could provide a PR or sample code if interested.
Here is an example fragment of a JSON schema that has this pattern:
"providers": {
"type": "object",
"patternProperties": {
"^[a-z0-9_]{2,64}$": {
"type": "object",
"properties": {
...
}
}
},
Would you be willing to add support for this into your library?
Using Python 3.10.12 and version jsonschema-gentypes
2.4.0
So for this schema:
{
"$schema": "http://json-schema.org/draft-06/schema#",
"definitions": {
"SubresourceUris": {
"type": "object",
"properties": {
"feedback": {
"type": "string"
}
},
"required": ["feedback"],
"title": "SubresourceUris"
}
},
"type": "object",
"properties": {
"subresource_uris": {
"$ref": "#/definitions/SubresourceUris"
}
},
"required": [
"subresource_uris"
],
"title": "ResponseType"
}
when I run:
from jsonschema_gentypes.cli import process_config
config = {
"python_version": None,
"generate": [
{
"source": "./input.json",
"destination": "./output.py",
}
],
}
process_config(config) # type: ignore
I get back the following:
from typing import TypedDict
from typing_extensions import Required
class Responsetype(TypedDict, total=False):
""" ResponseType. """
subresource_uris: Required["Subresourceuris"]
"""
SubresourceUris.
Required property
"""
class Subresourceuris(TypedDict, total=False):
""" SubresourceUris. """
feedback: Required[str]
""" Required property """
Is there any way to have the output match the case of the input, and have the class be named SubresourceUris
instead?
Love the library by the way! It's very nice.
This issue is the dashboard used by GHCI modules.
I'm having an issue where when I run the program it outputs a python file but claims there are no types
# Automatically generated file from a JSON schema
from typing import Any
Config = Any
""" WARNING: we get an schema without any type """
The input is the following (note that it was generated by https://www.npmjs.com/package/typescript-json-schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"BoundingRegion": {
"properties": {
"__typename": {
"const": "BoundingRegion",
"type": "string"
},
"bottomLeft": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
},
"bottomRight": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
},
"pageNum": {
"type": "number"
},
"topLeft": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
},
"topRight": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
}
},
"type": "object"
},
"ContextDomain": {
"properties": {
"__typename": {
"const": "ContextDomain",
"type": "string"
},
"context": {
"type": "string"
},
"contextType": {
"type": "string"
},
"documentId": {
"type": "string"
},
"embeddedText": {
"type": "string"
},
"page": {
"properties": {
"__typename": {
"const": "PageRange",
"type": "string"
},
"end": {
"type": "number"
},
"start": {
"type": "number"
}
},
"type": "object"
},
"query": {
"type": "string"
},
"ranking": {
"type": "number"
},
"section": {
"type": "string"
}
},
"type": "object"
},
"Exact": {
"type": "object"
},
"Filter": {
"properties": {
"__typename": {
"const": "Filter",
"type": "string"
},
"key": {}
},
"type": "object"
},
"Incremental": {
"anyOf": [
{
"$ref": "#/definitions/T_2"
},
{
"$ref": "#/definitions/{[PinkeyofT]?:Pextends\"$fragmentName\"|\"__typename\"?T[P]:never;}"
}
]
},
"InputMaybe": {
"type": "object"
},
"MakeEmpty": {
"type": "object"
},
"MakeMaybe": {
"allOf": [
{
"$ref": "#/definitions/Omit<T,K>_1"
},
{
"$ref": "#/definitions/{[SubKeyinK]:T[SubKey];}"
}
]
},
"MakeOptional": {
"allOf": [
{
"$ref": "#/definitions/Omit<T,K>"
},
{
"$ref": "#/definitions/{[SubKeyinK]?:T[SubKey];}"
}
]
},
"Maybe": {
"type": "object"
},
"Omit<T,K>": {
"type": "object"
},
"Omit<T,K>_1": {
"type": "object"
},
"PageRange": {
"properties": {
"__typename": {
"const": "PageRange",
"type": "string"
},
"end": {
"type": "number"
},
"start": {
"type": "number"
}
},
"type": "object"
},
"PayloadElement": {
"properties": {
"__typename": {
"const": "PayloadElement",
"type": "string"
},
"id": {},
"vector": {
"items": {
"type": "number"
},
"type": "array"
}
},
"type": "object"
},
"PineconeParallelUpsertParams": {
"properties": {
"__typename": {
"const": "PineconeParallelUpsertParams",
"type": "string"
},
"iterablePayload": {
"items": {
"properties": {
"__typename": {
"const": "PayloadElement",
"type": "string"
},
"id": {},
"vector": {
"items": {
"type": "number"
},
"type": "array"
}
},
"type": "object"
},
"type": "array"
},
"poolThreads": {
"type": "number"
}
},
"type": "object"
},
"PineconeQueryParams": {
"properties": {
"__typename": {
"const": "PineconeQueryParams",
"type": "string"
},
"filter": {
"properties": {
"__typename": {
"const": "Filter",
"type": "string"
},
"key": {}
},
"type": "object"
},
"includeMetadata": {
"type": "boolean"
},
"includeValues": {
"type": "boolean"
},
"sparseVector": {
"properties": {
"__typename": {
"const": "SparseVector",
"type": "string"
},
"key": {}
},
"type": "object"
},
"topK": {
"type": "number"
},
"vector": {
"items": {
"type": "number"
},
"type": "array"
}
},
"type": "object"
},
"Point": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
},
"Scalars": {
"description": "All built-in and custom scalars, mapped to their actual values",
"properties": {
"Boolean": {
"properties": {
"input": {
"type": "boolean"
},
"output": {
"type": "boolean"
}
},
"type": "object"
},
"Float": {
"properties": {
"input": {
"type": "number"
},
"output": {
"type": "number"
}
},
"type": "object"
},
"ID": {
"properties": {
"input": {
"type": "string"
},
"output": {
"type": "string"
}
},
"type": "object"
},
"Int": {
"properties": {
"input": {
"type": "number"
},
"output": {
"type": "number"
}
},
"type": "object"
},
"JSON": {
"properties": {
"input": {},
"output": {}
},
"type": "object"
},
"String": {
"properties": {
"input": {
"type": "string"
},
"output": {
"type": "string"
}
},
"type": "object"
}
},
"type": "object"
},
"SparseData": {
"properties": {
"__typename": {
"const": "SparseData",
"type": "string"
},
"indices": {
"items": {
"type": "number"
},
"type": "array"
},
"values": {
"items": {
"type": "number"
},
"type": "array"
}
},
"type": "object"
},
"SparseDenseVectors": {
"properties": {
"__typename": {
"const": "SparseDenseVectors",
"type": "string"
},
"dense": {
"items": {
"type": "number"
},
"type": "array"
},
"sparse": {
"properties": {
"__typename": {
"const": "SparseData",
"type": "string"
},
"indices": {
"items": {
"type": "number"
},
"type": "array"
},
"values": {
"items": {
"type": "number"
},
"type": "array"
}
},
"type": "object"
}
},
"type": "object"
},
"SparseVector": {
"properties": {
"__typename": {
"const": "SparseVector",
"type": "string"
},
"key": {}
},
"type": "object"
},
"T_2": {
"type": "object"
},
"Table": {
"properties": {
"__typename": {
"const": "Table",
"type": "string"
},
"bottomLeft": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
},
"bottomRight": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
},
"boundingRegion": {
"properties": {
"__typename": {
"const": "BoundingRegion",
"type": "string"
},
"bottomLeft": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
},
"bottomRight": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
},
"pageNum": {
"type": "number"
},
"topLeft": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
},
"topRight": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
}
},
"type": "object"
},
"caption": {
"properties": {
"__typename": {
"const": "TextBlock",
"type": "string"
},
"area": {
"type": "number"
},
"boundingRegion": {
"properties": {
"__typename": {
"const": "BoundingRegion",
"type": "string"
},
"bottomLeft": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
},
"bottomRight": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
},
"pageNum": {
"type": "number"
},
"topLeft": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
},
"topRight": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
}
},
"type": "object"
},
"content": {
"type": "string"
},
"endsWithoutClosure": {
"type": "boolean"
},
"isListItem": {
"type": "boolean"
},
"nearestParentHeading": {
"type": "string"
},
"pageNum": {
"type": "number"
},
"role": {
"$ref": "#/definitions/TextBlockRoleType"
},
"startsMidSentence": {
"type": "boolean"
}
},
"type": "object"
},
"cells": {
"items": {
"properties": {
"__typename": {
"const": "TableCell",
"type": "string"
},
"bottomLeft": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
},
"bottomRight": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
},
"boundingRegion": {
"properties": {
"__typename": {
"const": "BoundingRegion",
"type": "string"
},
"bottomLeft": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
},
"bottomRight": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
},
"pageNum": {
"type": "number"
},
"topLeft": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
},
"topRight": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
}
},
"type": "object"
},
"columnIndex": {
"type": "number"
},
"columnSpan": {
"type": "number"
},
"content": {
"type": "string"
},
"pageNum": {
"type": "number"
},
"rowIndex": {
"type": "number"
},
"rowSpan": {
"type": "number"
},
"topLeft": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
},
"topRight": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
},
"type": {
"$ref": "#/definitions/TableCellType"
}
},
"type": "object"
},
"type": "array"
},
"colCount": {
"type": "number"
},
"latexFormat": {
"type": "string"
},
"nearestParentHeading": {
"type": "string"
},
"pageNum": {
"type": "number"
},
"plainTextTable": {
"type": "string"
},
"rowCount": {
"type": "number"
},
"topLeft": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
},
"topRight": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
}
},
"type": "object"
},
"TableCell": {
"properties": {
"__typename": {
"const": "TableCell",
"type": "string"
},
"bottomLeft": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
},
"bottomRight": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
},
"boundingRegion": {
"properties": {
"__typename": {
"const": "BoundingRegion",
"type": "string"
},
"bottomLeft": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
},
"bottomRight": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
},
"pageNum": {
"type": "number"
},
"topLeft": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
},
"topRight": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
}
},
"type": "object"
},
"columnIndex": {
"type": "number"
},
"columnSpan": {
"type": "number"
},
"content": {
"type": "string"
},
"pageNum": {
"type": "number"
},
"rowIndex": {
"type": "number"
},
"rowSpan": {
"type": "number"
},
"topLeft": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
},
"topRight": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
},
"type": {
"$ref": "#/definitions/TableCellType"
}
},
"type": "object"
},
"TableCellType": {
"enum": [
"ColumnHeader",
"Content",
"Description",
"RowHeader",
"StubHead"
],
"type": "string"
},
"TextBlock": {
"properties": {
"__typename": {
"const": "TextBlock",
"type": "string"
},
"area": {
"type": "number"
},
"boundingRegion": {
"properties": {
"__typename": {
"const": "BoundingRegion",
"type": "string"
},
"bottomLeft": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
},
"bottomRight": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
},
"pageNum": {
"type": "number"
},
"topLeft": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
},
"topRight": {
"properties": {
"__typename": {
"const": "Point",
"type": "string"
},
"x": {
"type": "number"
},
"y": {
"type": "number"
}
},
"type": "object"
}
},
"type": "object"
},
"content": {
"type": "string"
},
"endsWithoutClosure": {
"type": "boolean"
},
"isListItem": {
"type": "boolean"
},
"nearestParentHeading": {
"type": "string"
},
"pageNum": {
"type": "number"
},
"role": {
"$ref": "#/definitions/TextBlockRoleType"
},
"startsMidSentence": {
"type": "boolean"
}
},
"type": "object"
},
"TextBlockRoleType": {
"enum": [
"ABSTRACT",
"FOOTNOTE",
"NONE",
"PAGE_FOOTER",
"PAGE_HEADER",
"PAGE_NUMBER",
"SECTION_HEADING",
"TABLE",
"TABLE_CAPTION",
"TITLE"
],
"type": "string"
},
"{[PinkeyofT]?:Pextends\"$fragmentName\"|\"__typename\"?T[P]:never;}": {
"type": "object"
},
"{[SubKeyinK]:T[SubKey];}": {
"type": "object"
},
"{[SubKeyinK]?:T[SubKey];}": {
"type": "object"
}
}
}
If you run jsonschema-gentypes
with a path like --json=../path/to/some.json
, and that file has relative $ref
entries in it, resolution will fail.
Repro:
$ cat base.json
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$ref": "sub.json"
}
$ cat sub.json
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type":"object",
"properties": { "x": { "type": "string" } }
}
$ jsonschema-gentypes --json=base.json --python=out.py
Processing base.json
$ cd subdir
$ jsonschema-gentypes --json=../base.json --python=out.py
Processing ../base.json
Traceback (most recent call last):
File "/Users/dbushong/.pyenv/versions/3.8.14/lib/python3.8/site-packages/referencing/_core.py", line 417, in get_or_retrieve
resource = registry._retrieve(uri)
File "/Users/dbushong/.pyenv/versions/3.8.14/lib/python3.8/site-packages/jsonschema_gentypes/resolver.py", line 83, in _open_uri_resolver
my_resource = referencing.Resource.from_contents(_open_uri(uri))
File "/Users/dbushong/.pyenv/versions/3.8.14/lib/python3.8/site-packages/jsonschema_gentypes/resolver.py", line 63, in _open_uri
with open(uri, encoding="utf-8") as open_file:
FileNotFoundError: [Errno 2] No such file or directory: 'sub.json'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/dbushong/.pyenv/versions/3.8.14/lib/python3.8/site-packages/referencing/_core.py", line 667, in lookup
retrieved = self._registry.get_or_retrieve(uri)
File "/Users/dbushong/.pyenv/versions/3.8.14/lib/python3.8/site-packages/referencing/_core.py", line 424, in get_or_retrieve
raise exceptions.Unretrievable(ref=uri) from error
referencing.exceptions.Unretrievable: 'sub.json'
Note that it works fine if you don't have ..
in your path
It is thread as Union
but it should be an intersection.
See also: python/typing#213
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.