-
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
Handle more parsing cases (int and str formats, additional props: fix #10, #11 and #13) #12
Open
smondet
wants to merge
16
commits into
ahrefs:master
Choose a base branch
from
smondet:smondet-I10-enum-int-format
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+238
−55
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ff87a53
Add the `"enum"` int-format
smondet 0851948
Add `"field-mask"` format
smondet e795852
Make `"additionalProperties"` “boolable”
smondet 8c9edad
Add the `"bytes"` str-format
smondet b35ddbd
Handle empty objects
smondet ce6759d
Add options `--skip-doc` and `--protect-against-duplicates`
smondet 51a30ed
Add option `--only-matching` to limit output
smondet 42755ed
Add missing types (a.k.a. `json`) as comments
smondet abd931e
Add option `--avoid-dangling-refs`
smondet dcf1757
Add option `--json-ocaml-type Module:type`
smondet ed9925e
Make `from` Vs `module` keyword also parametrizable
smondet e93bb6b
Update lib/generator.ml
smondet 2dfb183
Remove more `Printf` module paths
smondet c5822da
Make generated comment more useful
smondet 174a1e6
Update tests
smondet bf3888a
Update README and changelog
smondet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,13 +12,13 @@ module Input_format = struct | |
let all = [ JSONSchema; OpenAPI ] | ||
end | ||
|
||
let generate_atd input_format paths = | ||
let generate_atd state input_format paths = | ||
let generate = | ||
match input_format with | ||
| Input_format.JSONSchema -> Generator.make_atd_of_jsonschema | ||
| OpenAPI -> Generator.make_atd_of_openapi | ||
| Input_format.JSONSchema -> Generator.make_atd_of_jsonschema ~state | ||
| OpenAPI -> Generator.make_atd_of_openapi ~state | ||
in | ||
print_endline (Generator.base (String.concat " " (List.map Filename.basename paths))); | ||
print_endline (Generator.base state (String.concat " " (List.map Filename.basename paths))); | ||
let root = | ||
match paths with | ||
| [ _ ] -> `Default | ||
|
@@ -44,8 +44,42 @@ let input_format_term = | |
|
||
let main = | ||
let doc = "Generate an ATD file from a list of JSON Schema / OpenAPI document" in | ||
let state_term = | ||
Term.( | ||
const (fun skip_doc pad toplevel_types avoid_dangling_refs json_ocaml_type -> | ||
Generator. | ||
{ | ||
with_doc = not skip_doc; | ||
protect_against_duplicates = (if pad then Some (ref []) else None); | ||
toplevel_types; | ||
avoid_dangling_refs; | ||
json_ocaml_type; | ||
} | ||
) | ||
$ Arg.(value (flag (info [ "skip-doc" ] ~doc:"Skip documentation annotations."))) | ||
$ Arg.(value (flag (info [ "protect-against-duplicates" ] ~doc:"Make sure no duplicate types are generated."))) | ||
$ (const (function | ||
| [] -> `All | ||
| some -> `Only some | ||
) | ||
$ Arg.( | ||
value (opt_all string [] (info [ "only-matching" ] ~docv:"REGEXP" ~doc:"Only output types matching REGEXP.")) | ||
) | ||
) | ||
$ Arg.(value (flag (info [ "avoid-dangling-refs" ] ~doc:"Convert dangling refs to json."))) | ||
$ Arg.( | ||
let keyword = enum [ "module", `Module; "from", `From ] in | ||
value | ||
(opt (t3 ~sep:':' keyword string string) Generator.default_state.json_ocaml_type | ||
(info [ "json-ocaml-type" ] ~docv:"KEYWORD:MODULE.PATH:TYPE-NAME" | ||
~doc:"Use an alternate Mod.type for `json`, e.g. from:My_mod.Submod:json_type." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is useful 👍 |
||
) | ||
) | ||
) | ||
) | ||
in | ||
let paths = Arg.(non_empty & pos_all file [] & info [] ~docv:"FILES" ~doc) in | ||
let term = Term.(const generate_atd $ input_format_term $ paths) in | ||
let term = Term.(const generate_atd $ state_term $ input_format_term $ paths) in | ||
let info = Cmd.info "jsonschema2atd" ~doc ~version:(Version.get ()) in | ||
Cmd.v info term | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 thinking this is a nice addition, thank you @smondet
Could you please add also tests for this one and mention it in the doc?