From 411199bc9954c14779201e569d5f475ffb3e4be0 Mon Sep 17 00:00:00 2001 From: cgensoul <53224246+cgensoul@users.noreply.github.com> Date: Wed, 7 Aug 2019 05:25:32 +0200 Subject: [PATCH] [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. --- .../codegen/languages/OCamlClientCodegen.java | 16 +- .../main/resources/ocaml/api-impl.mustache | 63 ++++++-- .../main/resources/ocaml/api-intf.mustache | 2 +- .../src/main/resources/ocaml/model.mustache | 4 +- .../src/main/resources/ocaml/support.mustache | 53 ++++++- .../ocaml/to_optional_prefix.mustache | 1 + .../main/resources/ocaml/to_param.mustache | 1 + .../main/resources/ocaml/to_string.mustache | 2 +- .../client/petstore/ocaml/src/apis/pet_api.ml | 39 ++--- .../petstore/ocaml/src/apis/pet_api.mli | 16 +- .../petstore/ocaml/src/apis/store_api.ml | 11 +- .../petstore/ocaml/src/apis/store_api.mli | 6 +- .../petstore/ocaml/src/apis/user_api.ml | 24 +-- .../petstore/ocaml/src/apis/user_api.mli | 14 +- .../petstore/ocaml/src/models/api_response.ml | 2 +- .../petstore/ocaml/src/models/category.ml | 2 +- .../client/petstore/ocaml/src/models/order.ml | 2 +- .../client/petstore/ocaml/src/models/pet.ml | 2 +- .../client/petstore/ocaml/src/models/tag.ml | 2 +- .../client/petstore/ocaml/src/models/user.ml | 2 +- .../petstore/ocaml/src/support/request.ml | 53 ++++++- .../petstore/ocaml/.openapi-generator-ignore | 23 +++ .../petstore/ocaml/.openapi-generator/VERSION | 1 + .../openapi3/client/petstore/ocaml/README.md | 27 ++++ samples/openapi3/client/petstore/ocaml/dune | 9 ++ .../client/petstore/ocaml/dune-project | 2 + .../petstore/ocaml/petstore_client.opam | 15 ++ .../ocaml/src/apis/another_fake_api.ml | 15 ++ .../ocaml/src/apis/another_fake_api.mli | 8 + .../petstore/ocaml/src/apis/default_api.ml | 14 ++ .../petstore/ocaml/src/apis/default_api.mli | 8 + .../petstore/ocaml/src/apis/fake_api.ml | 143 ++++++++++++++++++ .../petstore/ocaml/src/apis/fake_api.mli | 20 +++ .../src/apis/fake_classname_tags123_api.ml | 16 ++ .../src/apis/fake_classname_tags123_api.mli | 8 + .../client/petstore/ocaml/src/apis/pet_api.ml | 93 ++++++++++++ .../petstore/ocaml/src/apis/pet_api.mli | 16 ++ .../petstore/ocaml/src/apis/store_api.ml | 39 +++++ .../petstore/ocaml/src/apis/store_api.mli | 11 ++ .../petstore/ocaml/src/apis/user_api.ml | 72 +++++++++ .../petstore/ocaml/src/apis/user_api.mli | 15 ++ .../src/models/additional_properties_class.ml | 17 +++ .../petstore/ocaml/src/models/animal.ml | 17 +++ .../petstore/ocaml/src/models/api_response.ml | 19 +++ .../models/array_of_array_of_number_only.ml | 15 ++ .../ocaml/src/models/array_of_number_only.ml | 15 ++ .../petstore/ocaml/src/models/array_test.ml | 19 +++ .../ocaml/src/models/capitalization.ml | 26 ++++ .../client/petstore/ocaml/src/models/cat.ml | 19 +++ .../petstore/ocaml/src/models/cat_all_of.ml | 15 ++ .../petstore/ocaml/src/models/category.ml | 17 +++ .../petstore/ocaml/src/models/class_model.ml | 17 +++ .../petstore/ocaml/src/models/client.ml | 15 ++ .../client/petstore/ocaml/src/models/dog.ml | 19 +++ .../petstore/ocaml/src/models/dog_all_of.ml | 15 ++ .../petstore/ocaml/src/models/enum_arrays.ml | 17 +++ .../petstore/ocaml/src/models/enum_test.ml | 29 ++++ .../client/petstore/ocaml/src/models/file.ml | 18 +++ .../src/models/file_schema_test_class.ml | 17 +++ .../client/petstore/ocaml/src/models/foo.ml | 15 ++ .../petstore/ocaml/src/models/format_test.ml | 45 ++++++ .../ocaml/src/models/has_only_read_only.ml | 17 +++ .../ocaml/src/models/health_check_result.ml | 17 +++ .../ocaml/src/models/inline_object.ml | 19 +++ .../ocaml/src/models/inline_object_1.ml | 19 +++ .../ocaml/src/models/inline_object_2.ml | 19 +++ .../ocaml/src/models/inline_object_3.ml | 55 +++++++ .../ocaml/src/models/inline_object_4.ml | 19 +++ .../ocaml/src/models/inline_object_5.ml | 19 +++ .../src/models/inline_response_default.ml | 15 ++ .../petstore/ocaml/src/models/map_test.ml | 21 +++ ...perties_and_additional_properties_class.ml | 19 +++ .../ocaml/src/models/model_200_response.ml | 19 +++ .../src/models/model__special_model_name_.ml | 15 ++ .../client/petstore/ocaml/src/models/name.ml | 23 +++ .../ocaml/src/models/nullable_class.ml | 37 +++++ .../petstore/ocaml/src/models/number_only.ml | 15 ++ .../client/petstore/ocaml/src/models/order.ml | 26 ++++ .../ocaml/src/models/outer_composite.ml | 19 +++ .../client/petstore/ocaml/src/models/pet.ml | 26 ++++ .../ocaml/src/models/read_only_first.ml | 17 +++ .../petstore/ocaml/src/models/return.ml | 17 +++ .../client/petstore/ocaml/src/models/tag.ml | 17 +++ .../client/petstore/ocaml/src/models/user.ml | 30 ++++ .../petstore/ocaml/src/support/enums.ml | 142 +++++++++++++++++ .../petstore/ocaml/src/support/jsonSupport.ml | 55 +++++++ .../petstore/ocaml/src/support/request.ml | 97 ++++++++++++ 87 files changed, 1962 insertions(+), 90 deletions(-) create mode 100644 modules/openapi-generator/src/main/resources/ocaml/to_optional_prefix.mustache create mode 100644 modules/openapi-generator/src/main/resources/ocaml/to_param.mustache create mode 100644 samples/openapi3/client/petstore/ocaml/.openapi-generator-ignore create mode 100644 samples/openapi3/client/petstore/ocaml/.openapi-generator/VERSION create mode 100644 samples/openapi3/client/petstore/ocaml/README.md create mode 100644 samples/openapi3/client/petstore/ocaml/dune create mode 100644 samples/openapi3/client/petstore/ocaml/dune-project create mode 100644 samples/openapi3/client/petstore/ocaml/petstore_client.opam create mode 100644 samples/openapi3/client/petstore/ocaml/src/apis/another_fake_api.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/apis/another_fake_api.mli create mode 100644 samples/openapi3/client/petstore/ocaml/src/apis/default_api.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/apis/default_api.mli create mode 100644 samples/openapi3/client/petstore/ocaml/src/apis/fake_api.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/apis/fake_api.mli create mode 100644 samples/openapi3/client/petstore/ocaml/src/apis/fake_classname_tags123_api.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/apis/fake_classname_tags123_api.mli create mode 100644 samples/openapi3/client/petstore/ocaml/src/apis/pet_api.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/apis/pet_api.mli create mode 100644 samples/openapi3/client/petstore/ocaml/src/apis/store_api.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/apis/store_api.mli create mode 100644 samples/openapi3/client/petstore/ocaml/src/apis/user_api.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/apis/user_api.mli create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/additional_properties_class.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/animal.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/api_response.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/array_of_array_of_number_only.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/array_of_number_only.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/array_test.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/capitalization.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/cat.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/cat_all_of.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/category.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/class_model.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/client.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/dog.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/dog_all_of.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/enum_arrays.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/enum_test.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/file.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/file_schema_test_class.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/foo.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/format_test.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/has_only_read_only.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/health_check_result.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/inline_object.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/inline_object_1.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/inline_object_2.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/inline_object_3.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/inline_object_4.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/inline_object_5.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/inline_response_default.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/map_test.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/mixed_properties_and_additional_properties_class.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/model_200_response.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/model__special_model_name_.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/name.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/nullable_class.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/number_only.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/order.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/outer_composite.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/pet.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/read_only_first.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/return.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/tag.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/models/user.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/support/enums.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/support/jsonSupport.ml create mode 100644 samples/openapi3/client/petstore/ocaml/src/support/request.ml diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/OCamlClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/OCamlClientCodegen.java index 2e388012b15..a1fc7753de3 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/OCamlClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/OCamlClientCodegen.java @@ -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; diff --git a/modules/openapi-generator/src/main/resources/ocaml/api-impl.mustache b/modules/openapi-generator/src/main/resources/ocaml/api-impl.mustache index dc0c5d96776..8e86eeb45ab 100644 --- a/modules/openapi-generator/src/main/resources/ocaml/api-impl.mustache +++ b/modules/openapi-generator/src/main/resources/ocaml/api-impl.mustache @@ -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}} diff --git a/modules/openapi-generator/src/main/resources/ocaml/api-intf.mustache b/modules/openapi-generator/src/main/resources/ocaml/api-intf.mustache index 8bd8de3a4e6..42525de317c 100644 --- a/modules/openapi-generator/src/main/resources/ocaml/api-intf.mustache +++ b/modules/openapi-generator/src/main/resources/ocaml/api-intf.mustache @@ -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}} diff --git a/modules/openapi-generator/src/main/resources/ocaml/model.mustache b/modules/openapi-generator/src/main/resources/ocaml/model.mustache index 33fc27af079..dd45db1915b 100644 --- a/modules/openapi-generator/src/main/resources/ocaml/model.mustache +++ b/modules/openapi-generator/src/main/resources/ocaml/model.mustache @@ -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}}} *) diff --git a/modules/openapi-generator/src/main/resources/ocaml/support.mustache b/modules/openapi-generator/src/main/resources/ocaml/support.mustache index 09e5b1a922e..bc6d7a86f98 100644 --- a/modules/openapi-generator/src/main/resources/ocaml/support.mustache +++ b/modules/openapi-generator/src/main/resources/ocaml/support.mustache @@ -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 diff --git a/modules/openapi-generator/src/main/resources/ocaml/to_optional_prefix.mustache b/modules/openapi-generator/src/main/resources/ocaml/to_optional_prefix.mustache new file mode 100644 index 00000000000..aa35be7da04 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/ocaml/to_optional_prefix.mustache @@ -0,0 +1 @@ +{{^required}}{{^defaultValue}}{{^isContainer}}maybe_{{/isContainer}}{{/defaultValue}}{{/required}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/ocaml/to_param.mustache b/modules/openapi-generator/src/main/resources/ocaml/to_param.mustache new file mode 100644 index 00000000000..59bd7672b9c --- /dev/null +++ b/modules/openapi-generator/src/main/resources/ocaml/to_param.mustache @@ -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}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/ocaml/to_string.mustache b/modules/openapi-generator/src/main/resources/ocaml/to_string.mustache index 9e5b60af842..0588ac5ab4f 100644 --- a/modules/openapi-generator/src/main/resources/ocaml/to_string.mustache +++ b/modules/openapi-generator/src/main/resources/ocaml/to_string.mustache @@ -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}} \ No newline at end of file +{{#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}} \ No newline at end of file diff --git a/samples/client/petstore/ocaml/src/apis/pet_api.ml b/samples/client/petstore/ocaml/src/apis/pet_api.ml index bb0ebbc55e7..ec3d3674fb2 100644 --- a/samples/client/petstore/ocaml/src/apis/pet_api.ml +++ b/samples/client/petstore/ocaml/src/apis/pet_api.ml @@ -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 diff --git a/samples/client/petstore/ocaml/src/apis/pet_api.mli b/samples/client/petstore/ocaml/src/apis/pet_api.mli index 0cc31e085cf..301beaa2c72 100644 --- a/samples/client/petstore/ocaml/src/apis/pet_api.mli +++ b/samples/client/petstore/ocaml/src/apis/pet_api.mli @@ -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 diff --git a/samples/client/petstore/ocaml/src/apis/store_api.ml b/samples/client/petstore/ocaml/src/apis/store_api.ml index b9e7f536388..187cbbb5188 100644 --- a/samples/client/petstore/ocaml/src/apis/store_api.ml +++ b/samples/client/petstore/ocaml/src/apis/store_api.ml @@ -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 diff --git a/samples/client/petstore/ocaml/src/apis/store_api.mli b/samples/client/petstore/ocaml/src/apis/store_api.mli index bc3c93eb494..53c81ec52c7 100644 --- a/samples/client/petstore/ocaml/src/apis/store_api.mli +++ b/samples/client/petstore/ocaml/src/apis/store_api.mli @@ -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 diff --git a/samples/client/petstore/ocaml/src/apis/user_api.ml b/samples/client/petstore/ocaml/src/apis/user_api.ml index bf6e7cfc52d..5c1027f601c 100644 --- a/samples/client/petstore/ocaml/src/apis/user_api.ml +++ b/samples/client/petstore/ocaml/src/apis/user_api.ml @@ -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 diff --git a/samples/client/petstore/ocaml/src/apis/user_api.mli b/samples/client/petstore/ocaml/src/apis/user_api.mli index 5191a2ea41b..5ea7ba2471f 100644 --- a/samples/client/petstore/ocaml/src/apis/user_api.mli +++ b/samples/client/petstore/ocaml/src/apis/user_api.mli @@ -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 diff --git a/samples/client/petstore/ocaml/src/models/api_response.ml b/samples/client/petstore/ocaml/src/models/api_response.ml index f1b960d1449..1b5a0aabac2 100644 --- a/samples/client/petstore/ocaml/src/models/api_response.ml +++ b/samples/client/petstore/ocaml/src/models/api_response.ml @@ -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 = { diff --git a/samples/client/petstore/ocaml/src/models/category.ml b/samples/client/petstore/ocaml/src/models/category.ml index 31b9c3aab1d..830f34bc07b 100644 --- a/samples/client/petstore/ocaml/src/models/category.ml +++ b/samples/client/petstore/ocaml/src/models/category.ml @@ -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 = { diff --git a/samples/client/petstore/ocaml/src/models/order.ml b/samples/client/petstore/ocaml/src/models/order.ml index 6130f88fd95..e9f6a808003 100644 --- a/samples/client/petstore/ocaml/src/models/order.ml +++ b/samples/client/petstore/ocaml/src/models/order.ml @@ -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 = { diff --git a/samples/client/petstore/ocaml/src/models/pet.ml b/samples/client/petstore/ocaml/src/models/pet.ml index 5d267ef32db..a1f379778ab 100644 --- a/samples/client/petstore/ocaml/src/models/pet.ml +++ b/samples/client/petstore/ocaml/src/models/pet.ml @@ -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 = { diff --git a/samples/client/petstore/ocaml/src/models/tag.ml b/samples/client/petstore/ocaml/src/models/tag.ml index 5570d9c8eaf..3c33625f198 100644 --- a/samples/client/petstore/ocaml/src/models/tag.ml +++ b/samples/client/petstore/ocaml/src/models/tag.ml @@ -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 = { diff --git a/samples/client/petstore/ocaml/src/models/user.ml b/samples/client/petstore/ocaml/src/models/user.ml index a9483d72889..586ef26b537 100644 --- a/samples/client/petstore/ocaml/src/models/user.ml +++ b/samples/client/petstore/ocaml/src/models/user.ml @@ -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 = { diff --git a/samples/client/petstore/ocaml/src/support/request.ml b/samples/client/petstore/ocaml/src/support/request.ml index 3d7fd640e54..35123b9ec90 100644 --- a/samples/client/petstore/ocaml/src/support/request.ml +++ b/samples/client/petstore/ocaml/src/support/request.ml @@ -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 diff --git a/samples/openapi3/client/petstore/ocaml/.openapi-generator-ignore b/samples/openapi3/client/petstore/ocaml/.openapi-generator-ignore new file mode 100644 index 00000000000..7484ee590a3 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/.openapi-generator-ignore @@ -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 diff --git a/samples/openapi3/client/petstore/ocaml/.openapi-generator/VERSION b/samples/openapi3/client/petstore/ocaml/.openapi-generator/VERSION new file mode 100644 index 00000000000..83a328a9227 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/.openapi-generator/VERSION @@ -0,0 +1 @@ +4.1.0-SNAPSHOT \ No newline at end of file diff --git a/samples/openapi3/client/petstore/ocaml/README.md b/samples/openapi3/client/petstore/ocaml/README.md new file mode 100644 index 00000000000..0f61cbb94ec --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/README.md @@ -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 + diff --git a/samples/openapi3/client/petstore/ocaml/dune b/samples/openapi3/client/petstore/ocaml/dune new file mode 100644 index 00000000000..ed1c4d90e3d --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/dune @@ -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) +) \ No newline at end of file diff --git a/samples/openapi3/client/petstore/ocaml/dune-project b/samples/openapi3/client/petstore/ocaml/dune-project new file mode 100644 index 00000000000..79d86e3c901 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/dune-project @@ -0,0 +1,2 @@ +(lang dune 1.10) +(name petstore_client) \ No newline at end of file diff --git a/samples/openapi3/client/petstore/ocaml/petstore_client.opam b/samples/openapi3/client/petstore/ocaml/petstore_client.opam new file mode 100644 index 00000000000..3c3603c2f14 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/petstore_client.opam @@ -0,0 +1,15 @@ +opam-version: "2.0" +name: "petstore_client" +version: "1.0.0" +synopsis: "" +description: """ +Longer description +""" +maintainer: "Name " +authors: "Name " +license: "" +homepage: "" +bug-reports: "" +dev-repo: "" +depends: [ "ocaml" "ocamlfind" ] +build: ["dune" "build" "-p" name] \ No newline at end of file diff --git a/samples/openapi3/client/petstore/ocaml/src/apis/another_fake_api.ml b/samples/openapi3/client/petstore/ocaml/src/apis/another_fake_api.ml new file mode 100644 index 00000000000..c147d4d0579 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/apis/another_fake_api.ml @@ -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 + diff --git a/samples/openapi3/client/petstore/ocaml/src/apis/another_fake_api.mli b/samples/openapi3/client/petstore/ocaml/src/apis/another_fake_api.mli new file mode 100644 index 00000000000..3e9e0c80484 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/apis/another_fake_api.mli @@ -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 diff --git a/samples/openapi3/client/petstore/ocaml/src/apis/default_api.ml b/samples/openapi3/client/petstore/ocaml/src/apis/default_api.ml new file mode 100644 index 00000000000..f220c4ba598 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/apis/default_api.ml @@ -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 + diff --git a/samples/openapi3/client/petstore/ocaml/src/apis/default_api.mli b/samples/openapi3/client/petstore/ocaml/src/apis/default_api.mli new file mode 100644 index 00000000000..f1392d7621c --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/apis/default_api.mli @@ -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 diff --git a/samples/openapi3/client/petstore/ocaml/src/apis/fake_api.ml b/samples/openapi3/client/petstore/ocaml/src/apis/fake_api.ml new file mode 100644 index 00000000000..e9fce6261b9 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/apis/fake_api.ml @@ -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 + diff --git a/samples/openapi3/client/petstore/ocaml/src/apis/fake_api.mli b/samples/openapi3/client/petstore/ocaml/src/apis/fake_api.mli new file mode 100644 index 00000000000..b10b27d6fb0 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/apis/fake_api.mli @@ -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 diff --git a/samples/openapi3/client/petstore/ocaml/src/apis/fake_classname_tags123_api.ml b/samples/openapi3/client/petstore/ocaml/src/apis/fake_classname_tags123_api.ml new file mode 100644 index 00000000000..09bf9c3d63e --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/apis/fake_classname_tags123_api.ml @@ -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 + diff --git a/samples/openapi3/client/petstore/ocaml/src/apis/fake_classname_tags123_api.mli b/samples/openapi3/client/petstore/ocaml/src/apis/fake_classname_tags123_api.mli new file mode 100644 index 00000000000..0f9a292c507 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/apis/fake_classname_tags123_api.mli @@ -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 diff --git a/samples/openapi3/client/petstore/ocaml/src/apis/pet_api.ml b/samples/openapi3/client/petstore/ocaml/src/apis/pet_api.ml new file mode 100644 index 00000000000..64fbc19ba0f --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/apis/pet_api.ml @@ -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 + diff --git a/samples/openapi3/client/petstore/ocaml/src/apis/pet_api.mli b/samples/openapi3/client/petstore/ocaml/src/apis/pet_api.mli new file mode 100644 index 00000000000..b3f4af03ce5 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/apis/pet_api.mli @@ -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 diff --git a/samples/openapi3/client/petstore/ocaml/src/apis/store_api.ml b/samples/openapi3/client/petstore/ocaml/src/apis/store_api.ml new file mode 100644 index 00000000000..f88b0217bfd --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/apis/store_api.ml @@ -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 + diff --git a/samples/openapi3/client/petstore/ocaml/src/apis/store_api.mli b/samples/openapi3/client/petstore/ocaml/src/apis/store_api.mli new file mode 100644 index 00000000000..63b09db9ca5 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/apis/store_api.mli @@ -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 diff --git a/samples/openapi3/client/petstore/ocaml/src/apis/user_api.ml b/samples/openapi3/client/petstore/ocaml/src/apis/user_api.ml new file mode 100644 index 00000000000..9d1a563d1e8 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/apis/user_api.ml @@ -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 + diff --git a/samples/openapi3/client/petstore/ocaml/src/apis/user_api.mli b/samples/openapi3/client/petstore/ocaml/src/apis/user_api.mli new file mode 100644 index 00000000000..9a7e8e59c3a --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/apis/user_api.mli @@ -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 diff --git a/samples/openapi3/client/petstore/ocaml/src/models/additional_properties_class.ml b/samples/openapi3/client/petstore/ocaml/src/models/additional_properties_class.ml new file mode 100644 index 00000000000..9dcaf86f9ec --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/additional_properties_class.ml @@ -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 = []; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/animal.ml b/samples/openapi3/client/petstore/ocaml/src/models/animal.ml new file mode 100644 index 00000000000..ac1ea09d155 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/animal.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/api_response.ml b/samples/openapi3/client/petstore/ocaml/src/models/api_response.ml new file mode 100644 index 00000000000..7e79b466928 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/api_response.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/array_of_array_of_number_only.ml b/samples/openapi3/client/petstore/ocaml/src/models/array_of_array_of_number_only.ml new file mode 100644 index 00000000000..b88dfe66f25 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/array_of_array_of_number_only.ml @@ -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 = []; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/array_of_number_only.ml b/samples/openapi3/client/petstore/ocaml/src/models/array_of_number_only.ml new file mode 100644 index 00000000000..88d8440639c --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/array_of_number_only.ml @@ -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 = []; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/array_test.ml b/samples/openapi3/client/petstore/ocaml/src/models/array_test.ml new file mode 100644 index 00000000000..dc3ec34c9f9 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/array_test.ml @@ -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 = []; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/capitalization.ml b/samples/openapi3/client/petstore/ocaml/src/models/capitalization.ml new file mode 100644 index 00000000000..7ea60bc00ad --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/capitalization.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/cat.ml b/samples/openapi3/client/petstore/ocaml/src/models/cat.ml new file mode 100644 index 00000000000..bd28b8ab731 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/cat.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/cat_all_of.ml b/samples/openapi3/client/petstore/ocaml/src/models/cat_all_of.ml new file mode 100644 index 00000000000..8ef4045a61f --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/cat_all_of.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/category.ml b/samples/openapi3/client/petstore/ocaml/src/models/category.ml new file mode 100644 index 00000000000..cb4c98edec4 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/category.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/class_model.ml b/samples/openapi3/client/petstore/ocaml/src/models/class_model.ml new file mode 100644 index 00000000000..69dfbf46dcc --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/class_model.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/client.ml b/samples/openapi3/client/petstore/ocaml/src/models/client.ml new file mode 100644 index 00000000000..20ccd895114 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/client.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/dog.ml b/samples/openapi3/client/petstore/ocaml/src/models/dog.ml new file mode 100644 index 00000000000..e3dd000c8d6 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/dog.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/dog_all_of.ml b/samples/openapi3/client/petstore/ocaml/src/models/dog_all_of.ml new file mode 100644 index 00000000000..1a02a8d8b9a --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/dog_all_of.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/enum_arrays.ml b/samples/openapi3/client/petstore/ocaml/src/models/enum_arrays.ml new file mode 100644 index 00000000000..99953247de1 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/enum_arrays.ml @@ -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 = []; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/enum_test.ml b/samples/openapi3/client/petstore/ocaml/src/models/enum_test.ml new file mode 100644 index 00000000000..67d474406f5 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/enum_test.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/file.ml b/samples/openapi3/client/petstore/ocaml/src/models/file.ml new file mode 100644 index 00000000000..72df1e20230 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/file.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/file_schema_test_class.ml b/samples/openapi3/client/petstore/ocaml/src/models/file_schema_test_class.ml new file mode 100644 index 00000000000..6ce6e13efda --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/file_schema_test_class.ml @@ -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 = []; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/foo.ml b/samples/openapi3/client/petstore/ocaml/src/models/foo.ml new file mode 100644 index 00000000000..73821fc1aaf --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/foo.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/format_test.ml b/samples/openapi3/client/petstore/ocaml/src/models/format_test.ml new file mode 100644 index 00000000000..a2c8bc72c5a --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/format_test.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/has_only_read_only.ml b/samples/openapi3/client/petstore/ocaml/src/models/has_only_read_only.ml new file mode 100644 index 00000000000..54db5e69ad7 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/has_only_read_only.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/health_check_result.ml b/samples/openapi3/client/petstore/ocaml/src/models/health_check_result.ml new file mode 100644 index 00000000000..4ff90c6cb4d --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/health_check_result.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/inline_object.ml b/samples/openapi3/client/petstore/ocaml/src/models/inline_object.ml new file mode 100644 index 00000000000..37a44a8d683 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/inline_object.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/inline_object_1.ml b/samples/openapi3/client/petstore/ocaml/src/models/inline_object_1.ml new file mode 100644 index 00000000000..2d453134c43 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/inline_object_1.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/inline_object_2.ml b/samples/openapi3/client/petstore/ocaml/src/models/inline_object_2.ml new file mode 100644 index 00000000000..1a007a7afe4 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/inline_object_2.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/inline_object_3.ml b/samples/openapi3/client/petstore/ocaml/src/models/inline_object_3.ml new file mode 100644 index 00000000000..7d58d3cdbe5 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/inline_object_3.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/inline_object_4.ml b/samples/openapi3/client/petstore/ocaml/src/models/inline_object_4.ml new file mode 100644 index 00000000000..8914801491a --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/inline_object_4.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/inline_object_5.ml b/samples/openapi3/client/petstore/ocaml/src/models/inline_object_5.ml new file mode 100644 index 00000000000..14ca3e41a98 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/inline_object_5.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/inline_response_default.ml b/samples/openapi3/client/petstore/ocaml/src/models/inline_response_default.ml new file mode 100644 index 00000000000..b30b92591bd --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/inline_response_default.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/map_test.ml b/samples/openapi3/client/petstore/ocaml/src/models/map_test.ml new file mode 100644 index 00000000000..2bdd8f156b4 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/map_test.ml @@ -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 = []; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/mixed_properties_and_additional_properties_class.ml b/samples/openapi3/client/petstore/ocaml/src/models/mixed_properties_and_additional_properties_class.ml new file mode 100644 index 00000000000..ba41c7e7069 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/mixed_properties_and_additional_properties_class.ml @@ -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 = []; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/model_200_response.ml b/samples/openapi3/client/petstore/ocaml/src/models/model_200_response.ml new file mode 100644 index 00000000000..4cd900d8a58 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/model_200_response.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/model__special_model_name_.ml b/samples/openapi3/client/petstore/ocaml/src/models/model__special_model_name_.ml new file mode 100644 index 00000000000..61bc6d001f4 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/model__special_model_name_.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/name.ml b/samples/openapi3/client/petstore/ocaml/src/models/name.ml new file mode 100644 index 00000000000..dc4d8da8fd8 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/name.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/nullable_class.ml b/samples/openapi3/client/petstore/ocaml/src/models/nullable_class.ml new file mode 100644 index 00000000000..e48c6f0d324 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/nullable_class.ml @@ -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 = []; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/number_only.ml b/samples/openapi3/client/petstore/ocaml/src/models/number_only.ml new file mode 100644 index 00000000000..907a9acac9b --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/number_only.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/order.ml b/samples/openapi3/client/petstore/ocaml/src/models/order.ml new file mode 100644 index 00000000000..19ddf1e02e6 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/order.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/outer_composite.ml b/samples/openapi3/client/petstore/ocaml/src/models/outer_composite.ml new file mode 100644 index 00000000000..ab5d8902e08 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/outer_composite.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/pet.ml b/samples/openapi3/client/petstore/ocaml/src/models/pet.ml new file mode 100644 index 00000000000..10d93f2552d --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/pet.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/read_only_first.ml b/samples/openapi3/client/petstore/ocaml/src/models/read_only_first.ml new file mode 100644 index 00000000000..7ebca9b2119 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/read_only_first.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/return.ml b/samples/openapi3/client/petstore/ocaml/src/models/return.ml new file mode 100644 index 00000000000..cb27db04936 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/return.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/tag.ml b/samples/openapi3/client/petstore/ocaml/src/models/tag.ml new file mode 100644 index 00000000000..4dc25fdca67 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/tag.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/models/user.ml b/samples/openapi3/client/petstore/ocaml/src/models/user.ml new file mode 100644 index 00000000000..81e7d4e4e02 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/models/user.ml @@ -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; +} + diff --git a/samples/openapi3/client/petstore/ocaml/src/support/enums.ml b/samples/openapi3/client/petstore/ocaml/src/support/enums.ml new file mode 100644 index 00000000000..63ec5f49f85 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/support/enums.ml @@ -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 diff --git a/samples/openapi3/client/petstore/ocaml/src/support/jsonSupport.ml b/samples/openapi3/client/petstore/ocaml/src/support/jsonSupport.ml new file mode 100644 index 00000000000..4b0fac77545 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/support/jsonSupport.ml @@ -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) \ No newline at end of file diff --git a/samples/openapi3/client/petstore/ocaml/src/support/request.ml b/samples/openapi3/client/petstore/ocaml/src/support/request.ml new file mode 100644 index 00000000000..98f4dfd43a4 --- /dev/null +++ b/samples/openapi3/client/petstore/ocaml/src/support/request.ml @@ -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