Skip to content

Conversation

@danila-schelkov
Copy link
Contributor

This PR adds support for using examples defined inside a propertyNames schema as completion suggestions.

Currently, when a JSON Schema contains propertyNames with an examples array, the values are ignored by the language service.

Changes

  • Extended the completion provider in jsonCompletion.ts to check propertyNames.examples.
  • If examples is present and contains strings, they are included in the completion list as property name suggestions.
  • Added a new test case to ensure that examples appear in completion results.

Example schema

{
  "type": "object",
  "propertyNames": {
    "type": "string",
    "pattern": "^[a-z]+$",
    "examples": ["username", "email", "address"]
  }
}

Expected behavior

When editing a JSON file with this schema, the completion list for new property names should include "username", "email", and "address".

image

Motivation

This improves usability when working with schemas that define flexible object properties but still want to provide user-friendly suggestions via examples.

Notes & Future Improvements

According to the JSON Schema Validation specification (draft-07, §10.4), it is RECOMMENDED that the values in examples are valid against the associated schema.

This PR does not enforce validation of examples against pattern constraints. Instead, it assumes that schema authors provide consistent examples.

As a potential future improvement, validation could be added to filter out examples that don’t conform to the pattern regular expression.

@danila-schelkov
Copy link
Contributor Author

@microsoft-github-policy-service agree

@aeschli
Copy link
Collaborator

aeschli commented Sep 29, 2025

Thanks @danila-schelkov !

@vs-code-engineering vs-code-engineering bot added this to the September 2025 milestone Sep 29, 2025
@aeschli aeschli merged commit 5f9c3cc into microsoft:main Sep 29, 2025
3 checks passed
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.

3 participants