Created
February 23, 2021 16:36
-
-
Save thanakijwanavit/96a89fa7aac43cd765aaa4d6c786f94c to your computer and use it in GitHub Desktop.
convert json-dataclass to json schema yaml for use in validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from dataclasses_json import dataclass_json, Undefined, CatchAll | |
| from dataclasses_jsonschema import JsonSchemaMixin | |
| import yaml | |
| @dataclass_json(undefined=Undefined.INCLUDE) | |
| @dataclass | |
| class Product(JsonSchemaMixin): | |
| iprcode: int | |
| cprcode: int | |
| @dataclass_json | |
| @dataclass | |
| class ValueUpdate(JsonSchemaMixin): | |
| items: List[Product] | |
| print(yaml.dump(Product.json_schema(), indent=2, sort_keys=True)) | |
| print(yaml.dump(ValueUpdate.json_schema(), indent=2, sort_keys=True)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment