Skip to content

const is not handled properly #1428

@navytux

Description

@navytux

Hello up there,

We noticed that const is not handled by json-editor well. For example in the following schema

{
  "title": "Something",
  "type": "object",
  "required": [
    "type",
    "subtype",
    "flavour"
  ],
  "properties": {
    "type": {
      "type": "string",
      "description": "Type of something",
      "const": "ABC"
    },
    "subtype": {
      "type": "string",
      "description": "Subtype of something",
      "enum": [
        "DEF"
      ]
    },
    "flavour": {
      "type": "string",
      "description": "Flavour of something",
      "enum": [
        "GHI",
        "JKL"
      ]
    }
  }
}

for subtype a select with single item is created, and for flavour a select with two items is created.

However for type no select is created and the field is left empty to be manually input.

By definition const: xxx is equivalent to enum: [xxx] : https://json-schema.org/draft/2020-12/json-schema-validation#name-const , so what json-editor should have been done here is to create a select for type as well with single possible choice.

Thanks beforehand,
Kirill

/cc @rmonnerat, @perrinjerome

General information

  • json-editor version: 2.12.0

Expected behavior

Select with one item is created in the UI for const fields.

Actual behavior

const is not handled - fields are left empty for manual input.

Steps to reproduce the behavior

Direct link to example: https://json-editor.github.io/json-editor/?data=N4Ig9gDgLglmB2BnEAuUMDGCA2MBGqIAZglAIYDuApomALZUCsIANOHgFZUZQD62ZAJ5gArlELwwAJzplsrEIgwALKrNShYUbFUIBlelSjKY8AOYKogiLpTsuPBVKoBHETGcATVAG0QVmwVEETwA3TYiAQA3USkQAF02CClIKilYGg1/a1tNHMJEKClTCzZPGgxi6Dh4QgAVHIACMCJG2gZjEoUsJHE7AEEAIQBhEABfNmDQ/LRswLtC4vMFcqUq2AR9ELDm1vajE2W2KngROl8QABEAUQAxBIniaNissIKirrKK9ZrCW+eRFJdm1DJ0jiATmcLgBxAASAEkFAApADSABkHmNHohlGAKLw0ikpMg7KYoGkyDxfmxjGpbCA8GAwFBFmQIAAWcZjIA

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions