postman-open-technologies / gsoc-2022

This is a working area for Google Summer of Code 2022.
Apache License 2.0
4 stars 0 forks source link

JSON Schema Explainer (And AST) #17

Open Relequestual opened 2 years ago

Relequestual commented 2 years ago

Summary

Much like regular expression, JSON Schema has features that are easy to understand, and some which require looking up references or using tools to understand. Regular expression has tools like https://regex101.com which provides a way to easily understand and digest what the regular expression is doing and what each part of the regex actually means. JSON Schema has no such tool.

A solution should be two fold:

Even something as simple as identifying which objects are subschemas and which are not will help.

Project Duration: 175 hours (Maybe? Finding it hard to judge)

Use Case

An AST from JSON Schema that can be used by a front end to explain what a JSON Schema does, also has the ability to be used by other applications to build in such utility. A web base interactive UI to process the resutling AST is not only useful to schema authors and debuggers, but also proves evidence that the AST provides enough value.

Knowledge Required

Javascript, node, NPM/Yarn, React/Vue, AST, JSON Schema (preferable).

jviotti commented 2 years ago

Great proposal @Relequestual ! I'm super excited to see something like this come to life.

Create an Abstract Syntax Tree (AST) of any given JSON Schema

As a side thought, we should design the AST in a way that also forms the basis for advanced JSON Schema syntax highlighting. What do you think?

Use the AST to create an interactive web based application which can explain different parts of a schema.

You can even show the JSON Schema and the matching instance side by side and when you hover on i.e. a subschema, you can see specifically which part of the document is taking into account, and even which keywords are being taken into account.

jviotti commented 2 years ago

I think this is one instance of a larger and very interesting problem: creating an expressive AST out of JSON Schema is the core to solve many of the static analysis problems showing up on related tooling:

And probably more. Most of these tools would re-invent the static analysis wheel in some way or another, so having everything on top a unified AST definition would help a lot.

jviotti commented 2 years ago

I think the key is the push back as much metadata about the schema that i.e. validators typically know when evaluating the schema into the AST. For example, the AST for a specific node can contain things like:

Then, if you i.e. know there a specific contains keyword is in the schema, the path where it must me matched in the instance, the fact that is an assertion, and that it is the contains keyword from the validation vocabulary, then you can easily write rules to explain the meaning in the web-app, highlight the corresponding parts in the schema and the document, etc.

jviotti commented 2 years ago

Framing my specific use case on top of the concept of an AST, I would need to: