Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
[OCaml] new client generator #3446
#1159 Add OCaml client code generation support
This PR answers #1159 and adds OCaml Client code generation to openapi-generator. The generated OCaml project relies on the dune tool for the build process and uses :
It supports headers params, path params, query params, form params and body params. It currently has no support for authentication, nor file upload.
It generates one model file per OAS definition except for OAS enum definitions for which no model file is generated. Enums are treated globally and are all generated in a enums.ml file that contains one type per distinct enumeration present in the input file, even for enumerations that are not proper definitions but just local restrictions on a string parameter of an operation.
Note that generating one model file per OAS definition will work as long as there are no mutually recursive OAS definitions in the input file. Otherwise the generated OCaml code will not compile since it will generate mutually recursive compilation units which is not supported by the language.
For APIs files, both an implementation (.ml) and an interface (.mli) files are generated.
The command to compile the lib once all the tools (opam first then dune through opam is the easiest path) and dependencies (through opam as well) are installed is :
at the root of the generated code directory.
I'll add a README pointing to installation instructions of the tools and dependencies next week. There is an example program using the library committed in the repository in the samples/client/petstore/ocaml-client/bin directory. It's called test.ml and has an accompanying dune build file. I'll clean it up and reference it in the README.
Regarding merging to master, it can be merged without any risk since it's all new code and no existing classes have been modified by this PR but I think proper handling of response codes should be added before it's really useful to anyone. So maybe it's best to wait a bit to save some reviewing work ?
Do I need to run other commands in order to install those libraries locally?
Yes indeed. You need to install the dependencies. opam install ppx_deriving_yojson cohttp ppx_deriving.std cohttp-lwt-unix That should be enough. There is an opam search command in case you need to find out the name of a package. Le dim. 28 juil. 2019 à 05:25, William Cheng <firstname.lastname@example.org> a écrit :…
Tried running dune build locally and I got: ➜ ocaml-client git:(cgensoul-ocaml-client) dune build File "dune", line 6, characters 18-33: 6 | (libraries str cohttp-lwt-unix lwt yojson ppx_deriving_yojson.runtime) ^^^^^^^^^^^^^^^ Error: Library "cohttp-lwt-unix" not found. Hint: try: dune external-lib-deps --missing @@default File "dune", line 7, characters 20-39: 7 | (preprocess (pps ppx_deriving_yojson ppx_deriving.std)) ^^^^^^^^^^^^^^^^^^^ Error: Library "ppx_deriving_yojson" not found. Hint: try: dune external-lib-deps --missing @@default Do I need to run other commands in order to install those libraries locally? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#3446?email_source=notifications&email_token=AMWCGNXAYM46KJOQXE5SYULQBUGT5A5CNFSM4IGSCA62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD26WSOA#issuecomment-515729720>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AMWCGNSA322G5UNZ22XPNWDQBUGT5ANCNFSM4IGSCA6Q> .
Ya that was my intention. Le dim. 28 juil. 2019 à 15:40, William Cheng <email@example.com> a écrit :…
Thanks for the tips. It works for me after I run opam install ppx_deriving_yojson cohttp ppx_deriving cohttp-lwt-unix (wihtout .std) I would recommend including the opam install command in the readme as well. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#3446?email_source=notifications&email_token=AMWCGNQ5SUCPI2SSF5ZCBEDQBWOV5A5CNFSM4IGSCA62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2665BQ#issuecomment-515763846>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AMWCGNTM7W5IT6NDGI2J4CDQBWOV5ANCNFSM4IGSCA6Q> .
Jul 28, 2019
Yes my tweeter account is @cgensoul. Le dim. 28 juil. 2019 à 15:51, William Cheng <firstname.lastname@example.org> a écrit :…
@cgensoul <https://github.com/cgensoul> thanks for the new generator. Do you have a Twitter account so that I can tag you in my tweet to promote the new generator? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#3446?email_source=notifications&email_token=AMWCGNWNPN2TK43OQPHNPCLQBWP6DA5CNFSM4IGSCA62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD267DMA#issuecomment-515764656>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AMWCGNQAIUN7GDZTMGJ7V6LQBWP6DANCNFSM4IGSCA6Q> .
referenced this pull request
Aug 1, 2019
@cgensoul thanks for the PR, which has been included in the 4.1.0 release: https://twitter.com/oas_generator/status/1160000504455319553