Skip to content

Conversation

marcopiii
Copy link

@marcopiii marcopiii commented Jul 1, 2025

Despite the possibility to validate a key against a schema using propertyNames, LanguageService.getMatchingSchemas doesn't return such matches.

This little change fixes that and would solve #89

Example

Given a schema like this

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "id": { "type": "string", "my-custom-metadata": "foo" },
  },
  "type": "object",
  "properties": {
    "name": { "type": "string" },
    "things": {
      "type": "object",
      "propertyNames": { "$ref": "#/definitions/id" },
      "additionalProperties": { "type": "string" }
    }
  }
}

a json like this

{
    "name": "Tony",
    "things": {
        "f2617076": "hat",
        "2ae481ea": "skateboard"
    }
}

would produce the following matches

[
  ...,
  {
    node: StringASTNodeImpl {
      offset: 46,
      length: 10,
      type: 'string',
      value: 'f2617076'
    },
    schema: { type: 'string', 'my-custom-metadata': 'foo' }
  },
  {
    node: StringASTNodeImpl {
      offset: 73,
      length: 10,
      type: 'string',
      value: '2ae481ea'
    },
    schema: { type: 'string', 'my-custom-metadata': 'foo' }
  },
  ...
]

@aeschli
Copy link
Collaborator

aeschli commented Sep 29, 2025

Can you add tests?

@marcopiii
Copy link
Author

marcopiii commented Oct 3, 2025

@marcopiii please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree

@marcopiii
Copy link
Author

Can you add tests?

@aeschli i hope i did the right thing with the test, let me know if anything else is needed 👍

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.

2 participants