Generate C++ structures from JSON-Schema
Project description
JSON-Schema Codegen
This python library consumes JSON-Schema and generates C++ code. It generates structures to hold the values defined in the schema, restricting the values according to the schema. Each structure has JSON serialization and de-serialization methods.
Supported Schema Features
A C++ class is generated for each schema node according to the schema's type
property. Schemas without a type
property, with the exception of combining operators *Of
, are not supported.
- type: string
- minLength
- maxLength
- pattern
- type: string with enum
- type: integer
- maximum
- minimum
- exclusiveMaximum
- exclusiveMinimum
- multipleOf
- type: number
- maximum
- minimum
- exclusiveMaximum
- exclusiveMinimum
- multipleOf
- type: boolean
- type: null
- type: array
- items
- minItems
- maxItems
- type: object
- properties
- required
- allOf
- anyOf
- oneOf
References
$ref
references are supported for array items, object properties, allOf, anyOf, and oneOf. However, the caller must provide a "resolver" class which translates the reference into a class name and namespace.
C++ Requirements
- boost (boost::optional and boost::variant among others)
- rapidjson
- C++11
Python Requirements
- python 3.7
- jinja2
- stringcase
Installation
pip install json-schema-codegen
Usage
See example_usage.py
for a more elaborate example.
import jsonschemacodegen.cpp as cpp
simpleResolver = cpp.SimpleResolver()
output_dir = "/tmp"
generator = cpp.GeneratorFromSchema(src_output_dir=output_dir,
header_output_dir=output_dir,
resolver=simpleResolver,
namespace=[],
src_usings=[])
sampleSchema = {"type": "string"}
generator.Generate(sampleSchema, 'Example', 'example')
License
GPLv2
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for json-schema-codegen-0.0.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3bccba925a42bc05d87ea13b91704a2ee672a43ba5fb3af3c6c39b116e6ecae2 |
|
MD5 | d3865c1b1a8752b0354cbee9f9bbab74 |
|
BLAKE2b-256 | 2f9aedc2dc21143b7fb2f6a4ff84cc252d4a07d8b2a9bf4ecf00fbafdc22ef71 |
Hashes for json_schema_codegen-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 528c81f7c48ca8d6260c765faf93844de242134971e51c5d0dd7a6a5871c0be7 |
|
MD5 | 328a59b804119d93314ecdbefde90760 |
|
BLAKE2b-256 | 48eeb6c05c78eda97d66b4f94b2b4311e29b1fad18655de143d889260d5f2f70 |