nickel-lang / json-schema-to-nickel

Convert JSON schemas into Nickel contracts
Apache License 2.0
28 stars 0 forks source link

Expose the intermediate schemas #86

Open thufschmitt opened 1 month ago

thufschmitt commented 1 month ago

Since the schemas can easily be quite convoluted (with a lot of oneOf in particular), it's hard for Nickel to output good error messages when things go wrong, and easy for the LSP to get lost. To mitigate that, it would be nice to be able to add some contract annotations to intermediate nodes in a config. However, json-schema-to-nickel only exposes the toplevel schema, and there's no way to access the sub-schemas.

As a concrete example: I'd like to annotate this snippet to tell Nickel that it's of type normalJob, but this isn't exposed by the generated code.

What I would like

Expose all the items from the definitions or $defs field of the schema, so that they can be accessed from client-code.

yannham commented 1 month ago

So, if I understand correctly, you want to change the current output

let internal_definitions = ...defns... in
...schema def...

to something like

{
  definitions = ...defns...,
  Schema = ...schema def...
}

?

thufschmitt commented 1 month ago

I think so, yes

yannham commented 1 month ago

I wonder if that should be the default, or just a command line argument.

thufschmitt commented 1 month ago

Mh, good question :thinking:

Maybe a CLI flag would make sense, indeed. I guess the most common cases won't care about that