Skip to content

Add const validation keyword #34

Description

@crmne

Goal

Add support for JSON Schema const.

const means the value must equal one exact JSON value. It is similar to a one-value enum, but JSON Schema has a dedicated keyword for it.

Example JSON Schema:

{
  "const": "admin"
}

Proposed DSL

string :role, const: "admin"
integer :version, const: 1
boolean :enabled, const: true
null :deleted_at, const: nil

Acceptance criteria

  • Works across primitive types.
  • Output uses const.
  • Behavior tests cover matching and non-matching values.
  • Generated schemas validate against Draft 2020-12.

Related work

Generic enum support already has related work:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions