Skip to content

Conversation

@shin19991207
Copy link
Member

What does this PR do?

Implementation for propertyNames keyword auto-completion was only providing the title of the propertyNames schema as completion and did not correctly handle schemas that used enum, const, oneOf, anyOf, and allOf, and definition via $ref.

This PR improves propertyNames keyword auto-completion to support definition via $ref and enum/const/oneOf/anyOf/allOf.

What issues does this PR fix or reference?

Fixes #1141

Is it tested? How?

@coveralls
Copy link

coveralls commented Jan 5, 2026

Coverage Status

coverage: 84.238% (+0.1%) from 84.09%
when pulling 32079b6 on shin19991207:chang-patch-1141
into 8495b84 on redhat-developer:main.

@datho7561
Copy link
Contributor

"allOf" seems like it'll be a bit complicated to support. Here is the case I was playing with, I don't know if you want to handle it or not:

{
  "$schema": "https://json-schema.org/draft-07/schema#",
  "definitions": {
    "EventName": {
      "allOf": [
        {
          "const": "One"
        },
        {
          "enum": [
            "One",
            "Two"
          ]
        }
      ],
      "title": "EventName",
      "type": "string"
    }
  },
  "properties": {
    "events": {
      "additionalProperties": {
        "type": "integer"
      },
      "propertyNames": {
        "$ref": "#/definitions/EventName"
      },
      "title": "Events",
      "type": "object"
    }
  },
  "required": [
    "events"
  ],
  "title": "FooContainer",
  "type": "object"
}

In this case the property name can only be One, since it needs to match both the constant "One" and the enum "One" or "Two". Another similar case:

{
  "$schema": "https://json-schema.org/draft-07/schema#",
  "definitions": {
    "EventName": {
      "allOf": [
        {
          "const": "One"
        },
        {
          "const": "Two"
        }
      ],
      "title": "EventName",
      "type": "string"
    }
  },
  "properties": {
    "events": {
      "additionalProperties": {
        "type": "integer"
      },
      "propertyNames": {
        "$ref": "#/definitions/EventName"
      },
      "title": "Events",
      "type": "object"
    }
  },
  "required": [
    "events"
  ],
  "title": "FooContainer",
  "type": "object"
}

The property name cannot be anything, since it must be both "One" and "Two" and that's impossible.

@shin19991207
Copy link
Member Author

@datho7561 Thanks for catching this, David. I tested them individually and simply I combined them in the integration test without noticing the issue. I’ll get it fixed!

@shin19991207
Copy link
Member Author

@datho7561 The allOf bug cases are fixed now. I verified it manually with this schema:

{
  "$schema": "https://json-schema.org/draft-07/schema#",
  "properties": {
    "propertyNamesConst": {
      "type": "object",
      "propertyNames": {
        "const": "Event1"
      },
      "additionalProperties": {
        "type": "integer"
       }
    },
    "propertyNamesEnum": {
      "type": "object",
      "propertyNames": {
        "enum": [
          "Event1",
          "Event2",
          "Event3"
        ]
      },
      "additionalProperties": {
        "type": "integer"
      }
    },
    "propertyNamesOneOf": {
      "type": "object",
      "propertyNames": {
        "oneOf": [
          { "const": "Event1" },
          { "const": "Event2" }
        ]
      },
      "additionalProperties": {
        "type": "integer"
      }
    },
    "propertyNamesAnyOf": {
      "type": "object",
      "propertyNames": {
        "anyOf": [
          { "const": "Event1" },
          { "enum": ["Event2", "Event3"] }
        ]
      },
      "additionalProperties": {
        "type": "integer"
      }
    },
    "propertyNamesAllOf": {
      "type": "object",
      "propertyNames": {
        "allOf": [
          { "const": "One" },
          { "enum": ["One", "Two"] }
        ]
      },
      "additionalProperties": {
        "type": "integer"
      }
    },
    "propertyNamesAllOfImpossible": {
      "type": "object",
      "propertyNames": {
        "allOf": [
          { "const": "One" },
          { "const": "Two" }
        ]
      },
      "additionalProperties": {
        "type": "integer"
      }
    }
  },
  "required": [
    "propertyNamesConst",
    "propertyNamesEnum",
    "propertyNamesOneOf",
    "propertyNamesAnyOf",
    "propertyNamesAllOf",
    "propertyNamesAllOfImpossible"
  ],
  "title": "FooContainer",
  "type": "object"
}

Expected completion behavior:

propertyNamesConst:
  | # auto-complete gets option Event1
propertyNamesEnum:
  | # auto-complete gets options Event1, Event2, Event3
propertyNamesOneOf:
  | # auto-complete gets options Event1, Event2
propertyNamesAnyOf:
  | # auto-complete gets options Event1, Event2, Event3
propertyNamesAllOf:
  | # auto-complete gets option One only (your case 1)
propertyNamesAllOfImpossible:
  | # impossible case, no suggestion from auto-completion (your case 2)

Also updated the automated test cases as well.

@datho7561 datho7561 merged commit 1dc7e48 into redhat-developer:main Jan 6, 2026
4 checks passed
Copy link
Contributor

@datho7561 datho7561 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good and works well. Thanks, Morgan!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for propertyNames schema is incorrect

3 participants