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

Import JSON Schemas #14

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft

Import JSON Schemas #14

wants to merge 17 commits into from

Conversation

timothee-haudebourg
Copy link
Collaborator

@timothee-haudebourg timothee-haudebourg commented Apr 4, 2022

The PR implements the JSON Schema import feature. A first version of this feature will probably be merged before the full semantics of JSON Schema can be capture, mainly because it is not possible to express some of the JSON Schema constraints in TreeLDR for now.

Progress

  • $id
  • $ref
  • Read schema type
  • Generate TreeLDR structure layout on properties
  • Generate literal layout on const
  • Generate regular expression layout on pattern
  • Generate native layout on format (for formats already known by TreeLDR)
    • Add treeldr:native property to declare native layouts.
    • Handle the treeldr:native property in the compiler
  • Generate enumeration layout on oneOf.
  • Handle required properties constraint.
  • Handle array item schema constraint using schema:multipleValues
  • Throw a proper error for unsupported JSON Schema features.
  • Add an option in the command line interface to load JSON Schemas.

Unresolved questions

  • Should the generated layout be associated to a TreeLDR type (and if so, how), or should TreeLDR accept "orphan" layouts (not associated to any type, and thus without semantics).
  • TreeLDR require for every layout and enumeration variant to be named, so it can generate code in any target language. How do we define the name of a JSON Schema?

@timothee-haudebourg
Copy link
Collaborator Author

It is now possible to import basic JSON Schema as "orphan" TreeLDR layouts (layouts that are not associated to any type). Such an orphan layout can be used to generate code in the target language, but cannot be reasoned with on a semantic level. This means that translation from/to an orphan layout is impossible. Generating a JSON-LD context from an orphan layout is impossible (will generate an empty context).

@timothee-haudebourg
Copy link
Collaborator Author

For now, a name for the schema is inferred from the $id value, or the title value.

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.

None yet

1 participant