Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/toumorokoshi/jsonschema-extractor
Extract jsonschema from various Python objects
https://github.com/toumorokoshi/jsonschema-extractor
Last synced: about 2 months ago
JSON representation
Extract jsonschema from various Python objects
- Host: GitHub
- URL: https://github.com/toumorokoshi/jsonschema-extractor
- Owner: toumorokoshi
- License: mit
- Created: 2017-06-20T03:32:28.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-10-25T05:09:49.000Z (about 2 years ago)
- Last Synced: 2024-08-10T07:37:39.433Z (5 months ago)
- Language: Python
- Homepage:
- Size: 61.5 KB
- Stars: 26
- Watchers: 4
- Forks: 9
- Open Issues: 2
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
====================
jsonschema-extractor
====================jsonschema-extractor is a library and extensible framework for
extracting `json schema `_ from various object and
primitives... image:: https://github.com/toumorokoshi/jsonschema-extractor/actions/workflows/python-package.yaml/badge.svg
:target: https://github.com/toumorokoshi/jsonschema-extractor/actions/workflows/python-package.yamlOut of the box support exists for:
- `attrs `_
- `typing `_-----
Usage
-----.. code-block:: python
from typing import List
import jsonschema_extractor
assert jsonschema_extractor.extract(List[int]) == {
"type": "array",
"items": {"type": "integer"}
}-------------
Attrs-example
-------------.. code-block:: python
import attr
from attr.validators import instance_of
import jsonschema_extractor@attr.define
class Example(object):
integer: int = attr.field()
foo = attr.field(metadata={"jsonschema": {"type": "string", "format": "uuid"}})
validator_list: List[float] = attr.field()
string: str = attr.field(
default="foo",
metadata={"description": "This is an description."}
)assert extractor.extract(Example) == {
"type": "object",
"title": "Example",
"properties": {
"string": {"description": "This is an description.", "type": "string"},
"integer": {"type": "integer"},
"validator_list": {"items": {"type": "number"}, "type": "array"},
"foo": {"type": "string", "format": "uuid"},
},
"required": ["integer", "foo", "validator_list"],
}