Skip to content

Support constants in JSON schema #81

@tokarenko

Description

@tokarenko

What do you think about supporting constant values in schema, indicated by the Tuple type, e.g., as follows?

>>> from genson import SchemaBuilder
>>> builder = SchemaBuilder()
>>> builder.add_schema({"type": "object", "properties": {}})
>>> builder.add_object(
    { 
        "attr": ("value",)
    } 
)

Expected result is:
{'$schema': 'http://json-schema.org/schema#',
 'type': 'object',
 'properties': {
    'attr': {"const": "value"}},
    'required': ['attr']}

By the way, the code above raises the following error:
genson.schema.node.SchemaGenerationError: Could not find matching schema type for object: ("value",)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions