diff --git a/.github/workflows/samples-ocaml.yaml b/.github/workflows/samples-ocaml.yaml index 884ecc4a4c5f..9206c578d893 100644 --- a/.github/workflows/samples-ocaml.yaml +++ b/.github/workflows/samples-ocaml.yaml @@ -4,9 +4,13 @@ on: push: paths: - 'samples/client/petstore/ocaml/**' + - 'samples/client/petstore/ocaml-fake-petstore/**' + - 'samples/client/petstore/ocaml-oneOf/**' pull_request: paths: - 'samples/client/petstore/ocaml/**' + - 'samples/client/petstore/ocaml-fake-petstore/**' + - 'samples/client/petstore/ocaml-oneOf/**' jobs: build: @@ -17,6 +21,8 @@ jobs: matrix: sample: - 'samples/client/petstore/ocaml/' + - 'samples/client/petstore/ocaml-fake-petstore/' + - 'samples/client/petstore/ocaml-oneOf/' steps: - uses: actions/checkout@v5 - name: Set-up OCaml diff --git a/.gitignore b/.gitignore index 5c6df879f35d..36854746a1f0 100644 --- a/.gitignore +++ b/.gitignore @@ -296,6 +296,8 @@ samples/openapi3/client/petstore/go/privatekey.pem ## OCaml samples/client/petstore/ocaml/_build/ +samples/client/petstore/ocaml-fake-petstore/_build/ +samples/client/petstore/ocaml-oneOf/_build/ # jetbrain http client samples/client/jetbrains/adyen/checkout71/http/client/Apis/http-client.private.env.json diff --git a/bin/configs/ocaml-fake-petstore.yaml b/bin/configs/ocaml-fake-petstore.yaml new file mode 100644 index 000000000000..dcaf631f34fb --- /dev/null +++ b/bin/configs/ocaml-fake-petstore.yaml @@ -0,0 +1,6 @@ +generatorName: ocaml +outputDir: samples/client/petstore/ocaml-fake-petstore +inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml +templateDir: modules/openapi-generator/src/main/resources/ocaml +additionalProperties: + packageName: petstore_client diff --git a/bin/configs/ocaml-oneOf.yaml b/bin/configs/ocaml-oneOf.yaml new file mode 100644 index 000000000000..7bd6601e2c9f --- /dev/null +++ b/bin/configs/ocaml-oneOf.yaml @@ -0,0 +1,6 @@ +generatorName: ocaml +outputDir: samples/client/petstore/ocaml-oneOf +inputSpec: modules/openapi-generator/src/test/resources/3_0/oneOf_primitive.yaml +templateDir: modules/openapi-generator/src/main/resources/ocaml +additionalProperties: + packageName: petstore_client diff --git a/docs/generators/ocaml.md b/docs/generators/ocaml.md index d2bbfecfa3e0..9f98b06ac073 100644 --- a/docs/generators/ocaml.md +++ b/docs/generators/ocaml.md @@ -209,8 +209,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl |Polymorphism|✗|OAS2,OAS3 |Union|✗|OAS3 |allOf|✗|OAS2,OAS3 -|anyOf|✗|OAS3 -|oneOf|✗|OAS3 +|anyOf|✓|OAS3 +|oneOf|✓|OAS3 |not|✗|OAS3 ### Security Feature 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 2c963f78ce31..b3942140dd53 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 @@ -51,8 +51,6 @@ public class OCamlClientCodegen extends DefaultCodegen implements CodegenConfig static final String X_MODEL_MODULE = "x-model-module"; - public static final String CO_HTTP = "cohttp"; - @Setter protected String packageName = "openapi"; @Setter protected String packageVersion = "1.0.0"; protected String apiDocPath = "docs/"; @@ -97,12 +95,15 @@ public OCamlClientCodegen() { .excludeSchemaSupportFeatures( SchemaSupportFeature.Polymorphism ) + .includeSchemaSupportFeatures( + SchemaSupportFeature.oneOf, + SchemaSupportFeature.anyOf + ) .includeClientModificationFeatures( ClientModificationFeature.BasePath ) ); - outputFolder = "generated-code/ocaml"; modelTemplateFiles.put("model.mustache", ".ml"); @@ -171,6 +172,7 @@ public OCamlClientCodegen() { typeMapping.put("short", "int"); typeMapping.put("char", "char"); typeMapping.put("float", "float"); + typeMapping.put("decimal", "string"); typeMapping.put("double", "float"); typeMapping.put("integer", "int32"); typeMapping.put("number", "float"); @@ -179,6 +181,7 @@ public OCamlClientCodegen() { typeMapping.put("any", "Yojson.Safe.t"); typeMapping.put("file", "string"); typeMapping.put("ByteArray", "string"); + typeMapping.put("AnyType", "Yojson.Safe.t"); // lib typeMapping.put("string", "string"); typeMapping.put("UUID", "string"); @@ -186,15 +189,6 @@ public OCamlClientCodegen() { typeMapping.put("set", "`Set"); typeMapping.put("password", "string"); typeMapping.put("DateTime", "string"); - -// supportedLibraries.put(CO_HTTP, "HTTP client: CoHttp."); -// -// CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use."); -// libraryOption.setEnum(supportedLibraries); -// // set hyper as the default -// libraryOption.setDefault(CO_HTTP); -// cliOptions.add(libraryOption); -// setLibrary(CO_HTTP); } @Override @@ -202,13 +196,12 @@ public Map postProcessAllModels(Map supero List toRemove = new ArrayList<>(); for (Map.Entry modelEntry : superobjs.entrySet()) { - // process enum in models List models = modelEntry.getValue().getModels(); for (ModelMap mo : models) { CodegenModel cm = mo.getModel(); // for enum model - if (Boolean.TRUE.equals(cm.isEnum) && cm.allowableValues != null) { + if (cm.isEnum && cm.allowableValues != null) { toRemove.add(modelEntry.getKey()); } else { enrichPropertiesWithEnumDefaultValues(cm.getAllVars()); @@ -219,6 +212,15 @@ public Map postProcessAllModels(Map supero enrichPropertiesWithEnumDefaultValues(cm.getVars()); enrichPropertiesWithEnumDefaultValues(cm.getParentVars()); } + + if (!cm.oneOf.isEmpty()) { + // Add a boolean if it is a `oneOf`, because Mustache does not let us check if a list is non-empty + cm.getVendorExtensions().put("x-ocaml-isOneOf", true); + } + if (!cm.anyOf.isEmpty()) { + // Add a boolean if it is a `anyOf`, because Mustache does not let us check if a list is non-empty + cm.getVendorExtensions().put("x-ocaml-isAnyOf", true); + } } } @@ -242,8 +244,7 @@ private void enrichPropertiesWithEnumDefaultValues(List propert @Override protected void updateDataTypeWithEnumForMap(CodegenProperty property) { CodegenProperty baseItem = property.items; - while (baseItem != null && (Boolean.TRUE.equals(baseItem.isMap) - || Boolean.TRUE.equals(baseItem.isArray))) { + while (baseItem != null && (baseItem.isMap || baseItem.isArray)) { baseItem = baseItem.items; } @@ -260,8 +261,7 @@ protected void updateDataTypeWithEnumForMap(CodegenProperty property) { @Override protected void updateDataTypeWithEnumForArray(CodegenProperty property) { CodegenProperty baseItem = property.items; - while (baseItem != null && (Boolean.TRUE.equals(baseItem.isMap) - || Boolean.TRUE.equals(baseItem.isArray))) { + while (baseItem != null && (baseItem.isMap || baseItem.isArray)) { baseItem = baseItem.items; } if (baseItem != null) { @@ -312,19 +312,17 @@ private void collectEnumSchemas(String parentName, Map schemas) collectEnumSchemas(parentName, sName, schema); + String pName = parentName != null ? parentName + "_" + sName : sName; if (schema.getProperties() != null) { - String pName = parentName != null ? parentName + "_" + sName : sName; collectEnumSchemas(pName, schema.getProperties()); } if (schema.getAdditionalProperties() != null && schema.getAdditionalProperties() instanceof Schema) { - String pName = parentName != null ? parentName + "_" + sName : sName; collectEnumSchemas(pName, (Schema) schema.getAdditionalProperties()); } if (ModelUtils.isArraySchema(schema)) { if (ModelUtils.getSchemaItems(schema) != null) { - String pName = parentName != null ? parentName + "_" + sName : sName; collectEnumSchemas(pName, ModelUtils.getSchemaItems(schema)); } } @@ -677,7 +675,7 @@ private List> buildEnumValues(String valueString) { public String toEnumValueName(String name) { if (reservedWords.contains(name)) { return escapeReservedWord(name); - } else if (((CharSequence) name).chars().anyMatch(character -> specialCharReplacements.keySet().contains(String.valueOf((char) character)))) { + } else if (name.chars().anyMatch(character -> specialCharReplacements.containsKey(String.valueOf((char) character)))) { return escape(name, specialCharReplacements, Collections.singletonList("_"), null); } else { return name; @@ -723,8 +721,6 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List operations = objectMap.getOperation(); for (CodegenOperation operation : operations) { - // http method verb conversion, depending on client library (e.g. Hyper: PUT => Put, Reqwest: PUT => put) - //if (CO_HTTP.equals(getLibrary())) { for (CodegenParameter param : operation.bodyParams) { if (param.isModel && param.dataType.endsWith(".t")) { param.vendorExtensions.put(X_MODEL_MODULE, param.dataType.substring(0, param.dataType.lastIndexOf('.'))); 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 f29964db21b3..b2a5a9037a4d 100644 --- a/modules/openapi-generator/src/main/resources/ocaml/api-impl.mustache +++ b/modules/openapi-generator/src/main/resources/ocaml/api-impl.mustache @@ -30,7 +30,7 @@ let {{{operationId}}} {{^hasParams}}(){{/hasParams}}{{#allParams}}{{> to_param}} 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{{#isArray}}_list{{/isArray}} uri "{{{baseName}}}" {{> to_string}} {{{paramName}}} in + let uri = Request.{{> to_optional_prefix}}add_query_param{{#isArray}}_list{{/isArray}}{{#isExplode}}{{#isFormStyle}}{{#isMap}}_exploded_form_object{{/isMap}}{{/isFormStyle}}{{/isExplode}} uri "{{{baseName}}}" {{> to_string}} {{{paramName}}} in {{/queryParams}} {{#hasAuthMethods}} {{#authMethods}} @@ -42,7 +42,10 @@ let {{{operationId}}} {{^hasParams}}(){{/hasParams}}{{#allParams}}{{> to_param}} {{/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 + let body = Request. + {{#isByteArray}}write_string_body {{{paramName}}}{{/isByteArray}} + {{^isByteArray}}write_as_json_body {{> to_json}} {{{paramName}}}{{/isByteArray}} + in {{/bodyParams}} {{^hasBodyParam}} {{#hasFormParams}} diff --git a/modules/openapi-generator/src/main/resources/ocaml/json.mustache b/modules/openapi-generator/src/main/resources/ocaml/json.mustache index 4b0fac77545a..0af0c25e759a 100644 --- a/modules/openapi-generator/src/main/resources/ocaml/json.mustache +++ b/modules/openapi-generator/src/main/resources/ocaml/json.mustache @@ -50,6 +50,19 @@ 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_list_of of_f l = `List (Stdlib.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 +let of_map_of of_f l = `Assoc (Stdlib.List.map (fun (k, v) -> (k, of_f v)) l) + +let to_map_of of_f json = + match json with + | `Assoc l -> + Stdlib.List.fold_right + (fun (k, json) acc -> + match (of_f json, acc) with + | Stdlib.Result.Ok parsed_v, Stdlib.Result.Ok tl -> + Stdlib.Result.Ok ((k, parsed_v) :: tl) + | Stdlib.Result.Error e, _ -> Stdlib.Result.Error e + | _, Stdlib.Result.Error e -> Stdlib.Result.Error e) + l (Stdlib.Result.Ok []) + | _ -> Stdlib.Result.Error "Expected" diff --git a/modules/openapi-generator/src/main/resources/ocaml/model-any-of.mustache b/modules/openapi-generator/src/main/resources/ocaml/model-any-of.mustache new file mode 100644 index 000000000000..2999d6e3100a --- /dev/null +++ b/modules/openapi-generator/src/main/resources/ocaml/model-any-of.mustache @@ -0,0 +1,25 @@ +type t = +{{#composedSchemas.anyOf}} + | {{{nameInPascalCase}}} of {{{dataType}}} +{{/composedSchemas.anyOf}} +[@@deriving show, eq];; + +let to_yojson = function +{{#composedSchemas.anyOf}} + | {{{nameInPascalCase}}} v -> [%to_yojson: {{{ datatypeWithEnum }}}] v +{{/composedSchemas.anyOf}} + +(* Manual implementations because the derived one encodes into a tuple list where the first element is the constructor name. *) + +let of_yojson json = + [ +{{#composedSchemas.anyOf}} + [%of_yojson: {{{ datatypeWithEnum }}}] json + |> Stdlib.Result.to_option + |> Stdlib.Option.map (fun v -> {{{nameInPascalCase}}} v); +{{/composedSchemas.anyOf}} + ] + |> Stdlib.List.filter_map (Fun.id) + |> function + | t :: _ -> Ok t (* Return the first successful parsing. *) + | [] -> Error ("Failed to parse JSON " ^ Yojson.Safe.show json ^ " into a value of type {{{ classname }}}") diff --git a/modules/openapi-generator/src/main/resources/ocaml/model-one-of.mustache b/modules/openapi-generator/src/main/resources/ocaml/model-one-of.mustache new file mode 100644 index 000000000000..6ced87d25291 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/ocaml/model-one-of.mustache @@ -0,0 +1,29 @@ +type t = +{{#composedSchemas.oneOf}} + | {{{nameInPascalCase}}} of {{{dataType}}} +{{/composedSchemas.oneOf}} +[@@deriving show, eq];; + +let to_yojson = function +{{#composedSchemas.oneOf}} + | {{{nameInPascalCase}}} v -> [%to_yojson: {{{ datatypeWithEnum }}}] v +{{/composedSchemas.oneOf}} + +(* Manual implementations because the derived one encodes into a tuple list where the first element is the constructor name. *) + +let of_yojson json = + [ +{{#composedSchemas.oneOf}} + [%of_yojson: {{{ datatypeWithEnum }}}] json + |> Stdlib.Result.to_option + |> Stdlib.Option.map (fun v -> {{{nameInPascalCase}}} v); +{{/composedSchemas.oneOf}} + ] + |> Stdlib.List.filter_map (Fun.id) + |> function + | [t] -> Ok t + | [] -> Error ("Failed to parse JSON " ^ Yojson.Safe.show json ^ " into a value of type {{{ classname }}}") + | ts -> let parsed_ts = ts + |> Stdlib.List.map show + |> Stdlib.String.concat " | " + in Error ("Failed to parse JSON " ^ Yojson.Safe.show json ^ " into a value of type {{{ classname }}}: oneOf should only succeed on one parser, but the JSON was parsed into [" ^ parsed_ts ^ "]") diff --git a/modules/openapi-generator/src/main/resources/ocaml/model-record.mustache b/modules/openapi-generator/src/main/resources/ocaml/model-record.mustache new file mode 100644 index 000000000000..6977aed0a4ca --- /dev/null +++ b/modules/openapi-generator/src/main/resources/ocaml/model-record.mustache @@ -0,0 +1,44 @@ +type t = { +{{#vars}} + {{#description}} + (* {{{.}}} *) + {{/description}} + {{#isEnum}} + {{{name}}}: {{^isMap}}Enums.{{/isMap}}{{{datatypeWithEnum}}} + {{^isContainer}} + {{#required}} + {{#defaultValue}}[@default {{{.}}}]{{/defaultValue}} + {{#isNullable}} option [@default + {{#defaultValue}}Some({{{.}}}){{/defaultValue}} + {{^defaultValue}}None{{/defaultValue}} + ] + {{/isNullable}} + {{/required}} + {{^required}} option [@default + {{#defaultValue}}Some({{{.}}}){{/defaultValue}} + {{^defaultValue}}None{{/defaultValue}} + ] + {{/required}} + {{/isContainer}}; [@key "{{{baseName}}}"] + {{/isEnum}} + {{^isEnum}} + {{{name}}}: {{{datatypeWithEnum}}} + {{^isContainer}} + {{#required}}{{#isNullable}} option{{/isNullable}}{{/required}} + {{^required}} option [@default None]{{/required}} + {{/isContainer}} + {{#isArray}}{{^required}} [@default []]{{/required}}{{/isArray}} + {{#isMap}}{{^required}} [@default []] [@to_yojson JsonSupport.of_map_of [%to_yojson: {{{items.datatypeWithEnum}}}]] [@of_yojson JsonSupport.to_map_of [%of_yojson: {{{items.datatypeWithEnum}}}]] {{/required}}{{/isMap}} + ; [@key "{{{baseName}}}"] + {{/isEnum}} +{{/vars}} +} [@@deriving yojson { strict = false }, show, eq ];; + +{{#description}} +(** {{{.}}} *) +{{/description}} +let create {{#requiredVars}}({{{name}}} : {{#isEnum}}Enums.{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#isNullable}} option{{/isNullable}}){{^-last}} {{/-last}}{{/requiredVars}}{{^hasRequired}}(){{/hasRequired}} : t = { + {{#vars}} + {{{name}}} = {{#required}}{{{name}}}{{/required}}{{^required}}{{#isContainer}}[]{{/isContainer}}{{^isContainer}}None{{/isContainer}}{{/required}}; + {{/vars}} +} diff --git a/modules/openapi-generator/src/main/resources/ocaml/model.mustache b/modules/openapi-generator/src/main/resources/ocaml/model.mustache index cbd93f1524b6..eae441c741d3 100644 --- a/modules/openapi-generator/src/main/resources/ocaml/model.mustache +++ b/modules/openapi-generator/src/main/resources/ocaml/model.mustache @@ -10,49 +10,17 @@ {{/description}} {{^isEnum}} -type t = { -{{#vars}} - {{#description}} - (* {{{.}}} *) - {{/description}} - {{#isEnum}} - {{{name}}}: {{^isMap}}Enums.{{/isMap}}{{{datatypeWithEnum}}} - {{^isContainer}} - {{#required}} - {{#defaultValue}}[@default {{{.}}}]{{/defaultValue}} - {{#isNullable}} option [@default - {{#defaultValue}}Some({{{.}}}){{/defaultValue}} - {{^defaultValue}}None{{/defaultValue}} - ] - {{/isNullable}} - {{/required}} - {{^required}} option [@default - {{#defaultValue}}Some({{{.}}}){{/defaultValue}} - {{^defaultValue}}None{{/defaultValue}} - ] - {{/required}} - {{/isContainer}}; [@key "{{{baseName}}}"] - {{/isEnum}} - {{^isEnum}} - {{{name}}}: {{{datatypeWithEnum}}} - {{^isContainer}} - {{#required}}{{#isNullable}} option{{/isNullable}}{{/required}} - {{^required}} option [@default None]{{/required}} - {{/isContainer}} - {{#isArray}}{{^required}} [@default []]{{/required}}{{/isArray}} - ; [@key "{{{baseName}}}"] - {{/isEnum}} -{{/vars}} -} [@@deriving yojson { strict = false }, show, eq ];; + {{#vendorExtensions.x-ocaml-isOneOf}} + {{>model-one-of}} + {{/vendorExtensions.x-ocaml-isOneOf}} -{{#description}} -(** {{{.}}} *) -{{/description}} -let create {{#requiredVars}}({{{name}}} : {{#isEnum}}Enums.{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#isNullable}} option{{/isNullable}}){{^-last}} {{/-last}}{{/requiredVars}}{{^hasRequired}}(){{/hasRequired}} : t = { - {{#vars}} - {{{name}}} = {{#required}}{{{name}}}{{/required}}{{^required}}{{#isContainer}}[]{{/isContainer}}{{^isContainer}}None{{/isContainer}}{{/required}}; - {{/vars}} -} + {{#vendorExtensions.x-ocaml-isAnyOf}} + {{>model-any-of}} + {{/vendorExtensions.x-ocaml-isAnyOf}} + + {{^vendorExtensions.x-ocaml-isOneOf}}{{^vendorExtensions.x-ocaml-isAnyOf}} + {{>model-record}} + {{/vendorExtensions.x-ocaml-isAnyOf}}{{/vendorExtensions.x-ocaml-isOneOf}} {{/isEnum}} {{/model}} diff --git a/modules/openapi-generator/src/main/resources/ocaml/support.mustache b/modules/openapi-generator/src/main/resources/ocaml/support.mustache index 14d5ba0d5793..ee134b87198b 100644 --- a/modules/openapi-generator/src/main/resources/ocaml/support.mustache +++ b/modules/openapi-generator/src/main/resources/ocaml/support.mustache @@ -35,7 +35,7 @@ let write_json_body payload = 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 + match Cohttp.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))) @@ -52,13 +52,13 @@ 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) + Lwt.(read_json_body_as_list resp body >|= Stdlib.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))) + Lwt.(read_json_body_as_map resp body >|= Stdlib.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 @@ -80,6 +80,19 @@ let add_query_param_list 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 +(** Corresponds to: + - [style = form] + - [explode = true] + - type [object] + + See https://swagger.io/docs/specification/v3_0/serialization/#query-parameters +*) +let add_query_param_exploded_form_object uri _param_name to_string param_value = +Stdlib.List.fold_left + (fun uri (param_name, param_value) -> add_query_param uri param_name to_string param_value) + uri + param_value + let init_form_encoded_body () = "" let add_form_encoded_body_param params param_name to_string param_value = diff --git a/modules/openapi-generator/src/main/resources/ocaml/to_json.mustache b/modules/openapi-generator/src/main/resources/ocaml/to_json.mustache index 99e45aafb78e..ad7681d20781 100644 --- a/modules/openapi-generator/src/main/resources/ocaml/to_json.mustache +++ b/modules/openapi-generator/src/main/resources/ocaml/to_json.mustache @@ -1 +1,39 @@ -{{#isArray}}{{#items}}(JsonSupport.of_list_of {{> to_json}}){{/items}}{{/isArray}}{{#isMap}}{{#items}}(JsonSupport.of_map_of {{> to_json}}){{/items}}{{/isMap}}{{#isString}}JsonSupport.of_string{{/isString}}{{#isLong}}JsonSupport.of_int64{{/isLong}}{{#isInteger}}JsonSupport.of_int32{{/isInteger}}{{#isFloat}}JsonSupport.of_float{{/isFloat}}{{#isNumber}}JsonSupport.of_float{{/isNumber}}{{#isDouble}}JsonSupport.of_float{{/isDouble}}{{#isBoolean}}JsonSupport.of_bool{{/isBoolean}}{{^isEnum}}{{#isModel}}{{#vendorExtensions.x-model-module}}{{{vendorExtensions.x-model-module}}}.to_yojson{{/vendorExtensions.x-model-module}}{{^vendorExtensions.x-model-module}}{{{baseType}}}.to_yojson{{/vendorExtensions.x-model-module}}{{/isModel}}{{/isEnum}}{{^isModel}}{{^isContainer}}{{#isEnum}}Enums.{{{datatypeWithEnum}}}_to_yojson{{/isEnum}}{{/isContainer}}{{/isModel}} \ No newline at end of file +{{#isArray}} + {{#items}} + (JsonSupport.of_list_of {{> to_json}}) + {{/items}} +{{/isArray}} +{{#isMap}} + {{#items}} + (JsonSupport.of_map_of {{> to_json}}) + {{/items}} +{{/isMap}} +{{^isContainer}} + {{#isString}}JsonSupport.of_string{{/isString}} + {{#isLong}}JsonSupport.of_int64{{/isLong}} + {{#isInteger}}JsonSupport.of_int32{{/isInteger}} + {{#isFloat}}JsonSupport.of_float{{/isFloat}} + {{#isNumber}}JsonSupport.of_float{{/isNumber}} + {{#isDouble}}JsonSupport.of_float{{/isDouble}} + {{#isBoolean}}JsonSupport.of_bool{{/isBoolean}} + {{^isEnum}} + {{#isModel}} + {{#vendorExtensions.x-model-module}} + {{{vendorExtensions.x-model-module}}}.to_yojson + {{/vendorExtensions.x-model-module}} + {{^vendorExtensions.x-model-module}} + {{{baseType}}}.to_yojson + {{/vendorExtensions.x-model-module}} + {{/isModel}} + {{/isEnum}} + {{^isModel}} + {{^isContainer}} + {{#isEnum}} + Enums.{{{datatypeWithEnum}}}_to_yojson + {{/isEnum}} + {{/isContainer}} + {{/isModel}} + {{#isBinary}}JsonSupport.of_string{{/isBinary}} + {{#isAnyType}}(fun x -> x){{/isAnyType}} + {{#isFreeFormObject}}(fun x -> x){{/isFreeFormObject}} +{{/isContainer}} 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 3b41569d43d9..9dc1968f0c4e 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,26 @@ -{{#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-model-module}}}.show{{/isModel}}{{/isEnum}}{{^isModel}}{{^isContainer}}{{#isEnum}}Enums.show_{{{datatypeWithEnum}}}{{/isEnum}}{{/isContainer}}{{/isModel}} \ No newline at end of file +{{#isArray}} + {{#items}}(Stdlib.List.map {{> to_string}}){{/items}} +{{/isArray}} +{{#isMap}}{{! For maps, only transform the value, the call site will take care of properly transforming the key-value pairs since it depends on the context. }} + {{#items}}{{> to_string}}{{/items}} +{{/isMap}} +{{^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-model-module}}}.show{{/isModel}} +{{/isEnum}} +{{^isModel}} + {{^isContainer}} + {{#isEnum}}Enums.show_{{{datatypeWithEnum}}}{{/isEnum}} + {{#isEnumRef}}(failwith "Unsupported: enum reference"){{/isEnumRef}} + {{/isContainer}} +{{/isModel}} diff --git a/samples/client/petstore/ocaml-fake-petstore/.openapi-generator-ignore b/samples/client/petstore/ocaml-fake-petstore/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/.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/client/petstore/ocaml-fake-petstore/.openapi-generator/FILES b/samples/client/petstore/ocaml-fake-petstore/.openapi-generator/FILES new file mode 100644 index 000000000000..d4a1e97f7ede --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/.openapi-generator/FILES @@ -0,0 +1,65 @@ +README.md +dune +dune-project +petstore_client.opam +src/apis/another_fake_api.ml +src/apis/another_fake_api.mli +src/apis/default_api.ml +src/apis/default_api.mli +src/apis/fake_api.ml +src/apis/fake_api.mli +src/apis/fake_classname_tags123_api.ml +src/apis/fake_classname_tags123_api.mli +src/apis/pet_api.ml +src/apis/pet_api.mli +src/apis/store_api.ml +src/apis/store_api.mli +src/apis/user_api.ml +src/apis/user_api.mli +src/models/additional_properties_class.ml +src/models/all_of_with_single_ref.ml +src/models/animal.ml +src/models/api_response.ml +src/models/array_of_array_of_number_only.ml +src/models/array_of_number_only.ml +src/models/array_test.ml +src/models/capitalization.ml +src/models/cat.ml +src/models/category.ml +src/models/child_with_nullable.ml +src/models/class_model.ml +src/models/client.ml +src/models/deprecated_object.ml +src/models/dog.ml +src/models/enum_arrays.ml +src/models/enum_test.ml +src/models/fake_big_decimal_map_200_response.ml +src/models/file.ml +src/models/file_schema_test_class.ml +src/models/foo.ml +src/models/format_test.ml +src/models/has_only_read_only.ml +src/models/health_check_result.ml +src/models/list.ml +src/models/map_test.ml +src/models/mixed_properties_and_additional_properties_class.ml +src/models/model_200_response.ml +src/models/model__foo_get_default_response.ml +src/models/model__special_model_name_.ml +src/models/name.ml +src/models/nullable_class.ml +src/models/number_only.ml +src/models/object_with_deprecated_fields.ml +src/models/order.ml +src/models/outer_composite.ml +src/models/outer_object_with_enum_property.ml +src/models/parent_with_nullable.ml +src/models/pet.ml +src/models/read_only_first.ml +src/models/return.ml +src/models/tag.ml +src/models/test_inline_freeform_additional_properties_request.ml +src/models/user.ml +src/support/enums.ml +src/support/jsonSupport.ml +src/support/request.ml diff --git a/samples/client/petstore/ocaml-fake-petstore/.openapi-generator/VERSION b/samples/client/petstore/ocaml-fake-petstore/.openapi-generator/VERSION new file mode 100644 index 000000000000..5e5282953086 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.16.0-SNAPSHOT diff --git a/samples/client/petstore/ocaml-fake-petstore/README.md b/samples/client/petstore/ocaml-fake-petstore/README.md new file mode 100644 index 000000000000..d0ad85e9f3cf --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/README.md @@ -0,0 +1,33 @@ +# +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 +- Generator version: 7.16.0-SNAPSHOT +- Build package: org.openapitools.codegen.languages.OCamlClientCodegen + +## Requirements. + +OCaml 5.x + +## Installation + +Please run the following commands to build the package `petstore_client`: + +```sh +opam install . --deps-only --with-test +eval $(opam env) +dune build +``` + +## Getting Started + +The generated directory structure is: +- `src/apis`: contains several modules, each with several functions. Each function is an API endpoint. +- `src/models`: contains several modules. Each module contains: + - a type `t` representing an input and/or output schema of the OpenAPI spec + - a smart constructor `create` for this type +- `src/support`: various modules used by the generated APIs and Models + diff --git a/samples/client/petstore/ocaml-fake-petstore/dune b/samples/client/petstore/ocaml-fake-petstore/dune new file mode 100644 index 000000000000..ed1c4d90e3df --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/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/client/petstore/ocaml-fake-petstore/dune-project b/samples/client/petstore/ocaml-fake-petstore/dune-project new file mode 100644 index 000000000000..79d86e3c901a --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/dune-project @@ -0,0 +1,2 @@ +(lang dune 1.10) +(name petstore_client) \ No newline at end of file diff --git a/samples/client/petstore/ocaml-fake-petstore/petstore_client.opam b/samples/client/petstore/ocaml-fake-petstore/petstore_client.opam new file mode 100644 index 000000000000..7ca31fc5af4f --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/petstore_client.opam @@ -0,0 +1,24 @@ +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" + "dune" + "ppx_deriving_yojson" + "conf-libev" + "lwt" + "cohttp-lwt-unix" {< "6.0.0"} + "cohttp-async" {< "6.0.0"} +] +build: ["dune" "build" "-p" name] diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.ml new file mode 100644 index 000000000000..8e40a663d9be --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.ml @@ -0,0 +1,29 @@ +(* + * 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.Infix 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/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.mli b/samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.mli new file mode 100644 index 000000000000..3e9e0c80484b --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/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/client/petstore/ocaml-fake-petstore/src/apis/default_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/default_api.ml new file mode 100644 index 000000000000..0184891735dd --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/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.Infix 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 Model__foo_get_default_response.of_yojson) resp body + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/default_api.mli b/samples/client/petstore/ocaml-fake-petstore/src/apis/default_api.mli new file mode 100644 index 000000000000..d58454de73ac --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/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 -> Model__foo_get_default_response.t Lwt.t diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml new file mode 100644 index 000000000000..7dd18fe3ceb2 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml @@ -0,0 +1,1002 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +let fake_big_decimal_map () = + let open Lwt.Infix in + let uri = Request.build_uri "/fake/BigDecimalMap" 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 Fake_big_decimal_map_200_response.of_yojson) resp body + +let fake_health_get () = + let open Lwt.Infix 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_http_signature_test ~pet_t ?query_1 ?header_1 () = + let open Lwt.Infix in + let uri = Request.build_uri "/fake/http-signature-test" in + let headers = Request.default_headers in + let headers = Request.maybe_add_header headers "header_1" + + + + + + + + + (fun x -> x) + + + + + header_1 in + let uri = Request.maybe_add_query_param uri "query_1" + + + + + + + + + (fun x -> x) + + + + + query_1 in + let body = Request. + + write_as_json_body + + + + + + + Pet.to_yojson + + + + pet_t + in + Cohttp_lwt_unix.Client.call `GET uri ~headers ~body >>= fun (resp, body) -> + Request.handle_unit_response resp + +let fake_outer_boolean_serialize ~body () = + let open Lwt.Infix 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.Infix 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.Infix 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.Infix 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 fake_property_enum_integer_serialize ~outer_object_with_enum_property_t = + let open Lwt.Infix in + let uri = Request.build_uri "/fake/property/enum-int" in + let headers = Request.default_headers in + let body = Request. + + write_as_json_body + + + + + + + Outer_object_with_enum_property.to_yojson + + + + outer_object_with_enum_property_t + in + Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> + Request.read_json_body_as (JsonSupport.unwrap Outer_object_with_enum_property.of_yojson) resp body + +let test_additional_properties_reference ~request_body = + let open Lwt.Infix in + let uri = Request.build_uri "/fake/additionalProperties-reference" in + let headers = Request.default_headers in + let body = Request. + + write_as_json_body (JsonSupport.of_map_of + + + + + + + + (fun x -> x) + +) + request_body + in + Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> + Request.handle_unit_response resp + +let test_body_with_binary ~body = + let open Lwt.Infix in + let uri = Request.build_uri "/fake/body-with-binary" in + let headers = Request.default_headers in + let body = Request. + + write_as_json_body + + + + + + + JsonSupport.of_string + + + body + in + Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) -> + Request.handle_unit_response resp + +let test_body_with_file_schema ~file_schema_test_class_t = + let open Lwt.Infix 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.Infix 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.Infix 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.Infix 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_query_model_array = []) ?(enum_form_string_array = [`Dollar]) ?(enum_form_string = `Minusefg) () = + let open Lwt.Infix 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" (Stdlib.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" (Stdlib.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 uri = Request.add_query_param_list uri "enum_query_model_array" (Stdlib.List.map + + + + + + + + + + + + + (failwith "Unsupported: enum reference") +) + + + + + + + + + + + + + enum_query_model_array in + let body = Request.init_form_encoded_body () in + let body = Request.add_form_encoded_body_param_list body "enum_form_string_array" (Stdlib.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.Infix 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.Infix 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_inline_freeform_additional_properties ~test_inline_freeform_additional_properties_request_t = + let open Lwt.Infix in + let uri = Request.build_uri "/fake/inline-freeform-additionalProperties" in + let headers = Request.default_headers in + let body = Request. + + write_as_json_body + + + + + + + Test_inline_freeform_additional_properties_request.to_yojson + + + + test_inline_freeform_additional_properties_request_t + 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.Infix 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 + +let test_nullable ~child_with_nullable_t = + let open Lwt.Infix in + let uri = Request.build_uri "/fake/nullable" in + let headers = Request.default_headers in + let body = Request. + + write_as_json_body + + + + + + + Child_with_nullable.to_yojson + + + + child_with_nullable_t + in + Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> + Request.handle_unit_response resp + +let test_query_parameter_collection_format ~pipe ~ioutil ~http ~url ~context ~allow_empty ?(language = []) () = + let open Lwt.Infix in + let uri = Request.build_uri "/fake/test-query-parameters" in + let headers = Request.default_headers in + let uri = Request.add_query_param_list uri "pipe" (Stdlib.List.map + + + + + + + + + (fun x -> x) + + + + +) + + + + + + + + + + + + + pipe in + let uri = Request.add_query_param_list uri "ioutil" (Stdlib.List.map + + + + + + + + + (fun x -> x) + + + + +) + + + + + + + + + + + + + ioutil in + let uri = Request.add_query_param_list uri "http" (Stdlib.List.map + + + + + + + + + (fun x -> x) + + + + +) + + + + + + + + + + + + + http in + let uri = Request.add_query_param_list uri "url" (Stdlib.List.map + + + + + + + + + (fun x -> x) + + + + +) + + + + + + + + + + + + + url in + let uri = Request.add_query_param_list uri "context" (Stdlib.List.map + + + + + + + + + (fun x -> x) + + + + +) + + + + + + + + + + + + + context in + let uri = Request.add_query_param_exploded_form_object uri "language" + + + + + + + + + + (fun x -> x) + + + + + + + + + + + + + + + + + + language in + let uri = Request.add_query_param uri "allowEmpty" + + + + + + + + + (fun x -> x) + + + + + allow_empty in + Cohttp_lwt_unix.Client.call `PUT uri ~headers >>= fun (resp, body) -> + Request.handle_unit_response resp + +let test_string_map_reference ~request_body = + let open Lwt.Infix in + let uri = Request.build_uri "/fake/stringMap-reference" 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 + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.mli b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.mli new file mode 100644 index 000000000000..259a66dd29e0 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.mli @@ -0,0 +1,29 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +val fake_big_decimal_map : unit -> Fake_big_decimal_map_200_response.t Lwt.t +val fake_health_get : unit -> Health_check_result.t Lwt.t +val fake_http_signature_test : pet_t:Pet.t -> ?query_1:string -> ?header_1:string -> unit -> unit 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 fake_property_enum_integer_serialize : outer_object_with_enum_property_t:Outer_object_with_enum_property.t -> Outer_object_with_enum_property.t Lwt.t +val test_additional_properties_reference : request_body:(string * Yojson.Safe.t) list -> unit Lwt.t +val test_body_with_binary : body:string -> unit 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_query_model_array:Enums.enumclass list -> ?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_inline_freeform_additional_properties : test_inline_freeform_additional_properties_request_t:Test_inline_freeform_additional_properties_request.t -> unit Lwt.t +val test_json_form_data : param:string -> param2:string -> unit Lwt.t +val test_nullable : child_with_nullable_t:Child_with_nullable.t -> unit Lwt.t +val test_query_parameter_collection_format : pipe:string list -> ioutil:string list -> http:string list -> url:string list -> context:string list -> allow_empty:string -> ?language:(string * string) list -> unit -> unit Lwt.t +val test_string_map_reference : request_body:(string * string) list -> unit Lwt.t diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.ml new file mode 100644 index 000000000000..5eb1391914f8 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.ml @@ -0,0 +1,30 @@ +(* + * 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.Infix 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/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.mli b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.mli new file mode 100644 index 000000000000..0f9a292c5073 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/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/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml new file mode 100644 index 000000000000..95637700510d --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml @@ -0,0 +1,319 @@ +(* + * 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.Infix 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.Infix 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.Infix in + let uri = Request.build_uri "/pet/findByStatus" in + let headers = Request.default_headers in + let uri = Request.add_query_param_list uri "status" (Stdlib.List.map Enums.show_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.Infix in + let uri = Request.build_uri "/pet/findByTags" in + let headers = Request.default_headers in + let uri = Request.add_query_param_list uri "tags" (Stdlib.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.Infix 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.Infix 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.Infix 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.Infix 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.Infix 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/client/petstore/ocaml-fake-petstore/src/apis/pet_api.mli b/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.mli new file mode 100644 index 000000000000..f0aa4208b358 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/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.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/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml new file mode 100644 index 000000000000..96c52f9b9ed7 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml @@ -0,0 +1,81 @@ +(* + * 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.Infix 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.Infix 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.Infix 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.Infix 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/client/petstore/ocaml-fake-petstore/src/apis/store_api.mli b/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.mli new file mode 100644 index 000000000000..63b09db9ca52 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/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/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml new file mode 100644 index 000000000000..c5f913e57a30 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml @@ -0,0 +1,200 @@ +(* + * 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.Infix 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.Infix 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.Infix 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.Infix 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.Infix 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.Infix 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.Infix 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.Infix 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/client/petstore/ocaml-fake-petstore/src/apis/user_api.mli b/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.mli new file mode 100644 index 000000000000..9a7e8e59c3ac --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/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/client/petstore/ocaml-fake-petstore/src/models/additional_properties_class.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/additional_properties_class.ml new file mode 100644 index 000000000000..1070136f5dec --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/additional_properties_class.ml @@ -0,0 +1,27 @@ +(* + * 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 + + [@default []] [@to_yojson JsonSupport.of_map_of [%to_yojson: string]] [@of_yojson JsonSupport.to_map_of [%of_yojson: string]] + ; [@key "map_property"] + map_of_map_property: (string * (string * string) list) list + + [@default []] [@to_yojson JsonSupport.of_map_of [%to_yojson: (string * string) list]] [@of_yojson JsonSupport.to_map_of [%of_yojson: (string * string) list]] + ; [@key "map_of_map_property"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create () : t = { + map_property = []; + map_of_map_property = []; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/all_of_with_single_ref.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/all_of_with_single_ref.ml new file mode 100644 index 000000000000..8824bf45851d --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/all_of_with_single_ref.ml @@ -0,0 +1,31 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + + + + + type t = { + username: string + + option [@default None] + + + ; [@key "username"] + single_ref_type: Enums.singlereftype + + option [@default None] + + + ; [@key "SingleRefType"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create () : t = { + username = None; + single_ref_type = None; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/animal.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/animal.ml new file mode 100644 index 000000000000..bb9694548e1e --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/animal.ml @@ -0,0 +1,31 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + + + + + type t = { + class_name: string + + + + + ; [@key "className"] + color: string + + option [@default None] + + + ; [@key "color"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create (class_name : string) : t = { + class_name = class_name; + color = None; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/api_response.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/api_response.ml new file mode 100644 index 000000000000..38c83657c392 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/api_response.ml @@ -0,0 +1,38 @@ +(* + * 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] + + + ; [@key "code"] + _type: string + + option [@default None] + + + ; [@key "type"] + message: string + + option [@default None] + + + ; [@key "message"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create () : t = { + code = None; + _type = None; + message = None; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/array_of_array_of_number_only.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/array_of_array_of_number_only.ml new file mode 100644 index 000000000000..17d2b550a3dc --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/array_of_array_of_number_only.ml @@ -0,0 +1,22 @@ +(* + * 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 + [@default []] + + ; [@key "ArrayArrayNumber"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create () : t = { + array_array_number = []; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/array_of_number_only.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/array_of_number_only.ml new file mode 100644 index 000000000000..e4ea0cc597d1 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/array_of_number_only.ml @@ -0,0 +1,22 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + + + + + type t = { + array_number: float list + [@default []] + + ; [@key "ArrayNumber"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create () : t = { + array_number = []; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/array_test.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/array_test.ml new file mode 100644 index 000000000000..850e8d6d7197 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/array_test.ml @@ -0,0 +1,32 @@ +(* + * 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 + [@default []] + + ; [@key "array_of_string"] + array_array_of_integer: int64 list list + [@default []] + + ; [@key "array_array_of_integer"] + array_array_of_model: Read_only_first.t list list + [@default []] + + ; [@key "array_array_of_model"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create () : t = { + array_of_string = []; + array_array_of_integer = []; + array_array_of_model = []; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/capitalization.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/capitalization.ml new file mode 100644 index 000000000000..2725a870b917 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/capitalization.ml @@ -0,0 +1,60 @@ +(* + * 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] + + + ; [@key "smallCamel"] + capital_camel: string + + option [@default None] + + + ; [@key "CapitalCamel"] + small_snake: string + + option [@default None] + + + ; [@key "small_Snake"] + capital_snake: string + + option [@default None] + + + ; [@key "Capital_Snake"] + sca_eth_flow_points: string + + option [@default None] + + + ; [@key "SCA_ETH_Flow_Points"] + (* Name of the pet *) + att_name: string + + option [@default None] + + + ; [@key "ATT_NAME"] + } [@@deriving yojson { strict = false }, show, eq ];; + + 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/client/petstore/ocaml-fake-petstore/src/models/cat.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/cat.ml new file mode 100644 index 000000000000..d9dcd55ac0af --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/cat.ml @@ -0,0 +1,38 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + + + + + type t = { + class_name: string + + + + + ; [@key "className"] + color: string + + option [@default None] + + + ; [@key "color"] + declawed: bool + + option [@default None] + + + ; [@key "declawed"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create (class_name : string) : t = { + class_name = class_name; + color = None; + declawed = None; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/category.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/category.ml new file mode 100644 index 000000000000..95e0b50ee994 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/category.ml @@ -0,0 +1,31 @@ +(* + * 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] + + + ; [@key "id"] + name: string + + + + + ; [@key "name"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create (name : string) : t = { + id = None; + name = name; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/child_with_nullable.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/child_with_nullable.ml new file mode 100644 index 000000000000..61eba92d86ce --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/child_with_nullable.ml @@ -0,0 +1,38 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + + + + + type t = { + _type: Enums.parentwithnullable_type + option [@default + Some(`ChildWithNullable) + + ] + ; [@key "type"] + nullable_property: string + + option [@default None] + + + ; [@key "nullableProperty"] + other_property: string + + option [@default None] + + + ; [@key "otherProperty"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create () : t = { + _type = None; + nullable_property = None; + other_property = None; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/class_model.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/class_model.ml new file mode 100644 index 000000000000..f63be054b150 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/class_model.ml @@ -0,0 +1,26 @@ +(* + * 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] + + + ; [@key "_class"] + } [@@deriving yojson { strict = false }, show, eq ];; + + (** Model for testing model with \''_class\'' property *) + let create () : t = { + _class = None; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/client.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/client.ml new file mode 100644 index 000000000000..d3b578e2509f --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/client.ml @@ -0,0 +1,24 @@ +(* + * 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] + + + ; [@key "client"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create () : t = { + client = None; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/deprecated_object.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/deprecated_object.ml new file mode 100644 index 000000000000..ff9a12f2eb4d --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/deprecated_object.ml @@ -0,0 +1,24 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + + + + + type t = { + name: string + + option [@default None] + + + ; [@key "name"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create () : t = { + name = None; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/dog.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/dog.ml new file mode 100644 index 000000000000..004e9bb56406 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/dog.ml @@ -0,0 +1,38 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + + + + + type t = { + class_name: string + + + + + ; [@key "className"] + color: string + + option [@default None] + + + ; [@key "color"] + breed: string + + option [@default None] + + + ; [@key "breed"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create (class_name : string) : t = { + class_name = class_name; + color = None; + breed = None; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/enum_arrays.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/enum_arrays.ml new file mode 100644 index 000000000000..612cdf25beba --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/enum_arrays.ml @@ -0,0 +1,27 @@ +(* + * 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 + ] + ; [@key "just_symbol"] + array_enum: Enums.array_enum list +; [@key "array_enum"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create () : t = { + just_symbol = None; + array_enum = []; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/enum_test.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/enum_test.ml new file mode 100644 index 000000000000..e9df9f2fec4e --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/enum_test.ml @@ -0,0 +1,70 @@ +(* + * 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 + ] + ; [@key "enum_string"] + enum_string_required: Enums.enum_string + + ; [@key "enum_string_required"] + enum_integer: Enums.enum_integer + option [@default + + None + ] + ; [@key "enum_integer"] + enum_number: Enums.enum_number + option [@default + + None + ] + ; [@key "enum_number"] + outer_enum: Enums.order_status + + option [@default None] + + + ; [@key "outerEnum"] + outer_enum_integer: Enums.outerenuminteger + + option [@default None] + + + ; [@key "outerEnumInteger"] + outer_enum_default_value: Enums.order_status + + option [@default None] + + + ; [@key "outerEnumDefaultValue"] + outer_enum_integer_default_value: Enums.outerenuminteger + + option [@default None] + + + ; [@key "outerEnumIntegerDefaultValue"] + } [@@deriving yojson { strict = false }, show, eq ];; + + 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/client/petstore/ocaml-fake-petstore/src/models/fake_big_decimal_map_200_response.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/fake_big_decimal_map_200_response.ml new file mode 100644 index 000000000000..6abba727a131 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/fake_big_decimal_map_200_response.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 = { + some_id: float + + option [@default None] + + + ; [@key "someId"] + some_map: (string * float) list + + [@default []] [@to_yojson JsonSupport.of_map_of [%to_yojson: float]] [@of_yojson JsonSupport.to_map_of [%of_yojson: float]] + ; [@key "someMap"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create () : t = { + some_id = None; + some_map = []; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/file.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/file.ml new file mode 100644 index 000000000000..e02dec2b6bde --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/file.ml @@ -0,0 +1,27 @@ +(* + * 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] + + + ; [@key "sourceURI"] + } [@@deriving yojson { strict = false }, show, eq ];; + + (** Must be named `File` for test. *) + let create () : t = { + source_uri = None; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/file_schema_test_class.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/file_schema_test_class.ml new file mode 100644 index 000000000000..e9bb0b52c6b6 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/file_schema_test_class.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 = { + file: File.t + + option [@default None] + + + ; [@key "file"] + files: File.t list + [@default []] + + ; [@key "files"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create () : t = { + file = None; + files = []; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/foo.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/foo.ml new file mode 100644 index 000000000000..a3f48385e0d7 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/foo.ml @@ -0,0 +1,24 @@ +(* + * 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] + + + ; [@key "bar"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create () : t = { + bar = None; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/format_test.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/format_test.ml new file mode 100644 index 000000000000..03631a54e643 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/format_test.ml @@ -0,0 +1,131 @@ +(* + * 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] + + + ; [@key "integer"] + int32: int32 + + option [@default None] + + + ; [@key "int32"] + int64: int64 + + option [@default None] + + + ; [@key "int64"] + number: float + + + + + ; [@key "number"] + float: float + + option [@default None] + + + ; [@key "float"] + double: float + + option [@default None] + + + ; [@key "double"] + decimal: string + + option [@default None] + + + ; [@key "decimal"] + string: string + + option [@default None] + + + ; [@key "string"] + byte: string + + + + + ; [@key "byte"] + binary: string + + option [@default None] + + + ; [@key "binary"] + date: string + + + + + ; [@key "date"] + date_time: string + + option [@default None] + + + ; [@key "dateTime"] + uuid: string + + option [@default None] + + + ; [@key "uuid"] + password: string + + + + + ; [@key "password"] + (* A string that is a 10 digit number. Can have leading zeros. *) + pattern_with_digits: string + + option [@default None] + + + ; [@key "pattern_with_digits"] + (* 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] + + + ; [@key "pattern_with_digits_and_delimiter"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create (number : float) (byte : string) (date : string) (password : string) : t = { + integer = None; + int32 = None; + int64 = None; + number = number; + float = None; + double = None; + decimal = 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/client/petstore/ocaml-fake-petstore/src/models/has_only_read_only.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/has_only_read_only.ml new file mode 100644 index 000000000000..cebf14ba37f9 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/has_only_read_only.ml @@ -0,0 +1,31 @@ +(* + * 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] + + + ; [@key "bar"] + foo: string + + option [@default None] + + + ; [@key "foo"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create () : t = { + bar = None; + foo = None; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/health_check_result.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/health_check_result.ml new file mode 100644 index 000000000000..b58d7cd6cfeb --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/health_check_result.ml @@ -0,0 +1,26 @@ +(* + * 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] + + + ; [@key "NullableMessage"] + } [@@deriving yojson { strict = false }, show, eq ];; + + (** 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/client/petstore/ocaml-fake-petstore/src/models/list.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/list.ml new file mode 100644 index 000000000000..13e71de7e641 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/list.ml @@ -0,0 +1,24 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + + + + + type t = { + var_123_list: string + + option [@default None] + + + ; [@key "123-list"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create () : t = { + var_123_list = None; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/map_test.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/map_test.ml new file mode 100644 index 000000000000..22a05cd8e6d1 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/map_test.ml @@ -0,0 +1,35 @@ +(* + * 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 + + [@default []] [@to_yojson JsonSupport.of_map_of [%to_yojson: (string * string) list]] [@of_yojson JsonSupport.to_map_of [%of_yojson: (string * string) list]] + ; [@key "map_map_of_string"] + map_of_enum_string: (string * Enums.map_of_enum_string) list +; [@key "map_of_enum_string"] + direct_map: (string * bool) list + + [@default []] [@to_yojson JsonSupport.of_map_of [%to_yojson: bool]] [@of_yojson JsonSupport.to_map_of [%of_yojson: bool]] + ; [@key "direct_map"] + indirect_map: (string * bool) list + + [@default []] [@to_yojson JsonSupport.of_map_of [%to_yojson: bool]] [@of_yojson JsonSupport.to_map_of [%of_yojson: bool]] + ; [@key "indirect_map"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create () : t = { + map_map_of_string = []; + map_of_enum_string = []; + direct_map = []; + indirect_map = []; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/mixed_properties_and_additional_properties_class.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/mixed_properties_and_additional_properties_class.ml new file mode 100644 index 000000000000..b3c6cedecc23 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/mixed_properties_and_additional_properties_class.ml @@ -0,0 +1,36 @@ +(* + * 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] + + + ; [@key "uuid"] + date_time: string + + option [@default None] + + + ; [@key "dateTime"] + map: (string * Animal.t) list + + [@default []] [@to_yojson JsonSupport.of_map_of [%to_yojson: Animal.t]] [@of_yojson JsonSupport.to_map_of [%of_yojson: Animal.t]] + ; [@key "map"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create () : t = { + uuid = None; + date_time = None; + map = []; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/model_200_response.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/model_200_response.ml new file mode 100644 index 000000000000..06031bb76b08 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/model_200_response.ml @@ -0,0 +1,33 @@ +(* + * 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] + + + ; [@key "name"] + _class: string + + option [@default None] + + + ; [@key "class"] + } [@@deriving yojson { strict = false }, show, eq ];; + + (** Model for testing model name starting with number *) + let create () : t = { + name = None; + _class = None; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/model__foo_get_default_response.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/model__foo_get_default_response.ml new file mode 100644 index 000000000000..3231ca32596c --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/model__foo_get_default_response.ml @@ -0,0 +1,24 @@ +(* + * 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] + + + ; [@key "string"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create () : t = { + string = None; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/model__special_model_name_.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/model__special_model_name_.ml new file mode 100644 index 000000000000..ae3b926c52b1 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/model__special_model_name_.ml @@ -0,0 +1,24 @@ +(* + * 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] + + + ; [@key "$special[property.name]"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create () : t = { + special_property_name = None; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/name.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/name.ml new file mode 100644 index 000000000000..4b1861ea51ad --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/name.ml @@ -0,0 +1,47 @@ +(* + * 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 + + + + + ; [@key "name"] + snake_case: int32 + + option [@default None] + + + ; [@key "snake_case"] + property: string + + option [@default None] + + + ; [@key "property"] + var_123_number: int32 + + option [@default None] + + + ; [@key "123Number"] + } [@@deriving yojson { strict = false }, show, eq ];; + + (** 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/client/petstore/ocaml-fake-petstore/src/models/nullable_class.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/nullable_class.ml new file mode 100644 index 000000000000..690eb51db5e7 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/nullable_class.ml @@ -0,0 +1,89 @@ +(* + * 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] + + + ; [@key "integer_prop"] + number_prop: float + + option [@default None] + + + ; [@key "number_prop"] + boolean_prop: bool + + option [@default None] + + + ; [@key "boolean_prop"] + string_prop: string + + option [@default None] + + + ; [@key "string_prop"] + date_prop: string + + option [@default None] + + + ; [@key "date_prop"] + datetime_prop: string + + option [@default None] + + + ; [@key "datetime_prop"] + array_nullable_prop: Yojson.Safe.t list + [@default []] + + ; [@key "array_nullable_prop"] + array_and_items_nullable_prop: Yojson.Safe.t list + [@default []] + + ; [@key "array_and_items_nullable_prop"] + array_items_nullable: Yojson.Safe.t list + [@default []] + + ; [@key "array_items_nullable"] + object_nullable_prop: (string * Yojson.Safe.t) list + + [@default []] [@to_yojson JsonSupport.of_map_of [%to_yojson: Yojson.Safe.t]] [@of_yojson JsonSupport.to_map_of [%of_yojson: Yojson.Safe.t]] + ; [@key "object_nullable_prop"] + object_and_items_nullable_prop: (string * Yojson.Safe.t) list + + [@default []] [@to_yojson JsonSupport.of_map_of [%to_yojson: Yojson.Safe.t]] [@of_yojson JsonSupport.to_map_of [%of_yojson: Yojson.Safe.t]] + ; [@key "object_and_items_nullable_prop"] + object_items_nullable: (string * Yojson.Safe.t) list + + [@default []] [@to_yojson JsonSupport.of_map_of [%to_yojson: Yojson.Safe.t]] [@of_yojson JsonSupport.to_map_of [%of_yojson: Yojson.Safe.t]] + ; [@key "object_items_nullable"] + } [@@deriving yojson { strict = false }, show, eq ];; + + 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/client/petstore/ocaml-fake-petstore/src/models/number_only.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/number_only.ml new file mode 100644 index 000000000000..2ca1bb224c58 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/number_only.ml @@ -0,0 +1,24 @@ +(* + * 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] + + + ; [@key "JustNumber"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create () : t = { + just_number = None; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/object_with_deprecated_fields.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/object_with_deprecated_fields.ml new file mode 100644 index 000000000000..93bb27889b10 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/object_with_deprecated_fields.ml @@ -0,0 +1,43 @@ +(* + * 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] + + + ; [@key "uuid"] + id: float + + option [@default None] + + + ; [@key "id"] + deprecated_ref: Deprecated_object.t + + option [@default None] + + + ; [@key "deprecatedRef"] + bars: string list + [@default []] + + ; [@key "bars"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create () : t = { + uuid = None; + id = None; + deprecated_ref = None; + bars = []; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/order.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/order.ml new file mode 100644 index 000000000000..edeb14daf189 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/order.ml @@ -0,0 +1,60 @@ +(* + * 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] + + + ; [@key "id"] + pet_id: int64 + + option [@default None] + + + ; [@key "petId"] + quantity: int32 + + option [@default None] + + + ; [@key "quantity"] + ship_date: string + + option [@default None] + + + ; [@key "shipDate"] + (* Order Status *) + status: Enums.order_status + option [@default + + None + ] + ; [@key "status"] + complete: bool + + option [@default None] + + + ; [@key "complete"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create () : t = { + id = None; + pet_id = None; + quantity = None; + ship_date = None; + status = None; + complete = None; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/outer_composite.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/outer_composite.ml new file mode 100644 index 000000000000..5ab6dc894cfc --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/outer_composite.ml @@ -0,0 +1,38 @@ +(* + * 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] + + + ; [@key "my_number"] + my_string: string + + option [@default None] + + + ; [@key "my_string"] + my_boolean: bool + + option [@default None] + + + ; [@key "my_boolean"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create () : t = { + my_number = None; + my_string = None; + my_boolean = None; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/outer_object_with_enum_property.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/outer_object_with_enum_property.ml new file mode 100644 index 000000000000..defddabc9421 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/outer_object_with_enum_property.ml @@ -0,0 +1,24 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + + + + + type t = { + value: Enums.outerenuminteger + + + + + ; [@key "value"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create (value : Enums.outerenuminteger) : t = { + value = value; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/parent_with_nullable.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/parent_with_nullable.ml new file mode 100644 index 000000000000..0a82027599dc --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/parent_with_nullable.ml @@ -0,0 +1,31 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + + + + + type t = { + _type: Enums.parentwithnullable_type + option [@default + Some(`ChildWithNullable) + + ] + ; [@key "type"] + nullable_property: string + + option [@default None] + + + ; [@key "nullableProperty"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create () : t = { + _type = None; + nullable_property = None; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/pet.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/pet.ml new file mode 100644 index 000000000000..bf5b6f289e3c --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/pet.ml @@ -0,0 +1,56 @@ +(* + * 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] + + + ; [@key "id"] + category: Category.t + + option [@default None] + + + ; [@key "category"] + name: string + + + + + ; [@key "name"] + photo_urls: string list + + + ; [@key "photoUrls"] + tags: Tag.t list + [@default []] + + ; [@key "tags"] + (* pet status in the store *) + status: Enums.status + option [@default + + None + ] + ; [@key "status"] + } [@@deriving yojson { strict = false }, show, eq ];; + + 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/client/petstore/ocaml-fake-petstore/src/models/read_only_first.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/read_only_first.ml new file mode 100644 index 000000000000..42764810c586 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/read_only_first.ml @@ -0,0 +1,31 @@ +(* + * 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] + + + ; [@key "bar"] + baz: string + + option [@default None] + + + ; [@key "baz"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create () : t = { + bar = None; + baz = None; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/return.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/return.ml new file mode 100644 index 000000000000..1b27a9c0c5b5 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/return.ml @@ -0,0 +1,26 @@ +(* + * 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] + + + ; [@key "return"] + } [@@deriving yojson { strict = false }, show, eq ];; + + (** Model for testing reserved words *) + let create () : t = { + return = None; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/tag.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/tag.ml new file mode 100644 index 000000000000..01467b5e0745 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/tag.ml @@ -0,0 +1,31 @@ +(* + * 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] + + + ; [@key "id"] + name: string + + option [@default None] + + + ; [@key "name"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create () : t = { + id = None; + name = None; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/test_inline_freeform_additional_properties_request.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/test_inline_freeform_additional_properties_request.ml new file mode 100644 index 000000000000..9aa631abe7bc --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/test_inline_freeform_additional_properties_request.ml @@ -0,0 +1,24 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + + + + + type t = { + some_property: string + + option [@default None] + + + ; [@key "someProperty"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create () : t = { + some_property = None; + } + + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/user.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/user.ml new file mode 100644 index 000000000000..4582d3115276 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/user.ml @@ -0,0 +1,74 @@ +(* + * 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] + + + ; [@key "id"] + username: string + + option [@default None] + + + ; [@key "username"] + first_name: string + + option [@default None] + + + ; [@key "firstName"] + last_name: string + + option [@default None] + + + ; [@key "lastName"] + email: string + + option [@default None] + + + ; [@key "email"] + password: string + + option [@default None] + + + ; [@key "password"] + phone: string + + option [@default None] + + + ; [@key "phone"] + (* User Status *) + user_status: int32 + + option [@default None] + + + ; [@key "userStatus"] + } [@@deriving yojson { strict = false }, show, eq ];; + + 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/client/petstore/ocaml-fake-petstore/src/support/enums.ml b/samples/client/petstore/ocaml-fake-petstore/src/support/enums.ml new file mode 100644 index 000000000000..38b8eb297499 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/support/enums.ml @@ -0,0 +1,163 @@ +(* + * 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 }, eq];; + +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 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 }, eq];; + +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 }, eq];; + +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 }, eq];; + +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 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 }, eq];; + +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 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 }, eq];; + +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 order_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 }, eq];; + +let order_status_of_yojson json = order_status_of_yojson (`List [json]) +let order_status_to_yojson e = + match order_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 }, eq];; + +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 }, eq];; + +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 parentwithnullable_type = [ +| `ChildWithNullable [@printer fun fmt _ -> Format.pp_print_string fmt "ChildWithNullable"] [@name "ChildWithNullable"] +] [@@deriving yojson, show { with_path = false }, eq];; + +let parentwithnullable_type_of_yojson json = parentwithnullable_type_of_yojson (`List [json]) +let parentwithnullable_type_to_yojson e = + match parentwithnullable_type_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 }, eq];; + +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 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 }, eq];; + +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 singlereftype = [ +| `Admin [@printer fun fmt _ -> Format.pp_print_string fmt "admin"] [@name "admin"] +| `User [@printer fun fmt _ -> Format.pp_print_string fmt "user"] [@name "user"] +] [@@deriving yojson, show { with_path = false }, eq];; + +let singlereftype_of_yojson json = singlereftype_of_yojson (`List [json]) +let singlereftype_to_yojson e = + match singlereftype_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 }, eq];; + +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/client/petstore/ocaml-fake-petstore/src/support/jsonSupport.ml b/samples/client/petstore/ocaml-fake-petstore/src/support/jsonSupport.ml new file mode 100644 index 000000000000..0af0c25e759a --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/support/jsonSupport.ml @@ -0,0 +1,68 @@ +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 (Stdlib.List.map of_f l) + +let of_map_of of_f l = `Assoc (Stdlib.List.map (fun (k, v) -> (k, of_f v)) l) + +let to_map_of of_f json = + match json with + | `Assoc l -> + Stdlib.List.fold_right + (fun (k, json) acc -> + match (of_f json, acc) with + | Stdlib.Result.Ok parsed_v, Stdlib.Result.Ok tl -> + Stdlib.Result.Ok ((k, parsed_v) :: tl) + | Stdlib.Result.Error e, _ -> Stdlib.Result.Error e + | _, Stdlib.Result.Error e -> Stdlib.Result.Error e) + l (Stdlib.Result.Ok []) + | _ -> Stdlib.Result.Error "Expected" diff --git a/samples/client/petstore/ocaml-fake-petstore/src/support/request.ml b/samples/client/petstore/ocaml-fake-petstore/src/support/request.ml new file mode 100644 index 000000000000..cbb1a71ea697 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/support/request.ml @@ -0,0 +1,110 @@ +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.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 >|= Stdlib.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 >|= Stdlib.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 + +(** Corresponds to: + - [style = form] + - [explode = true] + - type [object] + + See https://swagger.io/docs/specification/v3_0/serialization/#query-parameters +*) +let add_query_param_exploded_form_object uri _param_name to_string param_value = +Stdlib.List.fold_left + (fun uri (param_name, param_value) -> add_query_param uri param_name to_string param_value) + 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 diff --git a/samples/client/petstore/ocaml-oneOf/.openapi-generator-ignore b/samples/client/petstore/ocaml-oneOf/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/client/petstore/ocaml-oneOf/.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/client/petstore/ocaml-oneOf/.openapi-generator/FILES b/samples/client/petstore/ocaml-oneOf/.openapi-generator/FILES new file mode 100644 index 000000000000..0623f326da70 --- /dev/null +++ b/samples/client/petstore/ocaml-oneOf/.openapi-generator/FILES @@ -0,0 +1,11 @@ +README.md +dune +dune-project +petstore_client.opam +src/apis/default_api.ml +src/apis/default_api.mli +src/models/child.ml +src/models/example.ml +src/support/enums.ml +src/support/jsonSupport.ml +src/support/request.ml diff --git a/samples/client/petstore/ocaml-oneOf/.openapi-generator/VERSION b/samples/client/petstore/ocaml-oneOf/.openapi-generator/VERSION new file mode 100644 index 000000000000..5e5282953086 --- /dev/null +++ b/samples/client/petstore/ocaml-oneOf/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.16.0-SNAPSHOT diff --git a/samples/client/petstore/ocaml-oneOf/README.md b/samples/client/petstore/ocaml-oneOf/README.md new file mode 100644 index 000000000000..d33f72445fdf --- /dev/null +++ b/samples/client/petstore/ocaml-oneOf/README.md @@ -0,0 +1,33 @@ +# +No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + +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 +- Generator version: 7.16.0-SNAPSHOT +- Build package: org.openapitools.codegen.languages.OCamlClientCodegen + +## Requirements. + +OCaml 5.x + +## Installation + +Please run the following commands to build the package `petstore_client`: + +```sh +opam install . --deps-only --with-test +eval $(opam env) +dune build +``` + +## Getting Started + +The generated directory structure is: +- `src/apis`: contains several modules, each with several functions. Each function is an API endpoint. +- `src/models`: contains several modules. Each module contains: + - a type `t` representing an input and/or output schema of the OpenAPI spec + - a smart constructor `create` for this type +- `src/support`: various modules used by the generated APIs and Models + diff --git a/samples/client/petstore/ocaml-oneOf/dune b/samples/client/petstore/ocaml-oneOf/dune new file mode 100644 index 000000000000..ed1c4d90e3df --- /dev/null +++ b/samples/client/petstore/ocaml-oneOf/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/client/petstore/ocaml-oneOf/dune-project b/samples/client/petstore/ocaml-oneOf/dune-project new file mode 100644 index 000000000000..79d86e3c901a --- /dev/null +++ b/samples/client/petstore/ocaml-oneOf/dune-project @@ -0,0 +1,2 @@ +(lang dune 1.10) +(name petstore_client) \ No newline at end of file diff --git a/samples/client/petstore/ocaml-oneOf/petstore_client.opam b/samples/client/petstore/ocaml-oneOf/petstore_client.opam new file mode 100644 index 000000000000..7ca31fc5af4f --- /dev/null +++ b/samples/client/petstore/ocaml-oneOf/petstore_client.opam @@ -0,0 +1,24 @@ +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" + "dune" + "ppx_deriving_yojson" + "conf-libev" + "lwt" + "cohttp-lwt-unix" {< "6.0.0"} + "cohttp-async" {< "6.0.0"} +] +build: ["dune" "build" "-p" name] diff --git a/samples/client/petstore/ocaml-oneOf/src/apis/default_api.ml b/samples/client/petstore/ocaml-oneOf/src/apis/default_api.ml new file mode 100644 index 000000000000..93677e4bf1f5 --- /dev/null +++ b/samples/client/petstore/ocaml-oneOf/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 list () = + let open Lwt.Infix in + let uri = Request.build_uri "/example" 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 Example.of_yojson) resp body + diff --git a/samples/client/petstore/ocaml-oneOf/src/apis/default_api.mli b/samples/client/petstore/ocaml-oneOf/src/apis/default_api.mli new file mode 100644 index 000000000000..2b244b750994 --- /dev/null +++ b/samples/client/petstore/ocaml-oneOf/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 list : unit -> Example.t Lwt.t diff --git a/samples/client/petstore/ocaml-oneOf/src/models/child.ml b/samples/client/petstore/ocaml-oneOf/src/models/child.ml new file mode 100644 index 000000000000..ff9a12f2eb4d --- /dev/null +++ b/samples/client/petstore/ocaml-oneOf/src/models/child.ml @@ -0,0 +1,24 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + + + + + type t = { + name: string + + option [@default None] + + + ; [@key "name"] + } [@@deriving yojson { strict = false }, show, eq ];; + + let create () : t = { + name = None; + } + + diff --git a/samples/client/petstore/ocaml-oneOf/src/models/example.ml b/samples/client/petstore/ocaml-oneOf/src/models/example.ml new file mode 100644 index 000000000000..42162d950c76 --- /dev/null +++ b/samples/client/petstore/ocaml-oneOf/src/models/example.ml @@ -0,0 +1,39 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + + type t = + | OneOf0 of Child.t + | OneOf1 of int32 + [@@deriving show, eq];; + + let to_yojson = function + | OneOf0 v -> [%to_yojson: Child.t] v + | OneOf1 v -> [%to_yojson: int32] v + + (* Manual implementations because the derived one encodes into a tuple list where the first element is the constructor name. *) + + let of_yojson json = + [ + [%of_yojson: Child.t] json + |> Stdlib.Result.to_option + |> Stdlib.Option.map (fun v -> OneOf0 v); + [%of_yojson: int32] json + |> Stdlib.Result.to_option + |> Stdlib.Option.map (fun v -> OneOf1 v); + ] + |> Stdlib.List.filter_map (Fun.id) + |> function + | [t] -> Ok t + | [] -> Error ("Failed to parse JSON " ^ Yojson.Safe.show json ^ " into a value of type Example.t") + | ts -> let parsed_ts = ts + |> Stdlib.List.map show + |> Stdlib.String.concat " | " + in Error ("Failed to parse JSON " ^ Yojson.Safe.show json ^ " into a value of type Example.t: oneOf should only succeed on one parser, but the JSON was parsed into [" ^ parsed_ts ^ "]") + + + + diff --git a/samples/client/petstore/ocaml-oneOf/src/support/enums.ml b/samples/client/petstore/ocaml-oneOf/src/support/enums.ml new file mode 100644 index 000000000000..b30c42f110c6 --- /dev/null +++ b/samples/client/petstore/ocaml-oneOf/src/support/enums.ml @@ -0,0 +1,6 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) diff --git a/samples/client/petstore/ocaml-oneOf/src/support/jsonSupport.ml b/samples/client/petstore/ocaml-oneOf/src/support/jsonSupport.ml new file mode 100644 index 000000000000..0af0c25e759a --- /dev/null +++ b/samples/client/petstore/ocaml-oneOf/src/support/jsonSupport.ml @@ -0,0 +1,68 @@ +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 (Stdlib.List.map of_f l) + +let of_map_of of_f l = `Assoc (Stdlib.List.map (fun (k, v) -> (k, of_f v)) l) + +let to_map_of of_f json = + match json with + | `Assoc l -> + Stdlib.List.fold_right + (fun (k, json) acc -> + match (of_f json, acc) with + | Stdlib.Result.Ok parsed_v, Stdlib.Result.Ok tl -> + Stdlib.Result.Ok ((k, parsed_v) :: tl) + | Stdlib.Result.Error e, _ -> Stdlib.Result.Error e + | _, Stdlib.Result.Error e -> Stdlib.Result.Error e) + l (Stdlib.Result.Ok []) + | _ -> Stdlib.Result.Error "Expected" diff --git a/samples/client/petstore/ocaml-oneOf/src/support/request.ml b/samples/client/petstore/ocaml-oneOf/src/support/request.ml new file mode 100644 index 000000000000..c89862d5d0ea --- /dev/null +++ b/samples/client/petstore/ocaml-oneOf/src/support/request.ml @@ -0,0 +1,110 @@ +let api_key = "" +let base_url = "http://api.example.xyz/v1" +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.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 >|= Stdlib.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 >|= Stdlib.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 + +(** Corresponds to: + - [style = form] + - [explode = true] + - type [object] + + See https://swagger.io/docs/specification/v3_0/serialization/#query-parameters +*) +let add_query_param_exploded_form_object uri _param_name to_string param_value = +Stdlib.List.fold_left + (fun uri (param_name, param_value) -> add_query_param uri param_name to_string param_value) + 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 diff --git a/samples/client/petstore/ocaml/src/apis/pet_api.ml b/samples/client/petstore/ocaml/src/apis/pet_api.ml index 9df027a393cb..386163121bda 100644 --- a/samples/client/petstore/ocaml/src/apis/pet_api.ml +++ b/samples/client/petstore/ocaml/src/apis/pet_api.ml @@ -9,7 +9,21 @@ let add_pet ~pet_t = let open Lwt.Infix 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 + 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.read_json_body_as (JsonSupport.unwrap Pet.of_yojson) resp body @@ -17,8 +31,36 @@ let delete_pet ~pet_id ?api_key () = let open Lwt.Infix 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 + 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 @@ -26,7 +68,10 @@ let find_pets_by_status ~status = let open Lwt.Infix 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 + let uri = Request.add_query_param_list uri "status" (Stdlib.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 @@ -34,7 +79,34 @@ let find_pets_by_tags ~tags = let open Lwt.Infix 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 + let uri = Request.add_query_param_list uri "tags" (Stdlib.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 @@ -43,7 +115,21 @@ let get_pet_by_id ~pet_id = 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 + 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 @@ -51,7 +137,21 @@ let update_pet ~pet_t = let open Lwt.Infix 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 + 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.read_json_body_as (JsonSupport.unwrap Pet.of_yojson) resp body @@ -59,10 +159,52 @@ let update_pet_with_form ~pet_id ?name ?status () = let open Lwt.Infix 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.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.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 @@ -71,10 +213,52 @@ let upload_file ~pet_id ?additional_metadata ?file () = let open Lwt.Infix 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.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.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/store_api.ml b/samples/client/petstore/ocaml/src/apis/store_api.ml index 2fafcfd77eb7..510e9ea48325 100644 --- a/samples/client/petstore/ocaml/src/apis/store_api.ml +++ b/samples/client/petstore/ocaml/src/apis/store_api.ml @@ -9,7 +9,21 @@ let delete_order ~order_id = let open Lwt.Infix in let uri = Request.build_uri "/store/order/{orderId}" in let headers = Request.default_headers in - let uri = Request.replace_path_param uri "orderId" (fun x -> x) 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 @@ -25,7 +39,21 @@ let get_order_by_id ~order_id = let open Lwt.Infix 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 @@ -33,7 +61,21 @@ let place_order ~order_t = let open Lwt.Infix 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 + 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/client/petstore/ocaml/src/apis/user_api.ml b/samples/client/petstore/ocaml/src/apis/user_api.ml index b0b45d12095f..d034b4b22851 100644 --- a/samples/client/petstore/ocaml/src/apis/user_api.ml +++ b/samples/client/petstore/ocaml/src/apis/user_api.ml @@ -10,7 +10,21 @@ let create_user ~user_t = let uri = Request.build_uri "/user" in let headers = Request.default_headers in let headers = Cohttp.Header.add headers "api_key" Request.api_key in - let body = Request.write_as_json_body User.to_yojson user_t 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 @@ -19,7 +33,22 @@ let create_users_with_array_input ~user = let uri = Request.build_uri "/user/createWithArray" in let headers = Request.default_headers in let headers = Cohttp.Header.add headers "api_key" Request.api_key in - let body = Request.write_as_json_body (JsonSupport.of_list_of User.to_yojson) user 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 @@ -28,7 +57,22 @@ let create_users_with_list_input ~user = let uri = Request.build_uri "/user/createWithList" in let headers = Request.default_headers in let headers = Cohttp.Header.add headers "api_key" Request.api_key in - let body = Request.write_as_json_body (JsonSupport.of_list_of User.to_yojson) user 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 @@ -37,7 +81,21 @@ let delete_user ~username = let uri = Request.build_uri "/user/{username}" 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 "username" (fun x -> x) 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 @@ -45,7 +103,21 @@ let get_user_by_name ~username = let open Lwt.Infix 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 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 @@ -53,8 +125,36 @@ let login_user ~username ~password = let open Lwt.Infix 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 + 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 @@ -71,8 +171,36 @@ let update_user ~username ~user_t = let uri = Request.build_uri "/user/{username}" 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 "username" (fun x -> x) username in - let body = Request.write_as_json_body User.to_yojson user_t 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/client/petstore/ocaml/src/models/api_response.ml b/samples/client/petstore/ocaml/src/models/api_response.ml index 0abc8a37b74a..b2a6f6824638 100644 --- a/samples/client/petstore/ocaml/src/models/api_response.ml +++ b/samples/client/petstore/ocaml/src/models/api_response.ml @@ -6,28 +6,35 @@ * Schema Api_response.t : Describes the result of uploading an image resource *) -type t = { - code: int32 - - option [@default None] - - ; [@key "code"] - _type: string - - option [@default None] - - ; [@key "type"] - message: string - - option [@default None] - - ; [@key "message"] -} [@@deriving yojson { strict = false }, show, eq ];; -(** Describes the result of uploading an image resource *) -let create () : t = { - code = None; - _type = None; - message = None; -} + + + type t = { + code: int32 + + option [@default None] + + + ; [@key "code"] + _type: string + + option [@default None] + + + ; [@key "type"] + message: string + + option [@default None] + + + ; [@key "message"] + } [@@deriving yojson { strict = false }, show, eq ];; + + (** Describes the result of uploading an image resource *) + let create () : t = { + code = None; + _type = None; + message = None; + } + diff --git a/samples/client/petstore/ocaml/src/models/category.ml b/samples/client/petstore/ocaml/src/models/category.ml index 47b8f3bee0ea..cb63d1c6ff83 100644 --- a/samples/client/petstore/ocaml/src/models/category.ml +++ b/samples/client/petstore/ocaml/src/models/category.ml @@ -6,22 +6,28 @@ * Schema Category.t : A category for a pet *) -type t = { - id: int64 - - option [@default None] - - ; [@key "id"] - name: string - - option [@default None] - - ; [@key "name"] -} [@@deriving yojson { strict = false }, show, eq ];; -(** A category for a pet *) -let create () : t = { - id = None; - name = None; -} + + + type t = { + id: int64 + + option [@default None] + + + ; [@key "id"] + name: string + + option [@default None] + + + ; [@key "name"] + } [@@deriving yojson { strict = false }, show, eq ];; + + (** A category for a pet *) + let create () : t = { + id = None; + name = None; + } + diff --git a/samples/client/petstore/ocaml/src/models/order.ml b/samples/client/petstore/ocaml/src/models/order.ml index f88bd155f703..3e4e63cda43d 100644 --- a/samples/client/petstore/ocaml/src/models/order.ml +++ b/samples/client/petstore/ocaml/src/models/order.ml @@ -6,48 +6,57 @@ * Schema Order.t : An order for a pets from the pet store *) -type t = { - id: int64 - - option [@default None] - - ; [@key "id"] - pet_id: int64 - - option [@default None] - - ; [@key "petId"] - quantity: int32 - - option [@default None] - - ; [@key "quantity"] - ship_date: string - - option [@default None] - - ; [@key "shipDate"] - (* Order Status *) - status: Enums.status - option [@default - - None - ] - ; [@key "status"] - complete: bool - - option [@default None] - - ; [@key "complete"] -} [@@deriving yojson { strict = false }, show, eq ];; -(** An order for a pets from the pet store *) -let create () : t = { - id = None; - pet_id = None; - quantity = None; - ship_date = None; - status = None; - complete = None; -} + + + type t = { + id: int64 + + option [@default None] + + + ; [@key "id"] + pet_id: int64 + + option [@default None] + + + ; [@key "petId"] + quantity: int32 + + option [@default None] + + + ; [@key "quantity"] + ship_date: string + + option [@default None] + + + ; [@key "shipDate"] + (* Order Status *) + status: Enums.status + option [@default + + None + ] + ; [@key "status"] + complete: bool + + option [@default None] + + + ; [@key "complete"] + } [@@deriving yojson { strict = false }, show, eq ];; + + (** An order for a pets from the pet store *) + let create () : t = { + id = None; + pet_id = None; + quantity = None; + ship_date = None; + status = None; + complete = None; + } + diff --git a/samples/client/petstore/ocaml/src/models/pet.ml b/samples/client/petstore/ocaml/src/models/pet.ml index 34001310d298..af5288538870 100644 --- a/samples/client/petstore/ocaml/src/models/pet.ml +++ b/samples/client/petstore/ocaml/src/models/pet.ml @@ -6,44 +6,53 @@ * Schema Pet.t : A pet for sale in the pet store *) -type t = { - id: int64 - - option [@default None] - - ; [@key "id"] - category: Category.t - - option [@default None] - - ; [@key "category"] - name: string - - - - ; [@key "name"] - photo_urls: string list - - ; [@key "photoUrls"] - tags: Tag.t list - [@default []] - ; [@key "tags"] - (* pet status in the store *) - status: Enums.pet_status - option [@default - - None - ] - ; [@key "status"] -} [@@deriving yojson { strict = false }, show, eq ];; -(** A pet for sale in the pet store *) -let create (name : string) (photo_urls : string list) : t = { - id = None; - category = None; - name = name; - photo_urls = photo_urls; - tags = []; - status = None; -} + + + type t = { + id: int64 + + option [@default None] + + + ; [@key "id"] + category: Category.t + + option [@default None] + + + ; [@key "category"] + name: string + + + + + ; [@key "name"] + photo_urls: string list + + + ; [@key "photoUrls"] + tags: Tag.t list + [@default []] + + ; [@key "tags"] + (* pet status in the store *) + status: Enums.pet_status + option [@default + + None + ] + ; [@key "status"] + } [@@deriving yojson { strict = false }, show, eq ];; + + (** A pet for sale in the pet store *) + let create (name : string) (photo_urls : string list) : t = { + id = None; + category = None; + name = name; + photo_urls = photo_urls; + tags = []; + status = None; + } + diff --git a/samples/client/petstore/ocaml/src/models/tag.ml b/samples/client/petstore/ocaml/src/models/tag.ml index 9c89a1d1e051..8a4cd6418109 100644 --- a/samples/client/petstore/ocaml/src/models/tag.ml +++ b/samples/client/petstore/ocaml/src/models/tag.ml @@ -6,22 +6,28 @@ * Schema Tag.t : A tag for a pet *) -type t = { - id: int64 - - option [@default None] - - ; [@key "id"] - name: string - - option [@default None] - - ; [@key "name"] -} [@@deriving yojson { strict = false }, show, eq ];; -(** A tag for a pet *) -let create () : t = { - id = None; - name = None; -} + + + type t = { + id: int64 + + option [@default None] + + + ; [@key "id"] + name: string + + option [@default None] + + + ; [@key "name"] + } [@@deriving yojson { strict = false }, show, eq ];; + + (** A tag for a pet *) + let create () : t = { + id = None; + name = None; + } + diff --git a/samples/client/petstore/ocaml/src/models/user.ml b/samples/client/petstore/ocaml/src/models/user.ml index 38ed8cce2dd3..4f79bf2b71c0 100644 --- a/samples/client/petstore/ocaml/src/models/user.ml +++ b/samples/client/petstore/ocaml/src/models/user.ml @@ -6,59 +6,71 @@ * Schema User.t : A User who is purchasing from the pet store *) -type t = { - id: int64 - - option [@default None] - - ; [@key "id"] - username: string - - option [@default None] - - ; [@key "username"] - first_name: string - - option [@default None] - - ; [@key "firstName"] - last_name: string - - option [@default None] - - ; [@key "lastName"] - email: string - - option [@default None] - - ; [@key "email"] - password: string - - option [@default None] - - ; [@key "password"] - phone: string - - option [@default None] - - ; [@key "phone"] - (* User Status *) - user_status: int32 - - option [@default None] - - ; [@key "userStatus"] -} [@@deriving yojson { strict = false }, show, eq ];; -(** A User who is purchasing from the pet store *) -let create () : t = { - id = None; - username = None; - first_name = None; - last_name = None; - email = None; - password = None; - phone = None; - user_status = None; -} + + + type t = { + id: int64 + + option [@default None] + + + ; [@key "id"] + username: string + + option [@default None] + + + ; [@key "username"] + first_name: string + + option [@default None] + + + ; [@key "firstName"] + last_name: string + + option [@default None] + + + ; [@key "lastName"] + email: string + + option [@default None] + + + ; [@key "email"] + password: string + + option [@default None] + + + ; [@key "password"] + phone: string + + option [@default None] + + + ; [@key "phone"] + (* User Status *) + user_status: int32 + + option [@default None] + + + ; [@key "userStatus"] + } [@@deriving yojson { strict = false }, show, eq ];; + + (** A User who is purchasing from the pet store *) + let create () : t = { + id = None; + username = None; + first_name = None; + last_name = None; + email = None; + password = None; + phone = None; + user_status = None; + } + diff --git a/samples/client/petstore/ocaml/src/support/jsonSupport.ml b/samples/client/petstore/ocaml/src/support/jsonSupport.ml index 4b0fac77545a..0af0c25e759a 100644 --- a/samples/client/petstore/ocaml/src/support/jsonSupport.ml +++ b/samples/client/petstore/ocaml/src/support/jsonSupport.ml @@ -50,6 +50,19 @@ 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_list_of of_f l = `List (Stdlib.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 +let of_map_of of_f l = `Assoc (Stdlib.List.map (fun (k, v) -> (k, of_f v)) l) + +let to_map_of of_f json = + match json with + | `Assoc l -> + Stdlib.List.fold_right + (fun (k, json) acc -> + match (of_f json, acc) with + | Stdlib.Result.Ok parsed_v, Stdlib.Result.Ok tl -> + Stdlib.Result.Ok ((k, parsed_v) :: tl) + | Stdlib.Result.Error e, _ -> Stdlib.Result.Error e + | _, Stdlib.Result.Error e -> Stdlib.Result.Error e) + l (Stdlib.Result.Ok []) + | _ -> Stdlib.Result.Error "Expected" diff --git a/samples/client/petstore/ocaml/src/support/request.ml b/samples/client/petstore/ocaml/src/support/request.ml index dde0e723e481..fea945d04cf3 100644 --- a/samples/client/petstore/ocaml/src/support/request.ml +++ b/samples/client/petstore/ocaml/src/support/request.ml @@ -35,7 +35,7 @@ let write_json_body payload = 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 + match Cohttp.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))) @@ -52,13 +52,13 @@ 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) + Lwt.(read_json_body_as_list resp body >|= Stdlib.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))) + Lwt.(read_json_body_as_map resp body >|= Stdlib.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 @@ -80,6 +80,19 @@ let add_query_param_list 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 +(** Corresponds to: + - [style = form] + - [explode = true] + - type [object] + + See https://swagger.io/docs/specification/v3_0/serialization/#query-parameters +*) +let add_query_param_exploded_form_object uri _param_name to_string param_value = +Stdlib.List.fold_left + (fun uri (param_name, param_value) -> add_query_param uri param_name to_string param_value) + uri + param_value + let init_form_encoded_body () = "" let add_form_encoded_body_param params param_name to_string param_value =