jsonnext / codemirror-json-schema

A JSONSchema enabled mode for codemirror 6, for json4 and json5, inspired by monaco-json
https://codemirror-json-schema.netlify.app
MIT License
56 stars 9 forks source link

Get sub schema using parsed data for additional context #133

Closed imolorhe closed 2 weeks ago

imolorhe commented 2 weeks ago

As mentioned in #132, the "calculated" sub schema for a path in the JSON document can change based on the values of other fields in the document. json-schema-library already has the feature to get schema with the data when the schema is dynamic.

To retrieve the data, I added best-effort-json-parser so we can get some data even if the JSON document isn't in a valid JSON state (which is going to be the case while writing the document). Given a document in the following state:

{
  "type": "Test_2",
  "props": {
    te
  }
}

it is able to retrieve the data as:

{
    "type": "Test_1",
    "props": {
        "te": null
    }
}

...which is sufficient context (at least for all the existing test cases)

Other changes in this PR include:

changeset-bot[bot] commented 2 weeks ago

🦋 Changeset detected

Latest commit: c04ef4ffa58af3622d9bf4ba19048e4ff3931823

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ---------------------- | ----- | | codemirror-json-schema | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

netlify[bot] commented 2 weeks ago

Deploy Preview for codemirror-json-schema ready!

Name Link
Latest commit c04ef4ffa58af3622d9bf4ba19048e4ff3931823
Latest deploy log https://app.netlify.com/sites/codemirror-json-schema/deploys/66780b76481fe70008f96301
Deploy Preview https://deploy-preview-133--codemirror-json-schema.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

acao commented 2 weeks ago

oh I love this!

acao commented 2 weeks ago

@imolorhe my only question is, why do we make this disabled by default?

imolorhe commented 2 weeks ago

@acao didn't want to change more behavior than necessary. Enabling it by default causes a test case (json-validation > 'not handle invalid json') to fail because now it can handle invalid JSON. This behavior change is fine though so maybe we just enable it by default

acao commented 2 weeks ago

@imolorhe sounds good to me!

normally for > 0.x I would tag a new feature as a minor release, but with 0.x I think we just patch