forked from loafle/openapi-generator-original
[OCaml] Added optional params support in API operations (#3568)
* Added handling of api keys in headers. * Added handling of optional arguments in api functions. * Optional header params. * Fixed a bug in path param replacement. * Relaxed deserializing of model records with @@deriving yojson { strict = false }. It allows receiving more fields in the JSon payload than declared in the OCaml record, fields not matching any record field are ignored. * Reformatted api-impl.mustache. * Generate shorter enum value names by allowing underscore character. * Cleanup of optional params generation. * Updated the OCaml samples with the latest version of the generator. * Corrected a bug encountered when generating default value for optional enum fields. * Added v3 version of the samples for the OCaml generator.
This commit is contained in:
parent
4478f42927
commit
411199bc99
@ -33,6 +33,7 @@ import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.capitalize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.escape;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
public class OCamlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@ -631,9 +632,19 @@ public class OCamlClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
return result;
|
||||
}
|
||||
|
||||
public String toEnumValueName(String name) {
|
||||
if (reservedWords.contains(name)) {
|
||||
return escapeReservedWord(name);
|
||||
} else if (((CharSequence) name).chars().anyMatch(character -> specialCharReplacements.keySet().contains("" + ((char) character)))) {
|
||||
return escape(name, specialCharReplacements, Collections.singletonList("_"), null);
|
||||
} else {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
private String ocamlizeEnumValue(String value) {
|
||||
String sanitizedValue =
|
||||
super.toVarName(value.isEmpty() ? "empty" : value)
|
||||
toEnumValueName(value.isEmpty() ? "empty" : value)
|
||||
.replace(" ", "_");
|
||||
|
||||
if (!sanitizedValue.matches("^[a-zA-Z_].*")) {
|
||||
@ -735,6 +746,9 @@ public class OCamlClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
@Override
|
||||
public String toDefaultValue(Schema p) {
|
||||
if (p.getDefault() != null) {
|
||||
if (p.getEnum() != null) {
|
||||
return ocamlizeEnumValue(p.getDefault().toString());
|
||||
}
|
||||
return p.getDefault().toString();
|
||||
} else {
|
||||
return null;
|
||||
|
@ -10,21 +10,58 @@
|
||||
|
||||
{{#operations}}
|
||||
{{#operation}}
|
||||
let {{{operationId}}} {{^hasParams}}(){{/hasParams}}{{#allParams}}{{{paramName}}}{{#hasMore}} {{/hasMore}}{{/allParams}} =
|
||||
let {{{operationId}}} {{^hasParams}}(){{/hasParams}}{{#allParams}}{{> to_param}}{{#hasMore}} {{/hasMore}}{{#-last}}{{^required}} (){{/required}}{{/-last}}{{/allParams}} =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "{{{path}}}" in
|
||||
let headers = Request.default_headers in{{#headerParams}}
|
||||
let headers = Cohttp.Header.add{{#isContainer}}_multi{{/isContainer}} headers "{{baseName}}" ({{> to_string}}{{paramName}}) in{{/headerParams}}{{#pathParams}}
|
||||
let uri = Request.replace_path_param uri "{{{baseName}}}" ({{> to_string}}{{{paramName}}}) in{{/pathParams}}{{#queryParams}}
|
||||
let uri = Uri.add_query_param{{^isListContainer}}'{{/isListContainer}} uri ("{{{baseName}}}", {{> to_string}}{{{paramName}}}) in{{/queryParams}}{{#hasAuthMethods}}{{#authMethods}}{{#isApiKey}}{{#isKeyInQuery}}
|
||||
let uri = Uri.add_query_param' uri ("{{{keyParamName}}}", Request.api_key) in{{/isKeyInQuery}}{{/isApiKey}}{{/authMethods}}{{/hasAuthMethods}}{{#bodyParams}}
|
||||
let body = Request.{{#isFreeFormObject}}write_json_body{{/isFreeFormObject}}{{#isByteArray}}write_string_body{{/isByteArray}}{{^isFreeFormObject}}{{^isByteArray}}write_as_json_body{{/isByteArray}}{{/isFreeFormObject}} {{> to_json}} {{{paramName}}} in{{/bodyParams}}{{^hasBodyParam}}{{#hasFormParams}}
|
||||
let body = Request.init_form_encoded_body () in{{/hasFormParams}}{{#formParams}}
|
||||
let body = Request.add_form_encoded_body_param{{#isContainer}}s{{/isContainer}} body ("{{{paramName}}}", {{> to_string}}{{{paramName}}}) in{{/formParams}}{{#hasFormParams}}
|
||||
let body = Request.finalize_form_encoded_body body in{{/hasFormParams}}{{/hasBodyParam}}
|
||||
Cohttp_lwt_unix.Client.call `{{{httpMethod}}} uri ~headers {{#hasBodyParam}}~body {{/hasBodyParam}}{{^hasBodyParam}}{{#hasFormParams}}~body {{/hasFormParams}}{{/hasBodyParam}}>>= fun (resp, body) ->{{^returnType}}
|
||||
Request.handle_unit_response resp{{/returnType}}{{#returnType}}
|
||||
Request.read_json_body{{#returnContainer}}{{#isListContainer}}_as_list{{/isListContainer}}{{#isMapContainer}}_as_map{{/isMapContainer}}{{#returnBaseType}}{{^vendorExtensions.x-returnFreeFormObject}}_of{{/vendorExtensions.x-returnFreeFormObject}}{{/returnBaseType}}{{/returnContainer}}{{^returnContainer}}{{#returnBaseType}}{{^vendorExtensions.x-returnFreeFormObject}}_as{{/vendorExtensions.x-returnFreeFormObject}}{{/returnBaseType}}{{/returnContainer}} {{#returnType}}{{^vendorExtensions.x-returnFreeFormObject}}({{> of_json}}){{/vendorExtensions.x-returnFreeFormObject}}{{/returnType}} resp body{{/returnType}}
|
||||
let headers = Request.default_headers in
|
||||
{{#hasAuthMethods}}
|
||||
{{#authMethods}}
|
||||
{{#isApiKey}}
|
||||
{{#isKeyInHeader}}
|
||||
let headers = Cohttp.Header.add headers "{{{keyParamName}}}" Request.api_key in
|
||||
{{/isKeyInHeader}}
|
||||
{{/isApiKey}}
|
||||
{{/authMethods}}
|
||||
{{/hasAuthMethods}}
|
||||
{{#headerParams}}
|
||||
let headers = Request.{{> to_optional_prefix}}add_header{{#isContainer}}_multi{{/isContainer}} headers "{{baseName}}" {{> to_string}} {{{paramName}}} in
|
||||
{{/headerParams}}
|
||||
{{#pathParams}}
|
||||
let uri = Request.{{> to_optional_prefix}}replace_path_param uri "{{{baseName}}}" {{> to_string}} {{{paramName}}} in
|
||||
{{/pathParams}}
|
||||
{{#queryParams}}
|
||||
let uri = Request.{{> to_optional_prefix}}add_query_param{{#isListContainer}}_list{{/isListContainer}} uri "{{{baseName}}}" {{> to_string}} {{{paramName}}} in
|
||||
{{/queryParams}}
|
||||
{{#hasAuthMethods}}
|
||||
{{#authMethods}}
|
||||
{{#isApiKey}}
|
||||
{{#isKeyInQuery}}
|
||||
let uri = Uri.add_query_param' uri ("{{{keyParamName}}}", Request.api_key) in
|
||||
{{/isKeyInQuery}}
|
||||
{{/isApiKey}}
|
||||
{{/authMethods}}
|
||||
{{/hasAuthMethods}}
|
||||
{{#bodyParams}}
|
||||
let body = Request.{{#isFreeFormObject}}write_json_body{{/isFreeFormObject}}{{#isByteArray}}write_string_body{{/isByteArray}}{{^isFreeFormObject}}{{^isByteArray}}write_as_json_body{{/isByteArray}}{{/isFreeFormObject}} {{> to_json}} {{{paramName}}} in
|
||||
{{/bodyParams}}
|
||||
{{^hasBodyParam}}
|
||||
{{#hasFormParams}}
|
||||
let body = Request.init_form_encoded_body () in
|
||||
{{/hasFormParams}}
|
||||
{{#formParams}}
|
||||
let body = Request.{{> to_optional_prefix}}add_form_encoded_body_param{{#isContainer}}_list{{/isContainer}} body "{{{paramName}}}" {{> to_string}} {{{paramName}}} in
|
||||
{{/formParams}}
|
||||
{{#hasFormParams}}
|
||||
let body = Request.finalize_form_encoded_body body in
|
||||
{{/hasFormParams}}
|
||||
{{/hasBodyParam}}
|
||||
Cohttp_lwt_unix.Client.call `{{{httpMethod}}} uri ~headers {{#hasBodyParam}}~body {{/hasBodyParam}}{{^hasBodyParam}}{{#hasFormParams}}~body {{/hasFormParams}}{{/hasBodyParam}}>>= fun (resp, body) ->
|
||||
{{^returnType}}
|
||||
Request.handle_unit_response resp
|
||||
{{/returnType}}
|
||||
{{#returnType}}
|
||||
Request.read_json_body{{#returnContainer}}{{#isListContainer}}_as_list{{/isListContainer}}{{#isMapContainer}}_as_map{{/isMapContainer}}{{#returnBaseType}}{{^vendorExtensions.x-returnFreeFormObject}}_of{{/vendorExtensions.x-returnFreeFormObject}}{{/returnBaseType}}{{/returnContainer}}{{^returnContainer}}{{#returnBaseType}}{{^vendorExtensions.x-returnFreeFormObject}}_as{{/vendorExtensions.x-returnFreeFormObject}}{{/returnBaseType}}{{/returnContainer}} {{#returnType}}{{^vendorExtensions.x-returnFreeFormObject}}({{> of_json}}){{/vendorExtensions.x-returnFreeFormObject}}{{/returnType}} resp body
|
||||
{{/returnType}}
|
||||
|
||||
{{/operation}}
|
||||
{{/operations}}
|
||||
|
@ -10,6 +10,6 @@
|
||||
|
||||
{{#operations}}
|
||||
{{#operation}}
|
||||
val {{{operationId}}} : {{^hasParams}}unit{{/hasParams}}{{#allParams}}{{#isEnum}}Enums.{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#hasMore}} -> {{/hasMore}}{{/allParams}} -> {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}unit{{/returnType}} Lwt.t
|
||||
val {{{operationId}}} : {{^hasParams}}unit{{/hasParams}}{{#allParams}}{{#required}}{{{paramName}}}{{/required}}{{^required}}{{^isBodyParam}}?{{/isBodyParam}}{{{paramName}}}{{/required}}:{{#isEnum}}Enums.{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#hasMore}} -> {{/hasMore}}{{#-last}}{{^required}} -> unit{{/required}}{{/-last}}{{/allParams}} -> {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}unit{{/returnType}} Lwt.t
|
||||
{{/operation}}
|
||||
{{/operations}}
|
||||
|
@ -16,13 +16,13 @@ type t = {
|
||||
(* {{{description}}} *)
|
||||
{{/description}}
|
||||
{{#isEnum}}
|
||||
{{{name}}}: {{^isMapContainer}}Enums.{{/isMapContainer}}{{{datatypeWithEnum}}}{{^isContainer}}{{#defaultValue}}[@default {{{defaultValue}}}]{{/defaultValue}}{{/isContainer}}{{^isContainer}}{{#required}}{{#isNullable}} option [@default None]{{/isNullable}}{{/required}}{{/isContainer}}{{^isContainer}}{{^required}} option [@default None]{{/required}}{{/isContainer}};
|
||||
{{{name}}}: {{^isMapContainer}}Enums.{{/isMapContainer}}{{{datatypeWithEnum}}}{{^isContainer}}{{#required}}{{#defaultValue}}[@default {{{defaultValue}}}]{{/defaultValue}}{{/required}}{{/isContainer}}{{^isContainer}}{{#required}}{{#isNullable}} option [@default {{#defaultValue}}Some({{{defaultValue}}}){{/defaultValue}}{{^defaultValue}}None{{/defaultValue}}]{{/isNullable}}{{/required}}{{/isContainer}}{{^isContainer}}{{^required}} option [@default {{#defaultValue}}Some({{{defaultValue}}}){{/defaultValue}}{{^defaultValue}}None{{/defaultValue}}]{{/required}}{{/isContainer}};
|
||||
{{/isEnum}}
|
||||
{{^isEnum}}
|
||||
{{{name}}}: {{{datatypeWithEnum}}}{{^isContainer}}{{#required}}{{#isNullable}} option{{/isNullable}}{{/required}}{{/isContainer}}{{^isContainer}}{{^required}} option [@default None]{{/required}}{{/isContainer}};
|
||||
{{/isEnum}}
|
||||
{{/vars}}
|
||||
} [@@deriving yojson, show ];;
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
{{#description}}
|
||||
(** {{{description}}} *)
|
||||
|
@ -2,8 +2,31 @@ let api_key = ""
|
||||
let base_url = "{{{basePath}}}"
|
||||
let default_headers = Cohttp.Header.init_with "Content-Type" "application/json"
|
||||
|
||||
let option_fold f default o =
|
||||
match o with
|
||||
| Some v -> f v
|
||||
| None -> default
|
||||
|
||||
let build_uri operation_path = Uri.of_string (base_url ^ operation_path)
|
||||
|
||||
let add_string_header headers key value =
|
||||
Cohttp.Header.add headers key value
|
||||
|
||||
let add_string_header_multi headers key values =
|
||||
Cohttp.Header.add_multi headers key values
|
||||
|
||||
let add_header headers key to_string value =
|
||||
Cohttp.Header.add headers key (to_string value)
|
||||
|
||||
let add_header_multi headers key to_string value =
|
||||
Cohttp.Header.add_multi headers key (to_string value)
|
||||
|
||||
let maybe_add_header headers key to_string value =
|
||||
option_fold (add_header headers key to_string) headers value
|
||||
|
||||
let maybe_add_header_multi headers key to_string value =
|
||||
option_fold (add_header_multi headers key to_string) headers value
|
||||
|
||||
let write_string_body s = Cohttp_lwt.Body.of_string s
|
||||
|
||||
let write_json_body payload =
|
||||
@ -37,20 +60,38 @@ let read_json_body_as_map resp body =
|
||||
let read_json_body_as_map_of of_json resp body =
|
||||
Lwt.(read_json_body_as_map resp body >|= List.map (fun (s, v) -> (s, of_json v)))
|
||||
|
||||
let replace_path_param uri param_name param_value =
|
||||
let replace_string_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
|
||||
let path = Str.global_replace regexp param_value (Uri.pct_decode (Uri.path uri)) in
|
||||
Uri.with_path uri path
|
||||
|
||||
let replace_path_param uri param_name to_string param_value =
|
||||
replace_string_path_param uri param_name (to_string param_value)
|
||||
|
||||
let maybe_replace_path_param uri param_name to_string param_value =
|
||||
option_fold (replace_path_param uri param_name to_string) uri param_value
|
||||
|
||||
let add_query_param uri param_name to_string param_value =
|
||||
Uri.add_query_param' uri (param_name, to_string param_value)
|
||||
|
||||
let add_query_param_list uri param_name to_string param_value =
|
||||
Uri.add_query_param uri (param_name, to_string param_value)
|
||||
|
||||
let maybe_add_query_param uri param_name to_string param_value =
|
||||
option_fold (add_query_param uri param_name to_string) uri param_value
|
||||
|
||||
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
|
||||
let add_form_encoded_body_param params param_name to_string param_value =
|
||||
let new_param_enc = Printf.sprintf {|%s=%s|} (Uri.pct_encode param_name) (Uri.pct_encode (to_string param_value)) 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 add_form_encoded_body_param_list params param_name to_string new_params =
|
||||
add_form_encoded_body_param params param_name (String.concat ",") (to_string new_params)
|
||||
|
||||
let maybe_add_form_encoded_body_param params param_name to_string param_value =
|
||||
option_fold (add_form_encoded_body_param params param_name to_string) params param_value
|
||||
|
||||
let finalize_form_encoded_body body = Cohttp_lwt.Body.of_string body
|
||||
|
1
modules/openapi-generator/src/main/resources/ocaml/to_optional_prefix.mustache
vendored
Normal file
1
modules/openapi-generator/src/main/resources/ocaml/to_optional_prefix.mustache
vendored
Normal file
@ -0,0 +1 @@
|
||||
{{^required}}{{^defaultValue}}{{^isContainer}}maybe_{{/isContainer}}{{/defaultValue}}{{/required}}
|
1
modules/openapi-generator/src/main/resources/ocaml/to_param.mustache
vendored
Normal file
1
modules/openapi-generator/src/main/resources/ocaml/to_param.mustache
vendored
Normal file
@ -0,0 +1 @@
|
||||
{{^isBodyParam}}{{^required}}?{{#defaultValue}}({{{paramName}}} = {{^isEnum}}{{#isString}}"{{{defaultValue}}}"{{/isString}}{{#isBoolean}}{{{defaultValue}}}{{/isBoolean}}{{#isShort}}{{{defaultValue}}}{{/isShort}}{{#isInteger}}{{{defaultValue}}}l{{/isInteger}}{{#isLong}}{{{defaultValue}}}L{{/isLong}}{{#isFloat}}{{{defaultValue}}}.{{/isFloat}}{{#isNumber}}{{{defaultValue}}}.{{/isNumber}}{{/isEnum}}{{#isEnum}}{{#isContainer}}[{{{defaultValue}}}]{{/isContainer}}{{^isContainer}}{{{defaultValue}}}{{/isContainer}}{{/isEnum}}){{/defaultValue}}{{^defaultValue}}{{^isContainer}}{{{paramName}}}{{/isContainer}}{{#isContainer}}({{{paramName}}} = []){{/isContainer}}{{/defaultValue}}{{/required}}{{#required}}~{{{paramName}}}{{/required}}{{/isBodyParam}}{{#isBodyParam}}~{{{paramName}}}{{/isBodyParam}}
|
@ -1 +1 @@
|
||||
{{#isContainer}}{{#items}}{{#isEnum}}List.map {{> to_string}}{{/isEnum}}{{#isModel}}List.map {{> to_string}}{{/isModel}}{{/items}}{{/isContainer}}{{^isEnum}}{{#isString}}{{/isString}}{{#isLong}}Int64.to_string {{/isLong}}{{#isInteger}}Int32.to_string {{/isInteger}}{{#isFloat}}string_of_float {{/isFloat}}{{#isNumber}}string_of_float {{/isNumber}}{{#isDouble}}string_of_float {{/isDouble}}{{#isBoolean}}string_of_bool {{/isBoolean}}{{#isByteArray}}{{/isByteArray}}{{#isModel}}{{{vendorExtensions.x-modelModule}}}.show {{/isModel}}{{/isEnum}}{{^isModel}}{{^isContainer}}{{#isEnum}}Enums.show_{{{datatypeWithEnum}}} {{/isEnum}}{{/isContainer}}{{/isModel}}
|
||||
{{#isContainer}}{{#items}}(List.map {{> to_string}}){{/items}}{{/isContainer}}{{^isEnum}}{{#isLong}}Int64.to_string{{/isLong}}{{#isInteger}}Int32.to_string{{/isInteger}}{{#isFloat}}string_of_float{{/isFloat}}{{#isNumber}}string_of_float{{/isNumber}}{{#isDouble}}string_of_float{{/isDouble}}{{#isBoolean}}string_of_bool{{/isBoolean}}{{#isFile}}(fun x -> x){{/isFile}}{{#isDate}}(fun x -> x){{/isDate}}{{#isDateTime}}(fun x -> x){{/isDateTime}}{{#isString}}(fun x -> x){{/isString}}{{#isByteArray}}(fun x -> x){{/isByteArray}}{{#isModel}}{{{vendorExtensions.x-modelModule}}}.show{{/isModel}}{{/isEnum}}{{^isModel}}{{^isContainer}}{{#isEnum}}Enums.show_{{{datatypeWithEnum}}}{{/isEnum}}{{/isContainer}}{{/isModel}}
|
@ -5,7 +5,7 @@
|
||||
*
|
||||
*)
|
||||
|
||||
let add_pet body =
|
||||
let add_pet ~body =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/pet" in
|
||||
let headers = Request.default_headers in
|
||||
@ -13,40 +13,41 @@ let add_pet body =
|
||||
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 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
|
||||
let headers = Request.maybe_add_header headers "api_key" (fun x -> x) 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 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
|
||||
let uri = Request.add_query_param_list 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 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
|
||||
let uri = Request.add_query_param_list uri "tags" (List.map (fun x -> x)) 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 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
|
||||
let headers = Cohttp.Header.add headers "api_key" Request.api_key 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 update_pet ~body =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/pet" in
|
||||
let headers = Request.default_headers in
|
||||
@ -54,26 +55,26 @@ let update_pet body =
|
||||
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 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 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.maybe_add_form_encoded_body_param body "name" (fun x -> x) name in
|
||||
let body = Request.maybe_add_form_encoded_body_param body "status" (fun x -> x) 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 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 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.maybe_add_form_encoded_body_param body "additional_metadata" (fun x -> x) additional_metadata in
|
||||
let body = Request.maybe_add_form_encoded_body_param body "file" (fun x -> x) 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
|
||||
|
@ -5,11 +5,11 @@
|
||||
*
|
||||
*)
|
||||
|
||||
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
|
||||
val add_pet : body:Pet.t -> unit Lwt.t
|
||||
val delete_pet : pet_id:int64 -> ?api_key:string -> unit -> unit Lwt.t
|
||||
val find_pets_by_status : status:Enums.pet_status list -> Pet.t list Lwt.t
|
||||
val find_pets_by_tags : tags:string list -> Pet.t list Lwt.t
|
||||
val get_pet_by_id : pet_id:int64 -> Pet.t Lwt.t
|
||||
val update_pet : body:Pet.t -> unit Lwt.t
|
||||
val update_pet_with_form : pet_id:int64 -> ?name:string -> ?status:string -> unit -> unit Lwt.t
|
||||
val upload_file : pet_id:int64 -> ?additional_metadata:string -> ?file:string -> unit -> Api_response.t Lwt.t
|
||||
|
@ -5,11 +5,11 @@
|
||||
*
|
||||
*)
|
||||
|
||||
let delete_order order_id =
|
||||
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
|
||||
let uri = Request.replace_path_param uri "orderId" (fun x -> x) order_id in
|
||||
Cohttp_lwt_unix.Client.call `DELETE uri ~headers >>= fun (resp, body) ->
|
||||
Request.handle_unit_response resp
|
||||
|
||||
@ -17,18 +17,19 @@ let get_inventory () =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/store/inventory" in
|
||||
let headers = Request.default_headers in
|
||||
let headers = Cohttp.Header.add headers "api_key" Request.api_key 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 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
|
||||
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 place_order ~body =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/store/order" in
|
||||
let headers = Request.default_headers in
|
||||
|
@ -5,7 +5,7 @@
|
||||
*
|
||||
*)
|
||||
|
||||
val delete_order : string -> unit Lwt.t
|
||||
val delete_order : order_id: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
|
||||
val get_order_by_id : order_id:int64 -> Order.t Lwt.t
|
||||
val place_order : body:Order.t -> Order.t Lwt.t
|
||||
|
@ -5,7 +5,7 @@
|
||||
*
|
||||
*)
|
||||
|
||||
let create_user body =
|
||||
let create_user ~body =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/user" in
|
||||
let headers = Request.default_headers in
|
||||
@ -13,7 +13,7 @@ let create_user body =
|
||||
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 create_users_with_array_input ~body =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/user/createWithArray" in
|
||||
let headers = Request.default_headers in
|
||||
@ -21,7 +21,7 @@ let create_users_with_array_input body =
|
||||
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 create_users_with_list_input ~body =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/user/createWithList" in
|
||||
let headers = Request.default_headers in
|
||||
@ -29,28 +29,28 @@ let create_users_with_list_input body =
|
||||
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
|
||||
Request.handle_unit_response resp
|
||||
|
||||
let delete_user username =
|
||||
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
|
||||
let uri = Request.replace_path_param uri "username" (fun x -> x) 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 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
|
||||
let uri = Request.replace_path_param uri "username" (fun x -> x) 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 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
|
||||
let uri = Request.add_query_param uri "username" (fun x -> x) username in
|
||||
let uri = Request.add_query_param uri "password" (fun x -> x) password in
|
||||
Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) ->
|
||||
Request.read_json_body_as (JsonSupport.to_string) resp body
|
||||
|
||||
@ -61,11 +61,11 @@ let logout_user () =
|
||||
Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) ->
|
||||
Request.handle_unit_response resp
|
||||
|
||||
let update_user username body =
|
||||
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 uri = Request.replace_path_param uri "username" (fun x -> x) username in
|
||||
let body = Request.write_as_json_body User.to_yojson body in
|
||||
Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) ->
|
||||
Request.handle_unit_response resp
|
||||
|
@ -5,11 +5,11 @@
|
||||
*
|
||||
*)
|
||||
|
||||
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 create_user : body:User.t -> unit Lwt.t
|
||||
val create_users_with_array_input : body:User.t list -> unit Lwt.t
|
||||
val create_users_with_list_input : body:User.t list -> unit Lwt.t
|
||||
val delete_user : username:string -> unit Lwt.t
|
||||
val get_user_by_name : username:string -> User.t Lwt.t
|
||||
val login_user : username:string -> password:string -> string Lwt.t
|
||||
val logout_user : unit -> unit Lwt.t
|
||||
val update_user : string -> User.t -> unit Lwt.t
|
||||
val update_user : username:string -> body:User.t -> unit Lwt.t
|
||||
|
@ -10,7 +10,7 @@ type t = {
|
||||
code: int32 option [@default None];
|
||||
_type: string option [@default None];
|
||||
message: string option [@default None];
|
||||
} [@@deriving yojson, show ];;
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
(** Describes the result of uploading an image resource *)
|
||||
let create () : t = {
|
||||
|
@ -9,7 +9,7 @@
|
||||
type t = {
|
||||
id: int64 option [@default None];
|
||||
name: string option [@default None];
|
||||
} [@@deriving yojson, show ];;
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
(** A category for a pet *)
|
||||
let create () : t = {
|
||||
|
@ -14,7 +14,7 @@ type t = {
|
||||
(* Order Status *)
|
||||
status: Enums.status option [@default None];
|
||||
complete: bool option [@default None];
|
||||
} [@@deriving yojson, show ];;
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
(** An order for a pets from the pet store *)
|
||||
let create () : t = {
|
||||
|
@ -14,7 +14,7 @@ type t = {
|
||||
tags: Tag.t list;
|
||||
(* pet status in the store *)
|
||||
status: Enums.pet_status option [@default None];
|
||||
} [@@deriving yojson, show ];;
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
(** A pet for sale in the pet store *)
|
||||
let create (name : string) (photo_urls : string list) : t = {
|
||||
|
@ -9,7 +9,7 @@
|
||||
type t = {
|
||||
id: int64 option [@default None];
|
||||
name: string option [@default None];
|
||||
} [@@deriving yojson, show ];;
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
(** A tag for a pet *)
|
||||
let create () : t = {
|
||||
|
@ -16,7 +16,7 @@ type t = {
|
||||
phone: string option [@default None];
|
||||
(* User Status *)
|
||||
user_status: int32 option [@default None];
|
||||
} [@@deriving yojson, show ];;
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
(** A User who is purchasing from the pet store *)
|
||||
let create () : t = {
|
||||
|
@ -2,8 +2,31 @@ let api_key = ""
|
||||
let base_url = "http://petstore.swagger.io/v2"
|
||||
let default_headers = Cohttp.Header.init_with "Content-Type" "application/json"
|
||||
|
||||
let option_fold f default o =
|
||||
match o with
|
||||
| Some v -> f v
|
||||
| None -> default
|
||||
|
||||
let build_uri operation_path = Uri.of_string (base_url ^ operation_path)
|
||||
|
||||
let add_string_header headers key value =
|
||||
Cohttp.Header.add headers key value
|
||||
|
||||
let add_string_header_multi headers key values =
|
||||
Cohttp.Header.add_multi headers key values
|
||||
|
||||
let add_header headers key to_string value =
|
||||
Cohttp.Header.add headers key (to_string value)
|
||||
|
||||
let add_header_multi headers key to_string value =
|
||||
Cohttp.Header.add_multi headers key (to_string value)
|
||||
|
||||
let maybe_add_header headers key to_string value =
|
||||
option_fold (add_header headers key to_string) headers value
|
||||
|
||||
let maybe_add_header_multi headers key to_string value =
|
||||
option_fold (add_header_multi headers key to_string) headers value
|
||||
|
||||
let write_string_body s = Cohttp_lwt.Body.of_string s
|
||||
|
||||
let write_json_body payload =
|
||||
@ -37,20 +60,38 @@ let read_json_body_as_map resp body =
|
||||
let read_json_body_as_map_of of_json resp body =
|
||||
Lwt.(read_json_body_as_map resp body >|= List.map (fun (s, v) -> (s, of_json v)))
|
||||
|
||||
let replace_path_param uri param_name param_value =
|
||||
let replace_string_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
|
||||
let path = Str.global_replace regexp param_value (Uri.pct_decode (Uri.path uri)) in
|
||||
Uri.with_path uri path
|
||||
|
||||
let replace_path_param uri param_name to_string param_value =
|
||||
replace_string_path_param uri param_name (to_string param_value)
|
||||
|
||||
let maybe_replace_path_param uri param_name to_string param_value =
|
||||
option_fold (replace_path_param uri param_name to_string) uri param_value
|
||||
|
||||
let add_query_param uri param_name to_string param_value =
|
||||
Uri.add_query_param' uri (param_name, to_string param_value)
|
||||
|
||||
let add_query_param_list uri param_name to_string param_value =
|
||||
Uri.add_query_param uri (param_name, to_string param_value)
|
||||
|
||||
let maybe_add_query_param uri param_name to_string param_value =
|
||||
option_fold (add_query_param uri param_name to_string) uri param_value
|
||||
|
||||
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
|
||||
let add_form_encoded_body_param params param_name to_string param_value =
|
||||
let new_param_enc = Printf.sprintf {|%s=%s|} (Uri.pct_encode param_name) (Uri.pct_encode (to_string param_value)) 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 add_form_encoded_body_param_list params param_name to_string new_params =
|
||||
add_form_encoded_body_param params param_name (String.concat ",") (to_string new_params)
|
||||
|
||||
let maybe_add_form_encoded_body_param params param_name to_string param_value =
|
||||
option_fold (add_form_encoded_body_param params param_name to_string) params param_value
|
||||
|
||||
let finalize_form_encoded_body body = Cohttp_lwt.Body.of_string body
|
||||
|
@ -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
|
@ -0,0 +1 @@
|
||||
4.1.0-SNAPSHOT
|
27
samples/openapi3/client/petstore/ocaml/README.md
Normal file
27
samples/openapi3/client/petstore/ocaml/README.md
Normal file
@ -0,0 +1,27 @@
|
||||
#
|
||||
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \'' \\
|
||||
|
||||
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
|
||||
eval $(opam env)
|
||||
dune build
|
||||
```
|
||||
|
||||
## Getting Started
|
||||
|
||||
TODO
|
||||
|
9
samples/openapi3/client/petstore/ocaml/dune
Normal file
9
samples/openapi3/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/openapi3/client/petstore/ocaml/dune-project
Normal file
2
samples/openapi3/client/petstore/ocaml/dune-project
Normal file
@ -0,0 +1,2 @@
|
||||
(lang dune 1.10)
|
||||
(name petstore_client)
|
15
samples/openapi3/client/petstore/ocaml/petstore_client.opam
Normal file
15
samples/openapi3/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]
|
@ -0,0 +1,15 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
let call_123_test_special_tags ~client_t =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/another-fake/dummy" in
|
||||
let headers = Request.default_headers in
|
||||
let body = Request.write_as_json_body Client.to_yojson client_t in
|
||||
Cohttp_lwt_unix.Client.call `PATCH uri ~headers ~body >>= fun (resp, body) ->
|
||||
Request.read_json_body_as (JsonSupport.unwrap Client.of_yojson) resp body
|
||||
|
@ -0,0 +1,8 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
val call_123_test_special_tags : client_t:Client.t -> Client.t Lwt.t
|
@ -0,0 +1,14 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
let foo_get () =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/foo" in
|
||||
let headers = Request.default_headers in
|
||||
Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) ->
|
||||
Request.read_json_body_as (JsonSupport.unwrap Inline_response_default.of_yojson) resp body
|
||||
|
@ -0,0 +1,8 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
val foo_get : unit -> Inline_response_default.t Lwt.t
|
143
samples/openapi3/client/petstore/ocaml/src/apis/fake_api.ml
Normal file
143
samples/openapi3/client/petstore/ocaml/src/apis/fake_api.ml
Normal file
@ -0,0 +1,143 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
let fake_health_get () =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/fake/health" in
|
||||
let headers = Request.default_headers in
|
||||
Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) ->
|
||||
Request.read_json_body_as (JsonSupport.unwrap Health_check_result.of_yojson) resp body
|
||||
|
||||
let fake_outer_boolean_serialize ~body () =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/fake/outer/boolean" in
|
||||
let headers = Request.default_headers in
|
||||
let body = Request.write_as_json_body JsonSupport.of_bool body in
|
||||
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
|
||||
Request.read_json_body_as (JsonSupport.to_bool) resp body
|
||||
|
||||
let fake_outer_composite_serialize ~outer_composite_t () =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/fake/outer/composite" in
|
||||
let headers = Request.default_headers in
|
||||
let body = Request.write_as_json_body Outer_composite.to_yojson outer_composite_t in
|
||||
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
|
||||
Request.read_json_body_as (JsonSupport.unwrap Outer_composite.of_yojson) resp body
|
||||
|
||||
let fake_outer_number_serialize ~body () =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/fake/outer/number" in
|
||||
let headers = Request.default_headers in
|
||||
let body = Request.write_as_json_body JsonSupport.of_float body in
|
||||
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
|
||||
Request.read_json_body_as (JsonSupport.to_float) resp body
|
||||
|
||||
let fake_outer_string_serialize ~body () =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/fake/outer/string" in
|
||||
let headers = Request.default_headers in
|
||||
let body = Request.write_as_json_body JsonSupport.of_string body in
|
||||
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
|
||||
Request.read_json_body_as (JsonSupport.to_string) resp body
|
||||
|
||||
let test_body_with_file_schema ~file_schema_test_class_t =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/fake/body-with-file-schema" in
|
||||
let headers = Request.default_headers in
|
||||
let body = Request.write_as_json_body File_schema_test_class.to_yojson file_schema_test_class_t in
|
||||
Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) ->
|
||||
Request.handle_unit_response resp
|
||||
|
||||
let test_body_with_query_params ~query ~user_t =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/fake/body-with-query-params" in
|
||||
let headers = Request.default_headers in
|
||||
let uri = Request.add_query_param uri "query" (fun x -> x) query in
|
||||
let body = Request.write_as_json_body User.to_yojson user_t in
|
||||
Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) ->
|
||||
Request.handle_unit_response resp
|
||||
|
||||
let test_client_model ~client_t =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/fake" in
|
||||
let headers = Request.default_headers in
|
||||
let body = Request.write_as_json_body Client.to_yojson client_t in
|
||||
Cohttp_lwt_unix.Client.call `PATCH uri ~headers ~body >>= fun (resp, body) ->
|
||||
Request.read_json_body_as (JsonSupport.unwrap Client.of_yojson) resp body
|
||||
|
||||
let test_endpoint_parameters ~number ~double ~pattern_without_delimiter ~byte ?integer ?int32 ?int64 ?float ?string ?binary ?date ?date_time ?password ?callback () =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/fake" in
|
||||
let headers = Request.default_headers in
|
||||
let body = Request.init_form_encoded_body () in
|
||||
let body = Request.maybe_add_form_encoded_body_param body "integer" Int32.to_string integer in
|
||||
let body = Request.maybe_add_form_encoded_body_param body "int32" Int32.to_string int32 in
|
||||
let body = Request.maybe_add_form_encoded_body_param body "int64" Int64.to_string int64 in
|
||||
let body = Request.add_form_encoded_body_param body "number" string_of_float number in
|
||||
let body = Request.maybe_add_form_encoded_body_param body "float" string_of_float float in
|
||||
let body = Request.add_form_encoded_body_param body "double" string_of_float double in
|
||||
let body = Request.maybe_add_form_encoded_body_param body "string" (fun x -> x) string in
|
||||
let body = Request.add_form_encoded_body_param body "pattern_without_delimiter" (fun x -> x) pattern_without_delimiter in
|
||||
let body = Request.add_form_encoded_body_param body "byte" (fun x -> x) byte in
|
||||
let body = Request.maybe_add_form_encoded_body_param body "binary" (fun x -> x) binary in
|
||||
let body = Request.maybe_add_form_encoded_body_param body "date" (fun x -> x) date in
|
||||
let body = Request.maybe_add_form_encoded_body_param body "date_time" (fun x -> x) date_time in
|
||||
let body = Request.maybe_add_form_encoded_body_param body "password" (fun x -> x) password in
|
||||
let body = Request.maybe_add_form_encoded_body_param body "callback" (fun x -> x) callback 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 test_enum_parameters ?(enum_header_string_array = []) ?(enum_header_string = `Minusefg) ?(enum_query_string_array = []) ?(enum_query_string = `Minusefg) ?enum_query_integer ?enum_query_double ?(enum_form_string_array = [`Dollar]) ?(enum_form_string = `Minusefg) () =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/fake" in
|
||||
let headers = Request.default_headers in
|
||||
let headers = Request.add_header_multi headers "enum_header_string_array" (List.map Enums.show_enum_form_string_array) enum_header_string_array in
|
||||
let headers = Request.add_header headers "enum_header_string" Enums.show_enumclass enum_header_string in
|
||||
let uri = Request.add_query_param_list uri "enum_query_string_array" (List.map Enums.show_enum_form_string_array) enum_query_string_array in
|
||||
let uri = Request.add_query_param uri "enum_query_string" Enums.show_enumclass enum_query_string in
|
||||
let uri = Request.maybe_add_query_param uri "enum_query_integer" Enums.show_enum_query_integer enum_query_integer in
|
||||
let uri = Request.maybe_add_query_param uri "enum_query_double" Enums.show_enum_number enum_query_double in
|
||||
let body = Request.init_form_encoded_body () in
|
||||
let body = Request.add_form_encoded_body_param_list body "enum_form_string_array" (List.map Enums.show_enum_form_string_array) enum_form_string_array in
|
||||
let body = Request.add_form_encoded_body_param body "enum_form_string" Enums.show_enumclass enum_form_string in
|
||||
let body = Request.finalize_form_encoded_body body in
|
||||
Cohttp_lwt_unix.Client.call `GET uri ~headers ~body >>= fun (resp, body) ->
|
||||
Request.handle_unit_response resp
|
||||
|
||||
let test_group_parameters ~required_string_group ~required_boolean_group ~required_int64_group ?string_group ?boolean_group ?int64_group () =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/fake" in
|
||||
let headers = Request.default_headers in
|
||||
let headers = Request.add_header headers "required_boolean_group" string_of_bool required_boolean_group in
|
||||
let headers = Request.maybe_add_header headers "boolean_group" string_of_bool boolean_group in
|
||||
let uri = Request.add_query_param uri "required_string_group" Int32.to_string required_string_group in
|
||||
let uri = Request.add_query_param uri "required_int64_group" Int64.to_string required_int64_group in
|
||||
let uri = Request.maybe_add_query_param uri "string_group" Int32.to_string string_group in
|
||||
let uri = Request.maybe_add_query_param uri "int64_group" Int64.to_string int64_group in
|
||||
Cohttp_lwt_unix.Client.call `DELETE uri ~headers >>= fun (resp, body) ->
|
||||
Request.handle_unit_response resp
|
||||
|
||||
let test_inline_additional_properties ~request_body =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/fake/inline-additionalProperties" in
|
||||
let headers = Request.default_headers in
|
||||
let body = Request.write_as_json_body (JsonSupport.of_map_of JsonSupport.of_string) request_body in
|
||||
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
|
||||
Request.handle_unit_response resp
|
||||
|
||||
let test_json_form_data ~param ~param2 =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/fake/jsonFormData" in
|
||||
let headers = Request.default_headers in
|
||||
let body = Request.init_form_encoded_body () in
|
||||
let body = Request.add_form_encoded_body_param body "param" (fun x -> x) param in
|
||||
let body = Request.add_form_encoded_body_param body "param2" (fun x -> x) param2 in
|
||||
let body = Request.finalize_form_encoded_body body in
|
||||
Cohttp_lwt_unix.Client.call `GET uri ~headers ~body >>= fun (resp, body) ->
|
||||
Request.handle_unit_response resp
|
||||
|
20
samples/openapi3/client/petstore/ocaml/src/apis/fake_api.mli
Normal file
20
samples/openapi3/client/petstore/ocaml/src/apis/fake_api.mli
Normal file
@ -0,0 +1,20 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
val fake_health_get : unit -> Health_check_result.t Lwt.t
|
||||
val fake_outer_boolean_serialize : body:bool -> unit -> bool Lwt.t
|
||||
val fake_outer_composite_serialize : outer_composite_t:Outer_composite.t -> unit -> Outer_composite.t Lwt.t
|
||||
val fake_outer_number_serialize : body:float -> unit -> float Lwt.t
|
||||
val fake_outer_string_serialize : body:string -> unit -> string Lwt.t
|
||||
val test_body_with_file_schema : file_schema_test_class_t:File_schema_test_class.t -> unit Lwt.t
|
||||
val test_body_with_query_params : query:string -> user_t:User.t -> unit Lwt.t
|
||||
val test_client_model : client_t:Client.t -> Client.t Lwt.t
|
||||
val test_endpoint_parameters : number:float -> double:float -> pattern_without_delimiter:string -> byte:string -> ?integer:int32 -> ?int32:int32 -> ?int64:int64 -> ?float:float -> ?string:string -> ?binary:string -> ?date:string -> ?date_time:string -> ?password:string -> ?callback:string -> unit -> unit Lwt.t
|
||||
val test_enum_parameters : ?enum_header_string_array:Enums.enum_form_string_array list -> ?enum_header_string:Enums.enumclass -> ?enum_query_string_array:Enums.enum_form_string_array list -> ?enum_query_string:Enums.enumclass -> ?enum_query_integer:Enums.enum_query_integer -> ?enum_query_double:Enums.enum_number -> ?enum_form_string_array:Enums.enum_form_string_array list -> ?enum_form_string:Enums.enumclass -> unit -> unit Lwt.t
|
||||
val test_group_parameters : required_string_group:int32 -> required_boolean_group:bool -> required_int64_group:int64 -> ?string_group:int32 -> ?boolean_group:bool -> ?int64_group:int64 -> unit -> unit Lwt.t
|
||||
val test_inline_additional_properties : request_body:(string * string) list -> unit Lwt.t
|
||||
val test_json_form_data : param:string -> param2:string -> unit Lwt.t
|
@ -0,0 +1,16 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
let test_classname ~client_t =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/fake_classname_test" in
|
||||
let headers = Request.default_headers in
|
||||
let uri = Uri.add_query_param' uri ("api_key_query", Request.api_key) in
|
||||
let body = Request.write_as_json_body Client.to_yojson client_t in
|
||||
Cohttp_lwt_unix.Client.call `PATCH uri ~headers ~body >>= fun (resp, body) ->
|
||||
Request.read_json_body_as (JsonSupport.unwrap Client.of_yojson) resp body
|
||||
|
@ -0,0 +1,8 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
val test_classname : client_t:Client.t -> Client.t Lwt.t
|
93
samples/openapi3/client/petstore/ocaml/src/apis/pet_api.ml
Normal file
93
samples/openapi3/client/petstore/ocaml/src/apis/pet_api.ml
Normal file
@ -0,0 +1,93 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
let add_pet ~pet_t =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/pet" in
|
||||
let headers = Request.default_headers in
|
||||
let body = Request.write_as_json_body Pet.to_yojson pet_t 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 = Request.maybe_add_header headers "api_key" (fun x -> x) 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 = Request.add_query_param_list 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 = Request.add_query_param_list uri "tags" (List.map (fun x -> x)) 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 headers = Cohttp.Header.add headers "api_key" Request.api_key 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 ~pet_t =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/pet" in
|
||||
let headers = Request.default_headers in
|
||||
let body = Request.write_as_json_body Pet.to_yojson pet_t 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.maybe_add_form_encoded_body_param body "name" (fun x -> x) name in
|
||||
let body = Request.maybe_add_form_encoded_body_param body "status" (fun x -> x) 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.maybe_add_form_encoded_body_param body "additional_metadata" (fun x -> x) additional_metadata in
|
||||
let body = Request.maybe_add_form_encoded_body_param body "file" (fun x -> x) 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
|
||||
|
||||
let upload_file_with_required_file ~pet_id ~required_file ?additional_metadata () =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/fake/{petId}/uploadImageWithRequiredFile" 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.maybe_add_form_encoded_body_param body "additional_metadata" (fun x -> x) additional_metadata in
|
||||
let body = Request.add_form_encoded_body_param body "required_file" (fun x -> x) required_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
|
||||
|
16
samples/openapi3/client/petstore/ocaml/src/apis/pet_api.mli
Normal file
16
samples/openapi3/client/petstore/ocaml/src/apis/pet_api.mli
Normal file
@ -0,0 +1,16 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
val add_pet : pet_t:Pet.t -> unit Lwt.t
|
||||
val delete_pet : pet_id:int64 -> ?api_key:string -> unit -> unit Lwt.t
|
||||
val find_pets_by_status : status:Enums.pet_status list -> Pet.t list Lwt.t
|
||||
val find_pets_by_tags : tags:string list -> Pet.t list Lwt.t
|
||||
val get_pet_by_id : pet_id:int64 -> Pet.t Lwt.t
|
||||
val update_pet : pet_t:Pet.t -> unit Lwt.t
|
||||
val update_pet_with_form : pet_id:int64 -> ?name:string -> ?status:string -> unit -> unit Lwt.t
|
||||
val upload_file : pet_id:int64 -> ?additional_metadata:string -> ?file:string -> unit -> Api_response.t Lwt.t
|
||||
val upload_file_with_required_file : pet_id:int64 -> required_file:string -> ?additional_metadata:string -> unit -> Api_response.t Lwt.t
|
39
samples/openapi3/client/petstore/ocaml/src/apis/store_api.ml
Normal file
39
samples/openapi3/client/petstore/ocaml/src/apis/store_api.ml
Normal file
@ -0,0 +1,39 @@
|
||||
(*
|
||||
* 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/{order_id}" in
|
||||
let headers = Request.default_headers in
|
||||
let uri = Request.replace_path_param uri "order_id" (fun x -> x) 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
|
||||
let headers = Cohttp.Header.add headers "api_key" Request.api_key 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/{order_id}" in
|
||||
let headers = Request.default_headers in
|
||||
let uri = Request.replace_path_param uri "order_id" 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 ~order_t =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/store/order" in
|
||||
let headers = Request.default_headers in
|
||||
let body = Request.write_as_json_body Order.to_yojson order_t 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
|
||||
|
@ -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 : order_id:string -> unit Lwt.t
|
||||
val get_inventory : unit -> (string * int32) list Lwt.t
|
||||
val get_order_by_id : order_id:int64 -> Order.t Lwt.t
|
||||
val place_order : order_t:Order.t -> Order.t Lwt.t
|
72
samples/openapi3/client/petstore/ocaml/src/apis/user_api.ml
Normal file
72
samples/openapi3/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 ~user_t =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/user" in
|
||||
let headers = Request.default_headers in
|
||||
let body = Request.write_as_json_body User.to_yojson user_t in
|
||||
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
|
||||
Request.handle_unit_response resp
|
||||
|
||||
let create_users_with_array_input ~user =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/user/createWithArray" in
|
||||
let headers = Request.default_headers in
|
||||
let body = Request.write_as_json_body (JsonSupport.of_list_of User.to_yojson) user in
|
||||
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
|
||||
Request.handle_unit_response resp
|
||||
|
||||
let create_users_with_list_input ~user =
|
||||
let open Lwt in
|
||||
let uri = Request.build_uri "/user/createWithList" in
|
||||
let headers = Request.default_headers in
|
||||
let body = Request.write_as_json_body (JsonSupport.of_list_of User.to_yojson) user 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" (fun x -> x) 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" (fun x -> x) 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 = Request.add_query_param uri "username" (fun x -> x) username in
|
||||
let uri = Request.add_query_param uri "password" (fun x -> x) 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 ~user_t =
|
||||
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" (fun x -> x) username in
|
||||
let body = Request.write_as_json_body User.to_yojson user_t in
|
||||
Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) ->
|
||||
Request.handle_unit_response resp
|
||||
|
15
samples/openapi3/client/petstore/ocaml/src/apis/user_api.mli
Normal file
15
samples/openapi3/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:User.t -> unit Lwt.t
|
||||
val create_users_with_array_input : user:User.t list -> unit Lwt.t
|
||||
val create_users_with_list_input : user:User.t list -> unit Lwt.t
|
||||
val delete_user : username:string -> unit Lwt.t
|
||||
val get_user_by_name : username:string -> User.t Lwt.t
|
||||
val login_user : username:string -> password:string -> string Lwt.t
|
||||
val logout_user : unit -> unit Lwt.t
|
||||
val update_user : username:string -> user_t:User.t -> unit Lwt.t
|
@ -0,0 +1,17 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
map_property: (string * string) list;
|
||||
map_of_map_property: (string * (string * string) list) list;
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create () : t = {
|
||||
map_property = [];
|
||||
map_of_map_property = [];
|
||||
}
|
||||
|
17
samples/openapi3/client/petstore/ocaml/src/models/animal.ml
Normal file
17
samples/openapi3/client/petstore/ocaml/src/models/animal.ml
Normal file
@ -0,0 +1,17 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
class_name: string;
|
||||
color: string option [@default None];
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create (class_name : string) : t = {
|
||||
class_name = class_name;
|
||||
color = None;
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
code: int32 option [@default None];
|
||||
_type: string option [@default None];
|
||||
message: string option [@default None];
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create () : t = {
|
||||
code = None;
|
||||
_type = None;
|
||||
message = None;
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
array_array_number: float list list;
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create () : t = {
|
||||
array_array_number = [];
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
array_number: float list;
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create () : t = {
|
||||
array_number = [];
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
array_of_string: string list;
|
||||
array_array_of_integer: int64 list list;
|
||||
array_array_of_model: Read_only_first.t list list;
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create () : t = {
|
||||
array_of_string = [];
|
||||
array_array_of_integer = [];
|
||||
array_array_of_model = [];
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
small_camel: string option [@default None];
|
||||
capital_camel: string option [@default None];
|
||||
small_snake: string option [@default None];
|
||||
capital_snake: string option [@default None];
|
||||
sca_eth_flow_points: string option [@default None];
|
||||
(* Name of the pet *)
|
||||
att_name: string option [@default None];
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create () : t = {
|
||||
small_camel = None;
|
||||
capital_camel = None;
|
||||
small_snake = None;
|
||||
capital_snake = None;
|
||||
sca_eth_flow_points = None;
|
||||
att_name = None;
|
||||
}
|
||||
|
19
samples/openapi3/client/petstore/ocaml/src/models/cat.ml
Normal file
19
samples/openapi3/client/petstore/ocaml/src/models/cat.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
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
class_name: string;
|
||||
color: string option [@default None];
|
||||
declawed: bool option [@default None];
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create (class_name : string) : t = {
|
||||
class_name = class_name;
|
||||
color = None;
|
||||
declawed = None;
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
declawed: bool option [@default None];
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create () : t = {
|
||||
declawed = None;
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
id: int64 option [@default None];
|
||||
name: string;
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create (name : string) : t = {
|
||||
id = None;
|
||||
name = name;
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
* Schema Class_model.t : Model for testing model with \''_class\'' property
|
||||
*)
|
||||
|
||||
type t = {
|
||||
_class: string option [@default None];
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
(** Model for testing model with \''_class\'' property *)
|
||||
let create () : t = {
|
||||
_class = None;
|
||||
}
|
||||
|
15
samples/openapi3/client/petstore/ocaml/src/models/client.ml
Normal file
15
samples/openapi3/client/petstore/ocaml/src/models/client.ml
Normal file
@ -0,0 +1,15 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
client: string option [@default None];
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create () : t = {
|
||||
client = None;
|
||||
}
|
||||
|
19
samples/openapi3/client/petstore/ocaml/src/models/dog.ml
Normal file
19
samples/openapi3/client/petstore/ocaml/src/models/dog.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
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
class_name: string;
|
||||
color: string option [@default None];
|
||||
breed: string option [@default None];
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create (class_name : string) : t = {
|
||||
class_name = class_name;
|
||||
color = None;
|
||||
breed = None;
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
breed: string option [@default None];
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create () : t = {
|
||||
breed = None;
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
just_symbol: Enums.just_symbol option [@default None];
|
||||
array_enum: Enums.array_enum list;
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create () : t = {
|
||||
just_symbol = None;
|
||||
array_enum = [];
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
enum_string: Enums.enum_string option [@default None];
|
||||
enum_string_required: Enums.enum_string;
|
||||
enum_integer: Enums.enum_integer option [@default None];
|
||||
enum_number: Enums.enum_number option [@default None];
|
||||
outer_enum: Enums.status option [@default None];
|
||||
outer_enum_integer: Enums.outerenuminteger option [@default None];
|
||||
outer_enum_default_value: Enums.status option [@default None];
|
||||
outer_enum_integer_default_value: Enums.outerenuminteger option [@default None];
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create (enum_string_required : Enums.enum_string) : t = {
|
||||
enum_string = None;
|
||||
enum_string_required = enum_string_required;
|
||||
enum_integer = None;
|
||||
enum_number = None;
|
||||
outer_enum = None;
|
||||
outer_enum_integer = None;
|
||||
outer_enum_default_value = None;
|
||||
outer_enum_integer_default_value = None;
|
||||
}
|
||||
|
18
samples/openapi3/client/petstore/ocaml/src/models/file.ml
Normal file
18
samples/openapi3/client/petstore/ocaml/src/models/file.ml
Normal file
@ -0,0 +1,18 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
* Schema File.t : Must be named `File` for test.
|
||||
*)
|
||||
|
||||
type t = {
|
||||
(* Test capitalization *)
|
||||
source_uri: string option [@default None];
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
(** Must be named `File` for test. *)
|
||||
let create () : t = {
|
||||
source_uri = None;
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
file: File.t option [@default None];
|
||||
files: File.t list;
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create () : t = {
|
||||
file = None;
|
||||
files = [];
|
||||
}
|
||||
|
15
samples/openapi3/client/petstore/ocaml/src/models/foo.ml
Normal file
15
samples/openapi3/client/petstore/ocaml/src/models/foo.ml
Normal file
@ -0,0 +1,15 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
bar: string option [@default None];
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create () : t = {
|
||||
bar = None;
|
||||
}
|
||||
|
@ -0,0 +1,45 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
integer: int32 option [@default None];
|
||||
int32: int32 option [@default None];
|
||||
int64: int64 option [@default None];
|
||||
number: float;
|
||||
float: float option [@default None];
|
||||
double: float option [@default None];
|
||||
string: string option [@default None];
|
||||
byte: string;
|
||||
binary: string option [@default None];
|
||||
date: string;
|
||||
date_time: string option [@default None];
|
||||
uuid: string option [@default None];
|
||||
password: string;
|
||||
(* A string that is a 10 digit number. Can have leading zeros. *)
|
||||
pattern_with_digits: string option [@default None];
|
||||
(* A string starting with 'image_' (case insensitive) and one to three digits following i.e. Image_01. *)
|
||||
pattern_with_digits_and_delimiter: string option [@default None];
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create (number : float) (byte : string) (date : string) (password : string) : t = {
|
||||
integer = None;
|
||||
int32 = None;
|
||||
int64 = None;
|
||||
number = number;
|
||||
float = None;
|
||||
double = None;
|
||||
string = None;
|
||||
byte = byte;
|
||||
binary = None;
|
||||
date = date;
|
||||
date_time = None;
|
||||
uuid = None;
|
||||
password = password;
|
||||
pattern_with_digits = None;
|
||||
pattern_with_digits_and_delimiter = None;
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
bar: string option [@default None];
|
||||
foo: string option [@default None];
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create () : t = {
|
||||
bar = None;
|
||||
foo = None;
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
* Schema Health_check_result.t : Just a string to inform instance is up and running. Make it nullable in hope to get it as pointer in generated model.
|
||||
*)
|
||||
|
||||
type t = {
|
||||
nullable_message: string option [@default None];
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
(** Just a string to inform instance is up and running. Make it nullable in hope to get it as pointer in generated model. *)
|
||||
let create () : t = {
|
||||
nullable_message = None;
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
(* Updated name of the pet *)
|
||||
name: string option [@default None];
|
||||
(* Updated status of the pet *)
|
||||
status: string option [@default None];
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create () : t = {
|
||||
name = None;
|
||||
status = None;
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
(* Additional data to pass to server *)
|
||||
additional_metadata: string option [@default None];
|
||||
(* file to upload *)
|
||||
file: string option [@default None];
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create () : t = {
|
||||
additional_metadata = None;
|
||||
file = None;
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
(* Form parameter enum test (string array) *)
|
||||
enum_form_string_array: Enums.enum_form_string_array list;
|
||||
(* Form parameter enum test (string) *)
|
||||
enum_form_string: Enums.enumclass option [@default Some(`Minusefg)];
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create () : t = {
|
||||
enum_form_string_array = [];
|
||||
enum_form_string = None;
|
||||
}
|
||||
|
@ -0,0 +1,55 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
(* None *)
|
||||
integer: int32 option [@default None];
|
||||
(* None *)
|
||||
int32: int32 option [@default None];
|
||||
(* None *)
|
||||
int64: int64 option [@default None];
|
||||
(* None *)
|
||||
number: float;
|
||||
(* None *)
|
||||
float: float option [@default None];
|
||||
(* None *)
|
||||
double: float;
|
||||
(* None *)
|
||||
string: string option [@default None];
|
||||
(* None *)
|
||||
pattern_without_delimiter: string;
|
||||
(* None *)
|
||||
byte: string;
|
||||
(* None *)
|
||||
binary: string option [@default None];
|
||||
(* None *)
|
||||
date: string option [@default None];
|
||||
(* None *)
|
||||
date_time: string option [@default None];
|
||||
(* None *)
|
||||
password: string option [@default None];
|
||||
(* None *)
|
||||
callback: string option [@default None];
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create (number : float) (double : float) (pattern_without_delimiter : string) (byte : string) : t = {
|
||||
integer = None;
|
||||
int32 = None;
|
||||
int64 = None;
|
||||
number = number;
|
||||
float = None;
|
||||
double = double;
|
||||
string = None;
|
||||
pattern_without_delimiter = pattern_without_delimiter;
|
||||
byte = byte;
|
||||
binary = None;
|
||||
date = None;
|
||||
date_time = None;
|
||||
password = None;
|
||||
callback = None;
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
(* field1 *)
|
||||
param: string;
|
||||
(* field2 *)
|
||||
param2: string;
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create (param : string) (param2 : string) : t = {
|
||||
param = param;
|
||||
param2 = param2;
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
(* Additional data to pass to server *)
|
||||
additional_metadata: string option [@default None];
|
||||
(* file to upload *)
|
||||
required_file: string;
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create (required_file : string) : t = {
|
||||
additional_metadata = None;
|
||||
required_file = required_file;
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
string: Foo.t option [@default None];
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create () : t = {
|
||||
string = None;
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
map_map_of_string: (string * (string * string) list) list;
|
||||
map_of_enum_string: (string * Enums.map_of_enum_string) list;
|
||||
direct_map: (string * bool) list;
|
||||
indirect_map: (string * bool) list;
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create () : t = {
|
||||
map_map_of_string = [];
|
||||
map_of_enum_string = [];
|
||||
direct_map = [];
|
||||
indirect_map = [];
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
uuid: string option [@default None];
|
||||
date_time: string option [@default None];
|
||||
map: (string * Animal.t) list;
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create () : t = {
|
||||
uuid = None;
|
||||
date_time = None;
|
||||
map = [];
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
* Schema Model_200_response.t : Model for testing model name starting with number
|
||||
*)
|
||||
|
||||
type t = {
|
||||
name: int32 option [@default None];
|
||||
_class: string option [@default None];
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
(** Model for testing model name starting with number *)
|
||||
let create () : t = {
|
||||
name = None;
|
||||
_class = None;
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
special_property_name: int64 option [@default None];
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create () : t = {
|
||||
special_property_name = None;
|
||||
}
|
||||
|
23
samples/openapi3/client/petstore/ocaml/src/models/name.ml
Normal file
23
samples/openapi3/client/petstore/ocaml/src/models/name.ml
Normal file
@ -0,0 +1,23 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
* Schema Name.t : Model for testing model name same as property name
|
||||
*)
|
||||
|
||||
type t = {
|
||||
name: int32;
|
||||
snake_case: int32 option [@default None];
|
||||
property: string option [@default None];
|
||||
var_123_number: int32 option [@default None];
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
(** Model for testing model name same as property name *)
|
||||
let create (name : int32) : t = {
|
||||
name = name;
|
||||
snake_case = None;
|
||||
property = None;
|
||||
var_123_number = None;
|
||||
}
|
||||
|
@ -0,0 +1,37 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
integer_prop: int32 option [@default None];
|
||||
number_prop: float option [@default None];
|
||||
boolean_prop: bool option [@default None];
|
||||
string_prop: string option [@default None];
|
||||
date_prop: string option [@default None];
|
||||
datetime_prop: string option [@default None];
|
||||
array_nullable_prop: Yojson.Safe.t list;
|
||||
array_and_items_nullable_prop: Yojson.Safe.t list;
|
||||
array_items_nullable: Yojson.Safe.t list;
|
||||
object_nullable_prop: (string * Yojson.Safe.t) list;
|
||||
object_and_items_nullable_prop: (string * Yojson.Safe.t) list;
|
||||
object_items_nullable: (string * Yojson.Safe.t) list;
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create () : t = {
|
||||
integer_prop = None;
|
||||
number_prop = None;
|
||||
boolean_prop = None;
|
||||
string_prop = None;
|
||||
date_prop = None;
|
||||
datetime_prop = None;
|
||||
array_nullable_prop = [];
|
||||
array_and_items_nullable_prop = [];
|
||||
array_items_nullable = [];
|
||||
object_nullable_prop = [];
|
||||
object_and_items_nullable_prop = [];
|
||||
object_items_nullable = [];
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
just_number: float option [@default None];
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create () : t = {
|
||||
just_number = None;
|
||||
}
|
||||
|
26
samples/openapi3/client/petstore/ocaml/src/models/order.ml
Normal file
26
samples/openapi3/client/petstore/ocaml/src/models/order.ml
Normal file
@ -0,0 +1,26 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
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 { strict = false }, show ];;
|
||||
|
||||
let create () : t = {
|
||||
id = None;
|
||||
pet_id = None;
|
||||
quantity = None;
|
||||
ship_date = None;
|
||||
status = None;
|
||||
complete = None;
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
my_number: float option [@default None];
|
||||
my_string: string option [@default None];
|
||||
my_boolean: bool option [@default None];
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create () : t = {
|
||||
my_number = None;
|
||||
my_string = None;
|
||||
my_boolean = None;
|
||||
}
|
||||
|
26
samples/openapi3/client/petstore/ocaml/src/models/pet.ml
Normal file
26
samples/openapi3/client/petstore/ocaml/src/models/pet.ml
Normal file
@ -0,0 +1,26 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
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 { strict = false }, show ];;
|
||||
|
||||
let create (name : string) (photo_urls : string list) : t = {
|
||||
id = None;
|
||||
category = None;
|
||||
name = name;
|
||||
photo_urls = photo_urls;
|
||||
tags = [];
|
||||
status = None;
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
bar: string option [@default None];
|
||||
baz: string option [@default None];
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create () : t = {
|
||||
bar = None;
|
||||
baz = None;
|
||||
}
|
||||
|
17
samples/openapi3/client/petstore/ocaml/src/models/return.ml
Normal file
17
samples/openapi3/client/petstore/ocaml/src/models/return.ml
Normal file
@ -0,0 +1,17 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
* Schema Return.t : Model for testing reserved words
|
||||
*)
|
||||
|
||||
type t = {
|
||||
return: int32 option [@default None];
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
(** Model for testing reserved words *)
|
||||
let create () : t = {
|
||||
return = None;
|
||||
}
|
||||
|
17
samples/openapi3/client/petstore/ocaml/src/models/tag.ml
Normal file
17
samples/openapi3/client/petstore/ocaml/src/models/tag.ml
Normal file
@ -0,0 +1,17 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type t = {
|
||||
id: int64 option [@default None];
|
||||
name: string option [@default None];
|
||||
} [@@deriving yojson { strict = false }, show ];;
|
||||
|
||||
let create () : t = {
|
||||
id = None;
|
||||
name = None;
|
||||
}
|
||||
|
30
samples/openapi3/client/petstore/ocaml/src/models/user.ml
Normal file
30
samples/openapi3/client/petstore/ocaml/src/models/user.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 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 { strict = false }, show ];;
|
||||
|
||||
let create () : t = {
|
||||
id = None;
|
||||
username = None;
|
||||
first_name = None;
|
||||
last_name = None;
|
||||
email = None;
|
||||
password = None;
|
||||
phone = None;
|
||||
user_status = None;
|
||||
}
|
||||
|
142
samples/openapi3/client/petstore/ocaml/src/support/enums.ml
Normal file
142
samples/openapi3/client/petstore/ocaml/src/support/enums.ml
Normal file
@ -0,0 +1,142 @@
|
||||
(*
|
||||
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
|
||||
*
|
||||
* Generated by: https://openapi-generator.tech
|
||||
*
|
||||
*)
|
||||
|
||||
type outerenuminteger = [
|
||||
| `_0 [@printer fun fmt _ -> Format.pp_print_string fmt "0"] [@name "0"]
|
||||
| `_1 [@printer fun fmt _ -> Format.pp_print_string fmt "1"] [@name "1"]
|
||||
| `_2 [@printer fun fmt _ -> Format.pp_print_string fmt "2"] [@name "2"]
|
||||
] [@@deriving yojson, show { with_path = false }];;
|
||||
|
||||
let outerenuminteger_of_yojson json = outerenuminteger_of_yojson (`List [json])
|
||||
let outerenuminteger_to_yojson e =
|
||||
match outerenuminteger_to_yojson e with
|
||||
| `List [json] -> json
|
||||
| json -> json
|
||||
|
||||
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 enum_query_integer = [
|
||||
| `_1 [@printer fun fmt _ -> Format.pp_print_string fmt "1"] [@name "1"]
|
||||
| `Minus2 [@printer fun fmt _ -> Format.pp_print_string fmt "-2"] [@name "-2"]
|
||||
] [@@deriving yojson, show { with_path = false }];;
|
||||
|
||||
let enum_query_integer_of_yojson json = enum_query_integer_of_yojson (`List [json])
|
||||
let enum_query_integer_to_yojson e =
|
||||
match enum_query_integer_to_yojson e with
|
||||
| `List [json] -> json
|
||||
| json -> json
|
||||
|
||||
type enum_form_string_array = [
|
||||
| `Greater_Than [@printer fun fmt _ -> Format.pp_print_string fmt ">"] [@name ">"]
|
||||
| `Dollar [@printer fun fmt _ -> Format.pp_print_string fmt "$"] [@name "$"]
|
||||
] [@@deriving yojson, show { with_path = false }];;
|
||||
|
||||
let enum_form_string_array_of_yojson json = enum_form_string_array_of_yojson (`List [json])
|
||||
let enum_form_string_array_to_yojson e =
|
||||
match enum_form_string_array_to_yojson e with
|
||||
| `List [json] -> json
|
||||
| json -> json
|
||||
|
||||
type enum_number = [
|
||||
| `_1Period1 [@printer fun fmt _ -> Format.pp_print_string fmt "1.1"] [@name "1.1"]
|
||||
| `Minus1Period2 [@printer fun fmt _ -> Format.pp_print_string fmt "-1.2"] [@name "-1.2"]
|
||||
] [@@deriving yojson, show { with_path = false }];;
|
||||
|
||||
let enum_number_of_yojson json = enum_number_of_yojson (`List [json])
|
||||
let enum_number_to_yojson e =
|
||||
match enum_number_to_yojson e with
|
||||
| `List [json] -> json
|
||||
| json -> json
|
||||
|
||||
type map_of_enum_string = [
|
||||
| `UPPER [@printer fun fmt _ -> Format.pp_print_string fmt "UPPER"] [@name "UPPER"]
|
||||
| `Lower [@printer fun fmt _ -> Format.pp_print_string fmt "lower"] [@name "lower"]
|
||||
] [@@deriving yojson, show { with_path = false }];;
|
||||
|
||||
let map_of_enum_string_of_yojson json = map_of_enum_string_of_yojson (`List [json])
|
||||
let map_of_enum_string_to_yojson e =
|
||||
match map_of_enum_string_to_yojson e with
|
||||
| `List [json] -> json
|
||||
| json -> json
|
||||
|
||||
type enum_integer = [
|
||||
| `_1 [@printer fun fmt _ -> Format.pp_print_string fmt "1"] [@name "1"]
|
||||
| `Minus1 [@printer fun fmt _ -> Format.pp_print_string fmt "-1"] [@name "-1"]
|
||||
] [@@deriving yojson, show { with_path = false }];;
|
||||
|
||||
let enum_integer_of_yojson json = enum_integer_of_yojson (`List [json])
|
||||
let enum_integer_to_yojson e =
|
||||
match enum_integer_to_yojson e with
|
||||
| `List [json] -> json
|
||||
| json -> json
|
||||
|
||||
type just_symbol = [
|
||||
| `Greater_ThanEqual [@printer fun fmt _ -> Format.pp_print_string fmt ">="] [@name ">="]
|
||||
| `Dollar [@printer fun fmt _ -> Format.pp_print_string fmt "$"] [@name "$"]
|
||||
] [@@deriving yojson, show { with_path = false }];;
|
||||
|
||||
let just_symbol_of_yojson json = just_symbol_of_yojson (`List [json])
|
||||
let just_symbol_to_yojson e =
|
||||
match just_symbol_to_yojson e with
|
||||
| `List [json] -> json
|
||||
| json -> json
|
||||
|
||||
type array_enum = [
|
||||
| `Fish [@printer fun fmt _ -> Format.pp_print_string fmt "fish"] [@name "fish"]
|
||||
| `Crab [@printer fun fmt _ -> Format.pp_print_string fmt "crab"] [@name "crab"]
|
||||
] [@@deriving yojson, show { with_path = false }];;
|
||||
|
||||
let array_enum_of_yojson json = array_enum_of_yojson (`List [json])
|
||||
let array_enum_to_yojson e =
|
||||
match array_enum_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
|
||||
|
||||
type enumclass = [
|
||||
| `_abc [@printer fun fmt _ -> Format.pp_print_string fmt "_abc"] [@name "_abc"]
|
||||
| `Minusefg [@printer fun fmt _ -> Format.pp_print_string fmt "-efg"] [@name "-efg"]
|
||||
| `Left_ParenthesisxyzRight_Parenthesis [@printer fun fmt _ -> Format.pp_print_string fmt "(xyz)"] [@name "(xyz)"]
|
||||
] [@@deriving yojson, show { with_path = false }];;
|
||||
|
||||
let enumclass_of_yojson json = enumclass_of_yojson (`List [json])
|
||||
let enumclass_to_yojson e =
|
||||
match enumclass_to_yojson e with
|
||||
| `List [json] -> json
|
||||
| json -> json
|
||||
|
||||
type enum_string = [
|
||||
| `UPPER [@printer fun fmt _ -> Format.pp_print_string fmt "UPPER"] [@name "UPPER"]
|
||||
| `Lower [@printer fun fmt _ -> Format.pp_print_string fmt "lower"] [@name "lower"]
|
||||
] [@@deriving yojson, show { with_path = false }];;
|
||||
|
||||
let enum_string_of_yojson json = enum_string_of_yojson (`List [json])
|
||||
let enum_string_to_yojson e =
|
||||
match enum_string_to_yojson e with
|
||||
| `List [json] -> json
|
||||
| json -> json
|
@ -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)
|
@ -0,0 +1,97 @@
|
||||
let api_key = ""
|
||||
let base_url = "http://petstore.swagger.io:80/v2"
|
||||
let default_headers = Cohttp.Header.init_with "Content-Type" "application/json"
|
||||
|
||||
let option_fold f default o =
|
||||
match o with
|
||||
| Some v -> f v
|
||||
| None -> default
|
||||
|
||||
let build_uri operation_path = Uri.of_string (base_url ^ operation_path)
|
||||
|
||||
let add_string_header headers key value =
|
||||
Cohttp.Header.add headers key value
|
||||
|
||||
let add_string_header_multi headers key values =
|
||||
Cohttp.Header.add_multi headers key values
|
||||
|
||||
let add_header headers key to_string value =
|
||||
Cohttp.Header.add headers key (to_string value)
|
||||
|
||||
let add_header_multi headers key to_string value =
|
||||
Cohttp.Header.add_multi headers key (to_string value)
|
||||
|
||||
let maybe_add_header headers key to_string value =
|
||||
option_fold (add_header headers key to_string) headers value
|
||||
|
||||
let maybe_add_header_multi headers key to_string value =
|
||||
option_fold (add_header_multi headers key to_string) headers value
|
||||
|
||||
let write_string_body s = Cohttp_lwt.Body.of_string s
|
||||
|
||||
let write_json_body payload =
|
||||
Cohttp_lwt.Body.of_string (Yojson.Safe.to_string payload ~std:true)
|
||||
|
||||
let write_as_json_body to_json payload = write_json_body (to_json payload)
|
||||
|
||||
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 resp body =
|
||||
Lwt.(read_json_body resp body >|= Yojson.Safe.Util.to_assoc)
|
||||
|
||||
let read_json_body_as_map_of of_json resp body =
|
||||
Lwt.(read_json_body_as_map resp body >|= List.map (fun (s, v) -> (s, of_json v)))
|
||||
|
||||
let replace_string_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.pct_decode (Uri.path uri)) in
|
||||
Uri.with_path uri path
|
||||
|
||||
let replace_path_param uri param_name to_string param_value =
|
||||
replace_string_path_param uri param_name (to_string param_value)
|
||||
|
||||
let maybe_replace_path_param uri param_name to_string param_value =
|
||||
option_fold (replace_path_param uri param_name to_string) uri param_value
|
||||
|
||||
let add_query_param uri param_name to_string param_value =
|
||||
Uri.add_query_param' uri (param_name, to_string param_value)
|
||||
|
||||
let add_query_param_list uri param_name to_string param_value =
|
||||
Uri.add_query_param uri (param_name, to_string param_value)
|
||||
|
||||
let maybe_add_query_param uri param_name to_string param_value =
|
||||
option_fold (add_query_param uri param_name to_string) uri param_value
|
||||
|
||||
let init_form_encoded_body () = ""
|
||||
|
||||
let add_form_encoded_body_param params param_name to_string param_value =
|
||||
let new_param_enc = Printf.sprintf {|%s=%s|} (Uri.pct_encode param_name) (Uri.pct_encode (to_string param_value)) in
|
||||
if params = ""
|
||||
then new_param_enc
|
||||
else Printf.sprintf {|%s&%s|} params new_param_enc
|
||||
|
||||
let add_form_encoded_body_param_list params param_name to_string new_params =
|
||||
add_form_encoded_body_param params param_name (String.concat ",") (to_string new_params)
|
||||
|
||||
let maybe_add_form_encoded_body_param params param_name to_string param_value =
|
||||
option_fold (add_form_encoded_body_param params param_name to_string) params param_value
|
||||
|
||||
let finalize_form_encoded_body body = Cohttp_lwt.Body.of_string body
|
Loading…
x
Reference in New Issue
Block a user