Skip to content

Request of the const field support #229

@belgraviton

Description

@belgraviton

What are you trying to do?
We use this library to automatically generate classes to validate our data format.

Example Schema and code

import python_jsonschema_objects as pjs
exclass = {
    "type": "object",
    "properties": {
        "region_type": {  "const": "RECTANGLE"  }
    },
    "title": "Example"
}
builder = pjs.ObjectBuilder(exclass)
available_classes = builder.build_classes()

Error: "NotImplementedError: Unable to parse schema object '{'const': 'RECTANGLE', 'raw_name': 'region_type'}' with no type and no reference"

Is this a currently unsupported jsonschema directive? If so, please link to the documentation

I'd like to be able to use the format validator from v7, as described here: https://json-schema.org/understanding-json-schema/reference/generic.html#constant-values

Do you have an idea about how this should work?

Support of "const" field in schema could be realized in a way similar to "enum".

"region_type": { "enum": [ "RECTANGLE" ] }

Last format in my json schema works.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions