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

Synchronous validation #28

Open
Levertion opened this issue Sep 29, 2018 · 9 comments
Open

Synchronous validation #28

Levertion opened this issue Sep 29, 2018 · 9 comments
Assignees
Labels
feature-request Request for new features or functionality
Milestone

Comments

@Levertion
Copy link
Contributor

In some situations it is useful to support JSON where the set of required schemas is known before the validation is run. It appears to me, from my armchair (figure of speech) postulations, that the only required promises are in fetching schemas from a filesystem as decided by SchemaRequestService. In my case, this would be a single static schema.

However, the current api still requires that such cases happen in the infectious async world, which is not always valuable. Have you got any suggestions for how I could handle this/what changes would be required to support such a use case?

If this is out of scope, I will be forced to reimplement (using the powers vested in me by ctrl-c and ctrl-v) all of the logic in this library.

Many thanks!

Further Context:
For my project https://github.com/Levertion/mcfunction-langserver, I know that the only required schema is https://github.com/Levertion/minecraft-json-schemas/blob/master/shared/minecraft_definitions.json, which doesn't reference any external files.
As this is a language server implementation requiring JSON support, I thought that vscode-json-languageservice would be a suitable, but as my core api is synchronous, I would require large changes just to avoid this issue.

@aeschli
Copy link
Contributor

aeschli commented Sep 30, 2018

Sure, we can add a second validation API doValidate2 that requires a schema and is sync.

You want to give it a try and make a PR?

@Levertion
Copy link
Contributor Author

I'll give it a go! Thanks - I just wanted to check something like that could be useful for this library.

@Levertion
Copy link
Contributor Author

I have worked out a way to do what I want by using https://www.npmjs.com/package/synchronous-promise. This means that your library requires no changes to support my usecase because you already allow using a custom promise constructor.

I'm not going to close this issue, as a cleaner solution would be ideal, although I won't object if you wish to.

@azeemba
Copy link

azeemba commented Nov 26, 2018

I was looking into implementing this but I found something unexpected so wanted to clarify. It seems that getDiagnostics can be either called with a JSONSchema or a ResolvedSchema.
Since the former doesn't have a .error field, I am not sure how this line isn't erroring out.

Is this an issue? Or should the PR for this maintain this behavior?

@aeschli
Copy link
Contributor

aeschli commented Mar 5, 2019

Thanks @azeemba, you are correct, there's a bug. I fixed it with a72b1c0

@Levertion
Copy link
Contributor Author

I did look into this and that was what stopped me contributing - I thought there was some really complex infrastructure in place to make that work...

@aeschli aeschli added the feature-request Request for new features or functionality label Oct 14, 2019
@aeschli aeschli added this to the Backlog milestone Oct 14, 2019
@aeschli
Copy link
Contributor

aeschli commented Nov 12, 2020

Is there still demand for this or plans to work on this?

@my-tien
Copy link

my-tien commented Jun 8, 2023

Yes, so my use case is the following:
We have a monaco editor in which we do JSON validation against a given schema and additionally we want to log the diagnostics somewhere. Since the monaco editor doesn’t support simply reading out the diagnostics, we are forced to actually validate the same string again with vscode-json-languageservice.

Since at that point the schema and json string are already given, I would wish there was a simple synchronous validate(json, schema) and in my naive thinking this could be called by doValidation internally?

@my-tien
Copy link

my-tien commented Jul 24, 2023

Hi, is there any capacity to look into this issue? If I could receive some guidance I could also try to implement this in a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

4 participants