forked from loafle/openapi-generator-original
[OCaml] various enhancements (#3483)
* add ocaml template creator * various enhancement to ocaml generator * update instruction * update doc * remove readme * add back readme
This commit is contained in:
@@ -59,7 +59,7 @@ OpenAPI Generator allows generation of API client libraries (SDK generation), se
|
||||
|
||||
| | Languages/Frameworks |
|
||||
|-|-|
|
||||
**API clients** | **ActionScript**, **Ada**, **Apex**, **Bash**, **C**, **C#** (.net 2.0, 3.5 or later), **C++** (cpp-restsdk, Qt5, Tizen), **Clojure**, **Dart (1.x, 2.x)**, **Elixir**, **Elm**, **Eiffel**, **Erlang**, **Go**, **Groovy**, **Haskell** (http-client, Servant), **Java** (Jersey1.x, Jersey2.x, OkHttp, Retrofit1.x, Retrofit2.x, Feign, RestTemplate, RESTEasy, Vertx, Google API Client Library for Java, Rest-assured, Spring 5 Web Client), **Kotlin**, **Lua**, **Node.js/JavaScript** (ES5, ES6, AngularJS with Google Closure Compiler annotations, Flow types) **Objective-C**, **Perl**, **PHP**, **PowerShell**, **Python**, **R**, **Ruby**, **Rust** (rust, rust-server), **Scala** (akka, http4s, scalaz, swagger-async-httpclient), **Swift** (2.x, 3.x, 4.x), **Typescript** (AngularJS, Angular (2.x - 7.x), Aurelia, Axios, Fetch, Inversify, jQuery, Node, Rxjs)
|
||||
**API clients** | **ActionScript**, **Ada**, **Apex**, **Bash**, **C**, **C#** (.net 2.0, 3.5 or later), **C++** (cpp-restsdk, Qt5, Tizen), **Clojure**, **Dart (1.x, 2.x)**, **Elixir**, **Elm**, **Eiffel**, **Erlang**, **Go**, **Groovy**, **Haskell** (http-client, Servant), **Java** (Jersey1.x, Jersey2.x, OkHttp, Retrofit1.x, Retrofit2.x, Feign, RestTemplate, RESTEasy, Vertx, Google API Client Library for Java, Rest-assured, Spring 5 Web Client), **Kotlin**, **Lua**, **Node.js/JavaScript** (ES5, ES6, AngularJS with Google Closure Compiler annotations, Flow types), **Objective-C**, **OCaml**, **Perl**, **PHP**, **PowerShell**, **Python**, **R**, **Ruby**, **Rust** (rust, rust-server), **Scala** (akka, http4s, scalaz, swagger-async-httpclient), **Swift** (2.x, 3.x, 4.x), **Typescript** (AngularJS, Angular (2.x - 7.x), Aurelia, Axios, Fetch, Inversify, jQuery, Node, Rxjs)
|
||||
**Server stubs** | **Ada**, **C#** (ASP.NET Core, NancyFx), **C++** (Pistache, Restbed, Qt5 QHTTPEngine), **Erlang**, **F#** (Giraffe), **Go** (net/http, Gin), **Haskell** (Servant), **Java** (MSF4J, Spring, Undertow, JAX-RS: CDI, CXF, Inflector, RestEasy, Play Framework, [PKMST](https://github.com/ProKarma-Inc/pkmst-getting-started-examples)), **Kotlin** (Spring Boot, Ktor), **PHP** (Laravel, Lumen, Slim, Silex, [Symfony](https://symfony.com/), [Zend Expressive](https://github.com/zendframework/zend-expressive)), **Python** (Flask), **NodeJS**, **Ruby** (Sinatra, Rails5), **Rust** (rust-server), **Scala** ([Finch](https://github.com/finagle/finch), [Lagom](https://github.com/lagom/lagom), [Play](https://www.playframework.com/), Scalatra)
|
||||
**API documentation generators** | **HTML**, **Confluence Wiki**
|
||||
**Configuration files** | [**Apache2**](https://httpd.apache.org/)
|
||||
@@ -680,6 +680,7 @@ Here is a list of template creators:
|
||||
* JMeter: @davidkiss
|
||||
* Kotlin: @jimschubert [:heart:](https://www.patreon.com/jimschubert)
|
||||
* Lua: @daurnimator
|
||||
* OCaml: @cgensoul
|
||||
* Perl: @wing328 [:heart:](https://www.patreon.com/wing328)
|
||||
* PHP (Guzzle): @baartosz
|
||||
* PowerShell: @beatcracker
|
||||
|
||||
@@ -26,9 +26,9 @@ then
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DdebugOperations -DloggerPath=conf/log4j.properties"
|
||||
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
|
||||
args="generate -t modules/openapi-generator/src/main/resources/ocaml-client -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g ocaml-client -o samples/client/petstore/ocaml-client --additional-properties packageName=petstore_client $@"
|
||||
args="generate -t modules/openapi-generator/src/main/resources/ocaml -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g ocaml -o samples/client/petstore/ocaml --additional-properties packageName=petstore_client $@"
|
||||
|
||||
echo "java ${JAVA_OPTS} -jar ${executable} ${args}"
|
||||
java $JAVA_OPTS -jar $executable $args
|
||||
10
bin/windows/ocaml-petstore.bat
Executable file
10
bin/windows/ocaml-petstore.bat
Executable file
@@ -0,0 +1,10 @@
|
||||
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g ocaml -o samples\client\petstore\ocaml
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
@@ -39,7 +39,7 @@ The following generators are available:
|
||||
- [kotlin](generators/kotlin.md)
|
||||
- [lua](generators/lua.md)
|
||||
- [objc](generators/objc.md)
|
||||
- [ocaml-client](generators/ocaml-client.md)
|
||||
- [ocaml](generators/ocaml.md)
|
||||
- [perl](generators/perl.md)
|
||||
- [php](generators/php.md)
|
||||
- [powershell](generators/powershell.md)
|
||||
|
||||
13
docs/generators/ocaml.md
Normal file
13
docs/generators/ocaml.md
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
---
|
||||
id: generator-opts-client-ocaml
|
||||
title: Config Options for ocaml
|
||||
sidebar_label: ocaml
|
||||
---
|
||||
|
||||
| Option | Description | Values | Default |
|
||||
| ------ | ----------- | ------ | ------- |
|
||||
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|
||||
|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true|
|
||||
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
|
||||
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
|
||||
@@ -59,7 +59,7 @@ public class OCamlClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "ocaml-client";
|
||||
return "ocaml";
|
||||
}
|
||||
|
||||
public String getHelp() {
|
||||
@@ -68,13 +68,13 @@ public class OCamlClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
public OCamlClientCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code/ocaml-client";
|
||||
outputFolder = "generated-code/ocaml";
|
||||
modelTemplateFiles.put("model.mustache", ".ml");
|
||||
|
||||
// default HIDE_GENERATION_TIMESTAMP to true
|
||||
hideGenerationTimestamp = Boolean.TRUE;
|
||||
|
||||
embeddedTemplateDir = templateDir = "ocaml-client";
|
||||
embeddedTemplateDir = templateDir = "ocaml";
|
||||
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
@@ -95,6 +95,7 @@ public class OCamlClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
supportingFiles.add(new SupportingFile("dune.mustache", "", "dune"));
|
||||
supportingFiles.add(new SupportingFile("dune-project.mustache", "", "dune-project"));
|
||||
supportingFiles.add(new SupportingFile("readme.mustache", "", "README.md"));
|
||||
|
||||
defaultIncludes = new HashSet<>(
|
||||
Arrays.asList(
|
||||
@@ -106,7 +107,7 @@ public class OCamlClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
"char",
|
||||
"string",
|
||||
"list"
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
languageSpecificPrimitives = new HashSet<>(
|
||||
@@ -249,7 +250,7 @@ public class OCamlClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
private void collectEnumSchemas(String parentName, String sName, Schema schema) {
|
||||
if (schema instanceof ArraySchema) {
|
||||
collectEnumSchemas(parentName, sName, ((ArraySchema)schema).getItems());
|
||||
collectEnumSchemas(parentName, sName, ((ArraySchema) schema).getItems());
|
||||
} else if (schema instanceof MapSchema && schema.getAdditionalProperties() instanceof Schema) {
|
||||
collectEnumSchemas(parentName, sName, (Schema) schema.getAdditionalProperties());
|
||||
} else if (isEnumSchema(schema)) {
|
||||
@@ -348,7 +349,7 @@ public class OCamlClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
}
|
||||
if (!hasDefName) {
|
||||
int i = 0;
|
||||
String candidate;;
|
||||
String candidate;
|
||||
while (definitiveNames.containsKey(candidate = sanitizeOCamlTypeName(nameCandidates.get(0) + "_" + i))) {
|
||||
i++;
|
||||
}
|
||||
@@ -361,7 +362,7 @@ public class OCamlClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
private void collectEnumSchemas(OpenAPI openAPI) {
|
||||
Components components = openAPI.getComponents();
|
||||
if (components != null && components.getSchemas() != null && !components.getSchemas().isEmpty()) {
|
||||
if (components != null && components.getSchemas() != null && !components.getSchemas().isEmpty()) {
|
||||
collectEnumSchemas(null, components.getSchemas());
|
||||
}
|
||||
|
||||
|
||||
35
modules/openapi-generator/src/main/resources/ocaml/readme.mustache
vendored
Normal file
35
modules/openapi-generator/src/main/resources/ocaml/readme.mustache
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
# {{{projectName}}}
|
||||
{{#appDescription}}
|
||||
{{{appDescription}}}
|
||||
{{/appDescription}}
|
||||
|
||||
This OCaml package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
|
||||
|
||||
- API version: {{appVersion}}
|
||||
- Package version: {{packageVersion}}
|
||||
{{^hideGenerationTimestamp}}
|
||||
- Build date: {{generatedDate}}
|
||||
{{/hideGenerationTimestamp}}
|
||||
- Build package: {{generatorClass}}
|
||||
{{#infoUrl}}
|
||||
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
|
||||
{{/infoUrl}}
|
||||
|
||||
## Requirements.
|
||||
|
||||
OCaml 4.x
|
||||
|
||||
## Installation
|
||||
|
||||
Please run the following commands to build the package `{{{packageName}}}`:
|
||||
|
||||
```sh
|
||||
opam install ppx_deriving_yojson cohttp ppx_deriving cohttp-lwt-unix
|
||||
eval $(opam env)
|
||||
dune build
|
||||
```
|
||||
|
||||
## Getting Started
|
||||
|
||||
TODO
|
||||
|
||||
23
samples/client/petstore/ocaml/.openapi-generator-ignore
Normal file
23
samples/client/petstore/ocaml/.openapi-generator-ignore
Normal file
@@ -0,0 +1,23 @@
|
||||
# OpenAPI Generator Ignore
|
||||
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
|
||||
|
||||
# Use this file to prevent files from being overwritten by the generator.
|
||||
# The patterns follow closely to .gitignore or .dockerignore.
|
||||
|
||||
# As an example, the C# client generator defines ApiClient.cs.
|
||||
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
|
||||
#ApiClient.cs
|
||||
|
||||
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
|
||||
#foo/*/qux
|
||||
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
|
||||
|
||||
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
|
||||
#foo/**/qux
|
||||
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
|
||||
|
||||
# You can also negate patterns with an exclamation (!).
|
||||
# For example, you can ignore all files in a docs folder with the file extension .md:
|
||||
#docs/*.md
|
||||
# Then explicitly reverse the ignore rule for a single file:
|
||||
#!docs/README.md
|
||||
1
samples/client/petstore/ocaml/.openapi-generator/VERSION
Normal file
1
samples/client/petstore/ocaml/.openapi-generator/VERSION
Normal file
@@ -0,0 +1 @@
|
||||
4.1.0-SNAPSHOT
|
||||
26
samples/client/petstore/ocaml/README.md
Normal file
26
samples/client/petstore/ocaml/README.md
Normal file
@@ -0,0 +1,26 @@
|
||||
#
|
||||
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
|
||||
This OCaml package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
|
||||
|
||||
- API version: 1.0.0
|
||||
- Package version: 1.0.0
|
||||
- Build package: org.openapitools.codegen.languages.OCamlClientCodegen
|
||||
|
||||
## Requirements.
|
||||
|
||||
OCaml 4.x
|
||||
|
||||
## Installation
|
||||
|
||||
Please run the following commands to build the package `petstore_client`:
|
||||
|
||||
```sh
|
||||
opam install ppx_deriving_yojson cohttp ppx_deriving cohttp-lwt-unix
|
||||
dune build
|
||||
```
|
||||
|
||||
## Getting Started
|
||||
|
||||
TODO
|
||||
|
||||
9
samples/client/petstore/ocaml/dune
Normal file
9
samples/client/petstore/ocaml/dune
Normal file
@@ -0,0 +1,9 @@
|
||||
(include_subdirs unqualified)
|
||||
(library
|
||||
(name petstore_client)
|
||||
(public_name petstore_client)
|
||||
(flags (:standard -w -27))
|
||||
(libraries str cohttp-lwt-unix lwt yojson ppx_deriving_yojson.runtime)
|
||||
(preprocess (pps ppx_deriving_yojson ppx_deriving.std))
|
||||
(wrapped true)
|
||||
)
|
||||
2
samples/client/petstore/ocaml/dune-project
Normal file
2
samples/client/petstore/ocaml/dune-project
Normal file
@@ -0,0 +1,2 @@
|
||||
(lang dune 1.10)
|
||||
(name petstore_client)
|
||||
15
samples/client/petstore/ocaml/petstore_client.opam
Normal file
15
samples/client/petstore/ocaml/petstore_client.opam
Normal file
@@ -0,0 +1,15 @@
|
||||
opam-version: "2.0"
|
||||
name: "petstore_client"
|
||||
version: "1.0.0"
|
||||
synopsis: ""
|
||||
description: """
|
||||
Longer description
|
||||
"""
|
||||
maintainer: "Name <email>"
|
||||
authors: "Name <email>"
|
||||
license: ""
|
||||
homepage: ""
|
||||
bug-reports: ""
|
||||
dev-repo: ""
|
||||
depends: [ "ocaml" "ocamlfind" ]
|
||||
build: ["dune" "build" "-p" name]
|
||||
80
samples/client/petstore/ocaml/src/apis/pet_api.ml
Normal file
80
samples/client/petstore/ocaml/src/apis/pet_api.ml
Normal file
@@ -0,0 +1,80 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
let add_pet body =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/pet" in
|
||||
let headers = Request.default_headers in
|
||||
let body = Request.write_json_body Pet.to_yojson body in
|
||||
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
|
||||
Request.handle_unit_response resp
|
||||
|
||||
let delete_pet pet_id api_key =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/pet/{petId}" in
|
||||
let headers = Request.default_headers in
|
||||
let headers = Cohttp.Header.add headers "api_key" (api_key) in
|
||||
let uri = Request.replace_path_param uri "petId" (Int64.to_string pet_id) in
|
||||
Cohttp_lwt_unix.Client.call `DELETE uri ~headers >>= fun (resp, body) ->
|
||||
Request.handle_unit_response resp
|
||||
|
||||
let find_pets_by_status status =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/pet/findByStatus" in
|
||||
let headers = Request.default_headers in
|
||||
let uri = Uri.add_query_param uri ("status", List.map Enums.show_pet_status status) in
|
||||
Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) ->
|
||||
Request.read_json_body_as_list_of (JsonSupport.unwrap Pet.of_yojson) resp body
|
||||
|
||||
let find_pets_by_tags tags =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/pet/findByTags" in
|
||||
let headers = Request.default_headers in
|
||||
let uri = Uri.add_query_param uri ("tags", tags) in
|
||||
Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) ->
|
||||
Request.read_json_body_as_list_of (JsonSupport.unwrap Pet.of_yojson) resp body
|
||||
|
||||
let get_pet_by_id pet_id =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/pet/{petId}" in
|
||||
let headers = Request.default_headers in
|
||||
let uri = Request.replace_path_param uri "petId" (Int64.to_string pet_id) in
|
||||
Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) ->
|
||||
Request.read_json_body_as (JsonSupport.unwrap Pet.of_yojson) resp body
|
||||
|
||||
let update_pet body =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/pet" in
|
||||
let headers = Request.default_headers in
|
||||
let body = Request.write_json_body Pet.to_yojson body in
|
||||
Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) ->
|
||||
Request.handle_unit_response resp
|
||||
|
||||
let update_pet_with_form pet_id name status =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/pet/{petId}" in
|
||||
let headers = Request.default_headers in
|
||||
let uri = Request.replace_path_param uri "petId" (Int64.to_string pet_id) in
|
||||
let body = Request.init_form_encoded_body () in
|
||||
let body = Request.add_form_encoded_body_param body ("name", name) in
|
||||
let body = Request.add_form_encoded_body_param body ("status", status) in
|
||||
let body = Request.finalize_form_encoded_body body in
|
||||
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
|
||||
Request.handle_unit_response resp
|
||||
|
||||
let upload_file pet_id additional_metadata file =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/pet/{petId}/uploadImage" in
|
||||
let headers = Request.default_headers in
|
||||
let uri = Request.replace_path_param uri "petId" (Int64.to_string pet_id) in
|
||||
let body = Request.init_form_encoded_body () in
|
||||
let body = Request.add_form_encoded_body_param body ("additional_metadata", additional_metadata) in
|
||||
let body = Request.add_form_encoded_body_param body ("file", file) in
|
||||
let body = Request.finalize_form_encoded_body body in
|
||||
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
|
||||
Request.read_json_body_as (JsonSupport.unwrap Api_response.of_yojson) resp body
|
||||
|
||||
15
samples/client/petstore/ocaml/src/apis/pet_api.mli
Normal file
15
samples/client/petstore/ocaml/src/apis/pet_api.mli
Normal file
@@ -0,0 +1,15 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
val add_pet : Pet.t -> unit Lwt.t
|
||||
val delete_pet : int64 -> string -> unit Lwt.t
|
||||
val find_pets_by_status : Enums.pet_status list -> Pet.t list Lwt.t
|
||||
val find_pets_by_tags : string list -> Pet.t list Lwt.t
|
||||
val get_pet_by_id : int64 -> Pet.t Lwt.t
|
||||
val update_pet : Pet.t -> unit Lwt.t
|
||||
val update_pet_with_form : int64 -> string -> string -> unit Lwt.t
|
||||
val upload_file : int64 -> string -> string -> Api_response.t Lwt.t
|
||||
38
samples/client/petstore/ocaml/src/apis/store_api.ml
Normal file
38
samples/client/petstore/ocaml/src/apis/store_api.ml
Normal file
@@ -0,0 +1,38 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
let delete_order order_id =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/store/order/{orderId}" in
|
||||
let headers = Request.default_headers in
|
||||
let uri = Request.replace_path_param uri "orderId" (order_id) in
|
||||
Cohttp_lwt_unix.Client.call `DELETE uri ~headers >>= fun (resp, body) ->
|
||||
Request.handle_unit_response resp
|
||||
|
||||
let get_inventory () =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/store/inventory" in
|
||||
let headers = Request.default_headers in
|
||||
Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) ->
|
||||
Request.read_json_body_as_map_of (JsonSupport.to_int32) resp body
|
||||
|
||||
let get_order_by_id order_id =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/store/order/{orderId}" in
|
||||
let headers = Request.default_headers in
|
||||
let uri = Request.replace_path_param uri "orderId" (Int64.to_string order_id) in
|
||||
Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) ->
|
||||
Request.read_json_body_as (JsonSupport.unwrap Order.of_yojson) resp body
|
||||
|
||||
let place_order body =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/store/order" in
|
||||
let headers = Request.default_headers in
|
||||
let body = Request.write_json_body Order.to_yojson body in
|
||||
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
|
||||
Request.read_json_body_as (JsonSupport.unwrap Order.of_yojson) resp body
|
||||
|
||||
11
samples/client/petstore/ocaml/src/apis/store_api.mli
Normal file
11
samples/client/petstore/ocaml/src/apis/store_api.mli
Normal file
@@ -0,0 +1,11 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
val delete_order : string -> unit Lwt.t
|
||||
val get_inventory : unit -> (string * int32) list Lwt.t
|
||||
val get_order_by_id : int64 -> Order.t Lwt.t
|
||||
val place_order : Order.t -> Order.t Lwt.t
|
||||
72
samples/client/petstore/ocaml/src/apis/user_api.ml
Normal file
72
samples/client/petstore/ocaml/src/apis/user_api.ml
Normal file
@@ -0,0 +1,72 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
let create_user body =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/user" in
|
||||
let headers = Request.default_headers in
|
||||
let body = Request.write_json_body User.to_yojson body in
|
||||
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
|
||||
Request.handle_unit_response resp
|
||||
|
||||
let create_users_with_array_input body =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/user/createWithArray" in
|
||||
let headers = Request.default_headers in
|
||||
let body = Request.write_json_body (JsonSupport.of_list_of User.to_yojson) body in
|
||||
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
|
||||
Request.handle_unit_response resp
|
||||
|
||||
let create_users_with_list_input body =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/user/createWithList" in
|
||||
let headers = Request.default_headers in
|
||||
let body = Request.write_json_body (JsonSupport.of_list_of User.to_yojson) body in
|
||||
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
|
||||
Request.handle_unit_response resp
|
||||
|
||||
let delete_user username =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/user/{username}" in
|
||||
let headers = Request.default_headers in
|
||||
let uri = Request.replace_path_param uri "username" (username) in
|
||||
Cohttp_lwt_unix.Client.call `DELETE uri ~headers >>= fun (resp, body) ->
|
||||
Request.handle_unit_response resp
|
||||
|
||||
let get_user_by_name username =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/user/{username}" in
|
||||
let headers = Request.default_headers in
|
||||
let uri = Request.replace_path_param uri "username" (username) in
|
||||
Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) ->
|
||||
Request.read_json_body_as (JsonSupport.unwrap User.of_yojson) resp body
|
||||
|
||||
let login_user username password =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/user/login" in
|
||||
let headers = Request.default_headers in
|
||||
let uri = Uri.add_query_param' uri ("username", username) in
|
||||
let uri = Uri.add_query_param' uri ("password", password) in
|
||||
Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) ->
|
||||
Request.read_json_body_as (JsonSupport.to_string) resp body
|
||||
|
||||
let logout_user () =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/user/logout" in
|
||||
let headers = Request.default_headers in
|
||||
Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) ->
|
||||
Request.handle_unit_response resp
|
||||
|
||||
let update_user username body =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/user/{username}" in
|
||||
let headers = Request.default_headers in
|
||||
let uri = Request.replace_path_param uri "username" (username) in
|
||||
let body = Request.write_json_body User.to_yojson body in
|
||||
Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) ->
|
||||
Request.handle_unit_response resp
|
||||
|
||||
15
samples/client/petstore/ocaml/src/apis/user_api.mli
Normal file
15
samples/client/petstore/ocaml/src/apis/user_api.mli
Normal file
@@ -0,0 +1,15 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
val create_user : User.t -> unit Lwt.t
|
||||
val create_users_with_array_input : User.t list -> unit Lwt.t
|
||||
val create_users_with_list_input : User.t list -> unit Lwt.t
|
||||
val delete_user : string -> unit Lwt.t
|
||||
val get_user_by_name : string -> User.t Lwt.t
|
||||
val login_user : string -> string -> string Lwt.t
|
||||
val logout_user : unit -> unit Lwt.t
|
||||
val update_user : string -> User.t -> unit Lwt.t
|
||||
21
samples/client/petstore/ocaml/src/models/api_response.ml
Normal file
21
samples/client/petstore/ocaml/src/models/api_response.ml
Normal file
@@ -0,0 +1,21 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
* Schema Api_response.t : Describes the result of uploading an image resource
|
||||
*)
|
||||
|
||||
type t = {
|
||||
code: int32 option [@default None];
|
||||
_type: string option [@default None];
|
||||
message: string option [@default None];
|
||||
} [@@deriving yojson, show ];;
|
||||
|
||||
(** Describes the result of uploading an image resource *)
|
||||
let create () : t = {
|
||||
code = None;
|
||||
_type = None;
|
||||
message = None;
|
||||
}
|
||||
|
||||
19
samples/client/petstore/ocaml/src/models/category.ml
Normal file
19
samples/client/petstore/ocaml/src/models/category.ml
Normal file
@@ -0,0 +1,19 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
* Schema Category.t : A category for a pet
|
||||
*)
|
||||
|
||||
type t = {
|
||||
id: int64 option [@default None];
|
||||
name: string option [@default None];
|
||||
} [@@deriving yojson, show ];;
|
||||
|
||||
(** A category for a pet *)
|
||||
let create () : t = {
|
||||
id = None;
|
||||
name = None;
|
||||
}
|
||||
|
||||
28
samples/client/petstore/ocaml/src/models/order.ml
Normal file
28
samples/client/petstore/ocaml/src/models/order.ml
Normal file
@@ -0,0 +1,28 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
* Schema Order.t : An order for a pets from the pet store
|
||||
*)
|
||||
|
||||
type t = {
|
||||
id: int64 option [@default None];
|
||||
pet_id: int64 option [@default None];
|
||||
quantity: int32 option [@default None];
|
||||
ship_date: string option [@default None];
|
||||
(* Order Status *)
|
||||
status: Enums.status option [@default None];
|
||||
complete: bool option [@default None];
|
||||
} [@@deriving yojson, show ];;
|
||||
|
||||
(** An order for a pets from the pet store *)
|
||||
let create () : t = {
|
||||
id = None;
|
||||
pet_id = None;
|
||||
quantity = None;
|
||||
ship_date = None;
|
||||
status = None;
|
||||
complete = None;
|
||||
}
|
||||
|
||||
28
samples/client/petstore/ocaml/src/models/pet.ml
Normal file
28
samples/client/petstore/ocaml/src/models/pet.ml
Normal file
@@ -0,0 +1,28 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
* Schema Pet.t : A pet for sale in the pet store
|
||||
*)
|
||||
|
||||
type t = {
|
||||
id: int64 option [@default None];
|
||||
category: Category.t option [@default None];
|
||||
name: string;
|
||||
photo_urls: string list;
|
||||
tags: Tag.t list;
|
||||
(* pet status in the store *)
|
||||
status: Enums.pet_status option [@default None];
|
||||
} [@@deriving yojson, show ];;
|
||||
|
||||
(** A pet for sale in the pet store *)
|
||||
let create (name : string) (photo_urls : string list) : t = {
|
||||
id = None;
|
||||
category = None;
|
||||
name = name;
|
||||
photo_urls = photo_urls;
|
||||
tags = [];
|
||||
status = None;
|
||||
}
|
||||
|
||||
19
samples/client/petstore/ocaml/src/models/tag.ml
Normal file
19
samples/client/petstore/ocaml/src/models/tag.ml
Normal file
@@ -0,0 +1,19 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
* Schema Tag.t : A tag for a pet
|
||||
*)
|
||||
|
||||
type t = {
|
||||
id: int64 option [@default None];
|
||||
name: string option [@default None];
|
||||
} [@@deriving yojson, show ];;
|
||||
|
||||
(** A tag for a pet *)
|
||||
let create () : t = {
|
||||
id = None;
|
||||
name = None;
|
||||
}
|
||||
|
||||
32
samples/client/petstore/ocaml/src/models/user.ml
Normal file
32
samples/client/petstore/ocaml/src/models/user.ml
Normal file
@@ -0,0 +1,32 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
* Schema User.t : A User who is purchasing from the pet store
|
||||
*)
|
||||
|
||||
type t = {
|
||||
id: int64 option [@default None];
|
||||
username: string option [@default None];
|
||||
first_name: string option [@default None];
|
||||
last_name: string option [@default None];
|
||||
email: string option [@default None];
|
||||
password: string option [@default None];
|
||||
phone: string option [@default None];
|
||||
(* User Status *)
|
||||
user_status: int32 option [@default None];
|
||||
} [@@deriving yojson, show ];;
|
||||
|
||||
(** A User who is purchasing from the pet store *)
|
||||
let create () : t = {
|
||||
id = None;
|
||||
username = None;
|
||||
first_name = None;
|
||||
last_name = None;
|
||||
email = None;
|
||||
password = None;
|
||||
phone = None;
|
||||
user_status = None;
|
||||
}
|
||||
|
||||
30
samples/client/petstore/ocaml/src/support/enums.ml
Normal file
30
samples/client/petstore/ocaml/src/support/enums.ml
Normal file
@@ -0,0 +1,30 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type status = [
|
||||
| `Placed [@printer fun fmt _ -> Format.pp_print_string fmt "placed"] [@name "placed"]
|
||||
| `Approved [@printer fun fmt _ -> Format.pp_print_string fmt "approved"] [@name "approved"]
|
||||
| `Delivered [@printer fun fmt _ -> Format.pp_print_string fmt "delivered"] [@name "delivered"]
|
||||
] [@@deriving yojson, show { with_path = false }];;
|
||||
|
||||
let status_of_yojson json = status_of_yojson (`List [json])
|
||||
let status_to_yojson e =
|
||||
match status_to_yojson e with
|
||||
| `List [json] -> json
|
||||
| json -> json
|
||||
|
||||
type pet_status = [
|
||||
| `Available [@printer fun fmt _ -> Format.pp_print_string fmt "available"] [@name "available"]
|
||||
| `Pending [@printer fun fmt _ -> Format.pp_print_string fmt "pending"] [@name "pending"]
|
||||
| `Sold [@printer fun fmt _ -> Format.pp_print_string fmt "sold"] [@name "sold"]
|
||||
] [@@deriving yojson, show { with_path = false }];;
|
||||
|
||||
let pet_status_of_yojson json = pet_status_of_yojson (`List [json])
|
||||
let pet_status_to_yojson e =
|
||||
match pet_status_to_yojson e with
|
||||
| `List [json] -> json
|
||||
| json -> json
|
||||
55
samples/client/petstore/ocaml/src/support/jsonSupport.ml
Normal file
55
samples/client/petstore/ocaml/src/support/jsonSupport.ml
Normal file
@@ -0,0 +1,55 @@
|
||||
open Ppx_deriving_yojson_runtime
|
||||
|
||||
let unwrap to_json json =
|
||||
match to_json json with
|
||||
| Result.Ok json -> json
|
||||
| Result.Error s -> failwith s
|
||||
|
||||
let to_int json =
|
||||
match json with
|
||||
| `Int x -> x
|
||||
| `Intlit s -> int_of_string s
|
||||
| _ -> failwith "JsonSupport.to_int"
|
||||
|
||||
let to_bool json =
|
||||
match json with
|
||||
| `Bool x -> x
|
||||
| _ -> failwith "JsonSupport.to_bool"
|
||||
|
||||
let to_float json =
|
||||
match json with
|
||||
| `Float x -> x
|
||||
| _ -> failwith "JsonSupport.to_float"
|
||||
|
||||
let to_string json =
|
||||
match json with
|
||||
| `String s -> s
|
||||
| _ -> failwith "JsonSupport.to_string"
|
||||
|
||||
let to_int32 json : int32 =
|
||||
match json with
|
||||
| `Int x -> Int32.of_int x
|
||||
| `Intlit s -> Int32.of_string s
|
||||
| _ -> failwith "JsonSupport.to_int32"
|
||||
|
||||
let to_int64 json : int64 =
|
||||
match json with
|
||||
| `Int x -> Int64.of_int x
|
||||
| `Intlit s -> Int64.of_string s
|
||||
| _ -> failwith "JsonSupport.to_int64"
|
||||
|
||||
let of_int x = `Int x
|
||||
|
||||
let of_bool b = `Bool b
|
||||
|
||||
let of_float x = `Float x
|
||||
|
||||
let of_string s = `String s
|
||||
|
||||
let of_int32 x = `Intlit (Int32.to_string x)
|
||||
|
||||
let of_int64 x = `Intlit (Int64.to_string x)
|
||||
|
||||
let of_list_of of_f l = `List (List.map of_f l)
|
||||
|
||||
let of_map_of of_f l = `Assoc (List.map (fun (k, v) -> (k, of_f v)) l)
|
||||
48
samples/client/petstore/ocaml/src/support/request.ml
Normal file
48
samples/client/petstore/ocaml/src/support/request.ml
Normal file
@@ -0,0 +1,48 @@
|
||||
let api_key = ""
|
||||
let base_url = "http://petstore.swagger.io/v2"
|
||||
let default_headers = Cohttp.Header.init_with "Content-Type" "application/json"
|
||||
|
||||
let build_uri operation_path = Uri.of_string (base_url ^ operation_path)
|
||||
let write_json_body to_json payload =
|
||||
to_json payload |> Yojson.Safe.to_string ~std:true |> Cohttp_lwt.Body.of_string
|
||||
|
||||
let handle_response resp on_success_handler =
|
||||
match Cohttp_lwt.Response.status resp with
|
||||
| #Cohttp.Code.success_status -> on_success_handler ()
|
||||
| s -> failwith ("Server responded with status " ^ Cohttp.Code.(reason_phrase_of_code (code_of_status s)))
|
||||
|
||||
let handle_unit_response resp = handle_response resp (fun () -> Lwt.return ())
|
||||
|
||||
let read_json_body resp body =
|
||||
handle_response resp (fun () ->
|
||||
(Lwt.(Cohttp_lwt.Body.to_string body >|= Yojson.Safe.from_string)))
|
||||
|
||||
let read_json_body_as of_json resp body =
|
||||
Lwt.(read_json_body resp body >|= of_json)
|
||||
|
||||
let read_json_body_as_list resp body =
|
||||
Lwt.(read_json_body resp body >|= Yojson.Safe.Util.to_list)
|
||||
|
||||
let read_json_body_as_list_of of_json resp body =
|
||||
Lwt.(read_json_body_as_list resp body >|= List.map of_json)
|
||||
|
||||
let read_json_body_as_map_of of_json resp body =
|
||||
Lwt.(read_json_body resp body >|= Yojson.Safe.Util.to_assoc >|= List.map (fun (s, v) -> (s, of_json v)))
|
||||
|
||||
let replace_path_param uri param_name param_value =
|
||||
let regexp = Str.regexp (Str.quote ("{" ^ param_name ^ "}")) in
|
||||
let path = Str.global_replace regexp param_value (Uri.path uri) in
|
||||
Uri.with_path uri path
|
||||
|
||||
let init_form_encoded_body () = ""
|
||||
|
||||
let add_form_encoded_body_param params (paramName, paramValue) =
|
||||
let new_param_enc = Printf.sprintf {|%s=%s|} (Uri.pct_encode paramName) (Uri.pct_encode paramValue) in
|
||||
if params = ""
|
||||
then new_param_enc
|
||||
else Printf.sprintf {|%s&%s|} params new_param_enc
|
||||
|
||||
let add_form_encoded_body_params params (paramName, new_params) =
|
||||
add_form_encoded_body_param params (paramName, String.concat "," new_params)
|
||||
|
||||
let finalize_form_encoded_body body = Cohttp_lwt.Body.of_string body
|
||||
Reference in New Issue
Block a user