Edge cases and Gotchas

Open
#2 11 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
python
Domain
tooling

Research direction

No files, tests, or entry points are named. Start by reviewing the repository and the JSON Schema examples in this issue, then identify how dialect changes, schema context, and embedded dialects should affect highlighting; done means these cases have defined and verified behavior.

Written by the indexing model from the issue text.

Description

Here are a few things to look out for when implementing something like this.

The set of properties that are considered keywords depends on the dialect

In the following example, additionalItems should not be highlighted as a keyword because it was removed in 2020-12.

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "prefixItems": [true],
  "additionalItems": false, // <- not a keyword
  "items": false,
  "definitions": {} // <- not a keyword
  "aaa": 42 // <- not a keyword
}

When we change the dialect, the properties that are considered keywords changes.

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "prefixItems": [true], // <- not a keyword
  "additionalItems": false,
  "items": false
  "definitions": {}
  "aaa": 42 // <- not a keyword
}

Properties are only keywords inside schemas

Not every object in a JSON Schema document is a schema, so you need to know when you're in a schema and when you're not. Here are a couple examples.

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "properties": {
    "$id": "foo" // <- not a keyword
  }
}

In the next example, $id isn't considered a keyword because definitions isn't a keyword in 2020-12. Therefore, their values aren't schemas and the properties of those values shouldn't be considered keywords.

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "definitions": {
    "foo": {
      "type": "string" // <- not a keyword
    }
  }
}

Embedded schemas can have a different dialect

It's possible for embedded schemas to have a different dialect than their parent schema. In the following example, the same keywords are highlighted differently depending on which schema resource the keyword appears in.

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "prefixItems": [true],
  "additionalItems": false, // <- not a keyword
  "items": false,
  "$defs": {
    "foo": {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "$id": "https://example.com/schema/embedded",
      "prefixItems": [true], // <- not a keyword
      "additionalItems": false,
      "items": false,
      "definitions": {}
    }
  }
}
Dominant language
Python
Stars
1
Forks
1
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from python-jsonschema/jsonschema-lexer

All issues in python-jsonschema/jsonschema-lexer

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.