Skip to content

Support jsonschema's const keyword. #434

@Sean1708

Description

@Sean1708

Feature Request

https://json-schema.org/latest/json-schema-validation.html#rfc.section.6.1.3

This is a very useful feature for when structural subtyping just doesn't quite cut it and you need to differentiate two semantically different but structurally identical types.

Some ways that this could be implemented:

class Foo(pydantic.BaseModel):
    bar: pydantic.Constant = "baz"
class Foo(pydantic.BaseModel):
    bar: pydantic.constant("baz")

Which would each generate the following schema:

{
    "title": "Foo",
    "type": "object",
    "properties": {
        "bar": {
            "title": "Bar",
            "const": "baz"
        }
    },
    "required": ["bar"]
}

I'm happy to put some work in for this, if it's something that you're willing to support.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions