Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get sub schema using parsed data for additional context #133

Merged
merged 4 commits into from
Jun 23, 2024

Conversation

imolorhe
Copy link
Collaborator

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:

  • deleted unused (old) json-completion.ts file
  • created the DocumentParser type and moved parsers into a separate directory
  • added loglevel for better log tracing (logs now point to the file the logs come from as opposed to debug.ts)

Copy link

changeset-bot bot commented Jun 20, 2024

🦋 Changeset detected

Latest commit: c04ef4f

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

Copy link

netlify bot commented Jun 20, 2024

Deploy Preview for codemirror-json-schema ready!

Name Link
🔨 Latest commit c04ef4f
🔍 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.

@imolorhe imolorhe requested a review from acao June 20, 2024 04:33
@imolorhe imolorhe marked this pull request as ready for review June 20, 2024 04:33
@imolorhe imolorhe linked an issue Jun 20, 2024 that may be closed by this pull request
@acao
Copy link
Collaborator

acao commented Jun 23, 2024

oh I love this!

@acao
Copy link
Collaborator

acao commented Jun 23, 2024

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

@imolorhe
Copy link
Collaborator Author

@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
Copy link
Collaborator

acao commented Jun 23, 2024

@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

@acao acao merged commit 4fd7cc6 into main Jun 23, 2024
6 checks passed
@acao acao deleted the imolorhe/get-schema-by-data-context branch June 23, 2024 16:59
@github-actions github-actions bot mentioned this pull request Jun 23, 2024
imolorhe pushed a commit that referenced this pull request Nov 16, 2024
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## [email protected]

### Patch Changes

- [#133](#133)
[`4fd7cc6`](4fd7cc6)
Thanks [@imolorhe](https://github.com/imolorhe)! - Get sub schema using
parsed data for additional context

- [#137](#137)
[`29e2da5`](29e2da5)
Thanks [@xdavidwu](https://github.com/xdavidwu)! - Fix description
markdown rendering in completion

- [#144](#144)
[`ef7f336`](ef7f336)
Thanks [@imolorhe](https://github.com/imolorhe)! - updated to use fine
grained shiki bundle

- [#139](#139)
[`bfbe613`](bfbe613)
Thanks [@NickTomlin](https://github.com/NickTomlin)! - Move non
essential packages to devDependencies

- [#140](#140)
[`bceace2`](bceace2)
Thanks [@NickTomlin](https://github.com/NickTomlin)! - Add
CONTRIBUTING.md file

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
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.

The library ignores conditional schema structure
2 participants