Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/samples-ocaml.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ on:
paths:
- 'samples/client/petstore/ocaml/**'
- 'samples/client/petstore/ocaml-fake-petstore/**'
- 'samples/client/petstore/ocaml-oneOf/**'
- 'samples/client/petstore/ocaml-oneOf-primitive/**'
- 'samples/client/petstore/ocaml-additional-properties/**'
pull_request:
paths:
- 'samples/client/petstore/ocaml/**'
- 'samples/client/petstore/ocaml-fake-petstore/**'
- 'samples/client/petstore/ocaml-oneOf/**'
- 'samples/client/petstore/ocaml-oneOf-primitive/**'
- 'samples/client/petstore/ocaml-additional-properties/**'

jobs:
build:
Expand All @@ -22,7 +24,8 @@ jobs:
sample:
- 'samples/client/petstore/ocaml/'
- 'samples/client/petstore/ocaml-fake-petstore/'
- 'samples/client/petstore/ocaml-oneOf/'
- 'samples/client/petstore/ocaml-oneOf-primitive/'
- 'samples/client/petstore/ocaml-additional-properties/'
steps:
- uses: actions/checkout@v5
- name: Set-up OCaml
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,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/
samples/client/petstore/ocaml-oneOf-primitive/_build/
samples/client/petstore/ocaml-additional-properties/_build/

# jetbrain http client
samples/client/jetbrains/adyen/checkout71/http/client/Apis/http-client.private.env.json
6 changes: 6 additions & 0 deletions bin/configs/ocaml-additional-properties.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
generatorName: ocaml
outputDir: samples/client/petstore/ocaml-additional-properties
inputSpec: modules/openapi-generator/src/test/resources/3_0/ocaml/additional-properties.yaml
templateDir: modules/openapi-generator/src/main/resources/ocaml
additionalProperties:
packageName: petstore_client
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
generatorName: ocaml
outputDir: samples/client/petstore/ocaml-oneOf
outputDir: samples/client/petstore/ocaml-oneOf-primitive
inputSpec: modules/openapi-generator/src/test/resources/3_0/oneOf_primitive.yaml
templateDir: modules/openapi-generator/src/main/resources/ocaml
additionalProperties:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
type t = {
{{#vars}}
{{#description}}
(* {{{.}}} *)
{{/description}}
{{#isEnum}}
{{{name}}}: {{^isMap}}Enums.{{/isMap}}{{{datatypeWithEnum}}}
{{^isContainer}}
Expand All @@ -28,9 +25,12 @@ type t = {
{{^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}}
{{#isMap}}{{^required}} [@default []]{{/required}} [@to_yojson JsonSupport.of_map_of [%to_yojson: {{{items.datatypeWithEnum}}}]] [@of_yojson JsonSupport.to_map_of [%of_yojson: {{{items.datatypeWithEnum}}}]]{{/isMap}}
; [@key "{{{baseName}}}"]
{{/isEnum}}
{{#description}}
(** {{{.}}} *)
{{/description}}
{{/vars}}
} [@@deriving yojson { strict = false }, show, eq ];;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Test various flavors of additionalProperties
openapi: 3.0.0
info:
title: Test
version: 1.0.0
paths: {}
components:
schemas:
SomeObject:
required:
- required_field1
- required_field2
- required_field3
properties:
required_field1:
type: object
description: Required, free-form
additionalProperties: {}
required_field2:
type: object
description: Required, dictionary of strings
additionalProperties:
type: string
required_field3:
type: object
description: Required, dictionary of objects
additionalProperties:
type: object
properties:
sub_field1:
type: number
sub_field2:
type: boolean
optional_field1:
type: object
description: Optional, free-form
additionalProperties: {}
optional_field2:
type: object
description: Optional, dictionary of strings
additionalProperties:
type: string
optional_field3:
type: object
description: Optional, dictionary of objects
additionalProperties:
type: object
properties:
sub_field1:
type: number
sub_field2:
type: boolean
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.ocamlformat
README.md
dune
dune-project
petstore_client.opam
src/models/some_object.ml
src/models/some_object_required_field3_value.ml
src/support/enums.ml
src/support/jsonSupport.ml
src/support/request.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
(*
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
*
* Generated by: https://openapi-generator.tech
*
*)




type t = {
required_field1: (string * Yojson.Safe.t) list

[@to_yojson JsonSupport.of_map_of [%to_yojson: Yojson.Safe.t]] [@of_yojson JsonSupport.to_map_of [%of_yojson: Yojson.Safe.t]]
; [@key "required_field1"]
(** Required, free-form *)
required_field2: (string * string) list

[@to_yojson JsonSupport.of_map_of [%to_yojson: string]] [@of_yojson JsonSupport.to_map_of [%of_yojson: string]]
; [@key "required_field2"]
(** Required, dictionary of strings *)
required_field3: (string * Some_object_required_field3_value.t) list

[@to_yojson JsonSupport.of_map_of [%to_yojson: Some_object_required_field3_value.t]] [@of_yojson JsonSupport.to_map_of [%of_yojson: Some_object_required_field3_value.t]]
; [@key "required_field3"]
(** Required, dictionary of objects *)
optional_field1: (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 "optional_field1"]
(** Optional, free-form *)
optional_field2: (string * string) list

[@default []] [@to_yojson JsonSupport.of_map_of [%to_yojson: string]] [@of_yojson JsonSupport.to_map_of [%of_yojson: string]]
; [@key "optional_field2"]
(** Optional, dictionary of strings *)
optional_field3: (string * Some_object_required_field3_value.t) list

[@default []] [@to_yojson JsonSupport.of_map_of [%to_yojson: Some_object_required_field3_value.t]] [@of_yojson JsonSupport.to_map_of [%of_yojson: Some_object_required_field3_value.t]]
; [@key "optional_field3"]
(** Optional, dictionary of objects *)
} [@@deriving yojson { strict = false }, show, eq ];;

let create (required_field1 : (string * Yojson.Safe.t) list) (required_field2 : (string * string) list) (required_field3 : (string * Some_object_required_field3_value.t) list) : t = {
required_field1 = required_field1;
required_field2 = required_field2;
required_field3 = required_field3;
optional_field1 = [];
optional_field2 = [];
optional_field3 = [];
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
(*
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
*
* Generated by: https://openapi-generator.tech
*
*)




type t = {
sub_field1: float

option [@default None]


; [@key "sub_field1"]
sub_field2: bool

option [@default None]


; [@key "sub_field2"]
} [@@deriving yojson { strict = false }, show, eq ];;

let create () : t = {
sub_field1 = None;
sub_field2 = None;
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
let api_key = ""
let base_url = "http://localhost"
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@


type t = {
map_property: (string * string) list
map_property: (string * string) list

[@default []] [@to_yojson JsonSupport.of_map_of [%to_yojson: string]] [@of_yojson JsonSupport.to_map_of [%of_yojson: string]]
[@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]]
[@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 ];;
} [@@deriving yojson { strict = false }, show, eq ];;

let create () : t = {
map_property = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


type t = {
username: string
username: string

option [@default None]

Expand All @@ -21,7 +21,7 @@


; [@key "SingleRefType"]
} [@@deriving yojson { strict = false }, show, eq ];;
} [@@deriving yojson { strict = false }, show, eq ];;

let create () : t = {
username = None;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


type t = {
class_name: string
class_name: string



Expand All @@ -21,7 +21,7 @@


; [@key "color"]
} [@@deriving yojson { strict = false }, show, eq ];;
} [@@deriving yojson { strict = false }, show, eq ];;

let create (class_name : string) : t = {
class_name = class_name;
Expand Down
Loading
Loading