-
Notifications
You must be signed in to change notification settings - Fork 2
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
dojo quick changes #5
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thank you 👍
| `String s -> s | ||
| value -> | ||
failwith | ||
(sprintf "Invalid value %s in string enum %s" (Yojson.Basic.to_string value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 this check could be useful
let root = | ||
match root with | ||
| `Default -> None | ||
| `Per_file -> Some (path |> Filename.basename |> Filename.remove_extension |> Utils.sanitize_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: wondering if it does make sense to use filename for root time always (even if only one input scheme file passed)
I used jsonscheme2atd
for openapi files only, so I didn't have issues with root type name. @Khady if you think it is handy, feel free to change the default root
type to filename
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also it would simplify code (we can get rid of Default
and Per_file
variants)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went back and forth on this one. My problem with file names is that it can become very noisy when they are long. No strong opinion at this time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @Khady 👏 Feel free to merge the PR
Having LSP support (through odoc annotations) is super useful for complex schemas (like grafana types) 🎉
There are cases which won't work, for example if 2 of the schemas have types named the same. But I'm not sure how to fix that without creating too much noise.
I guess the relatively easy way would be to use global input_toplevel_schemas
to resolve typename collisions (convert it to map probably? with input filenames as a key). Please open an issue if you face the this problem in real world usage
the problem with this solution is that one needs to create some kind of connection between the http uri references in the schemas and the actual json files that are passed to the cli. I was scared that doing it explicitly through the cli would make the invocations too noisy. We could build something automatic based on the |
let uri, pointer = | ||
match String.split_on_char '#' ref with | ||
| [ uri; pointer ] -> uri, Some pointer | ||
| [ uri ] -> uri, None | ||
| _ -> failwith (sprintf "Unsupported remote ref value: %s. The URI contains multiple '#'." ref) | ||
in | ||
let name_of_path path = | ||
match path |> String.split_on_char '/' |> List.rev |> List.hd with | ||
| exception _ -> failwith (sprintf "Unsupported ref value: %s" ref) | ||
| name -> name | ||
in | ||
match pointer with | ||
| None -> name_of_path uri | ||
| Some pointer -> | ||
match String.split_on_char '/' pointer with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing this is not completely correct. If the pointer is to a subschema then the name shouldn't be just the last part of the pointer
This PR is based on the work done during the recent dojo. It should probably have been divided into different pull requests, as commits are mostly independent from each other. Most of the changes are relatively small. 2 of them could be controversial though:
Those two features kind of go hand in hand and are going in the same direction.
I was trying jsonschema2atd on schemas that have http uri references to other types. In the past I had to update all of those by hands to turn them into
#/$defs/typename
. Now those references don't trigger an error. But it means that we can generate a atd file that wouldn't compile without manual fixes.The generation from a batch of schemas helps with that, as I now can work with 3 schemas that related to each other. Schema A has http references to schemas B and C. So I can download those 3 files and then run
jsonschema2atd --format=jsonschema c.json b.json a.json
. There are cases which won't work, for example if 2 of the schemas have types named the same. But I'm not sure how to fix that without creating too much noise.