Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
8ad109e
Début d'un générateur pour OCaml.
Jul 12, 2019
6eee563
Ajout du script bash de generation pour OCaml.
Jul 13, 2019
428f682
Implémentation de la partie model du générateur OCaml.
cgensoul Jul 16, 2019
80dcf79
Suppression du fichier Model.mustache.
Jul 16, 2019
305c9aa
Légère modification dans le générateur OCaml.
Jul 16, 2019
8de8ef6
Début d'implémentation de la génération des opérations.
cgensoul Jul 16, 2019
ee3cef7
Avancées dans l'implémenatation des opérations.
cgensoul Jul 17, 2019
6d954f7
Avancée dans la gestion des enums : reste à traiter le fait que Yojso…
Jul 18, 2019
06619ac
Prise en compte du fait que Yojson représente les variants constants …
cgensoul Jul 18, 2019
b2cb9a2
Utilisation des variants polymorphe pour les enums car il se peut que…
Jul 19, 2019
8346f9f
Avancées dans le générateur de code OCaml : le code produit compile e…
Jul 19, 2019
80a9884
More tests.
Jul 19, 2019
5c7e0e0
Correction de problèmes dans la génération mis en évidence par l'util…
Jul 22, 2019
ef6c19c
Mapping du case Error de Ppx_deriving_yojson_runtime.ok_error vers l'…
Jul 22, 2019
83d0d17
Ajout de la génération des fichiers d'interfaces .mli pour les APIs.
Jul 22, 2019
afcfc1a
Ajout du support des parametres de type x-www-form-urlencoded.
Jul 23, 2019
4c63dfe
Le paramètres d'url de type number étaient mal gérés.
Jul 23, 2019
4f1f2fc
Cleanup.
Jul 23, 2019
55c81ef
Replace block comment start and end sequences in input text.
Jul 23, 2019
aa978f6
Make apis calls without a return type return unit rather than Yojson.…
Jul 23, 2019
28477e6
Make modules/openapi-generator/src/test/resources/3_0/petstore-with-f…
Jul 24, 2019
382eefe
Better handling of enums and map container and better sanitizing of g…
Jul 24, 2019
cce2152
Added generated code for modules/openapi-generator/src/test/resources…
Jul 24, 2019
eaad2bc
Correcting a violation : using toLowerCase without relying on the def…
Jul 24, 2019
c723573
Changed authoring in partial_header.mustache.
Jul 24, 2019
391de4e
Deleted commented code.
Jul 24, 2019
9287c8e
Collect enum schemas in items properties of operation parameters in t…
cgensoul Jul 24, 2019
b0b943b
Collect enums also in additional properties schemas of operation para…
cgensoul Jul 24, 2019
ba65b78
Removed copy-pasted Copyright notice from SmartBear.
cgensoul Jul 25, 2019
277822c
update doc
wing328 Jul 25, 2019
d80f22a
Use Locale.ROOT instead of Locale.ENGLISH for toLowerCase calls.
Jul 25, 2019
55bcfb7
Make GET operations with body generate compilable code.
Jul 25, 2019
67a2b38
Updated ocaml-client generated samples using the latest version of th…
Jul 25, 2019
b9545de
Added [@default None] for record fields with option types so that if …
Jul 25, 2019
70762d4
Added support of api keys in query params.
Jul 25, 2019
2b093bd
Updated generated ocaml samples to reflect latest changes in templates.
Jul 25, 2019
a2073f1
Added [@default] on enum record fields for which the enum type has on…
Jul 26, 2019
ecc8922
Delete useless space character in template.
cgensoul Jul 27, 2019
c4535f4
Added proper handling of http response codes.
cgensoul Jul 27, 2019
4b5d0aa
Updated generated ocaml samples to reflect latest changes in templates.
cgensoul Jul 27, 2019
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
Prev Previous commit
Next Next commit
Avancée dans la gestion des enums : reste à traiter le fait que Yojso…
…n sérialize les variants comme des tableaux JSON.
  • Loading branch information
Christophe Gensoul committed Jul 24, 2019
commit 6d954f70f37ab5441db33929f5a8c3e6b94e8668

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
{{#operation}}
let {{{operationId}}} {{#allParams}}{{{paramName}}}{{#hasMore}} {{/hasMore}}{{/allParams}} =
let headers = Request.default_headers in
let uri = Request.build_uri "{{{path}}}" in{{#hasPathParams}}
{{#pathParams}}let uri = Request.replace_path_param uri "{{{baseName}}}" {{#isString}}{{{paramName}}}{{/isString}}{{#isLong}}(Int64.to_string {{{paramName}}}){{/isLong}}{{#isInteger}}(Int32.to_string {{{paramName}}}){{/isInteger}}{{#isFloat}}(string_of_float {{{paramName}}}){{/isFloat}} in
{{/pathParams}}{{/hasPathParams}}{{#hasQueryParams}}
{{#queryParams}}let uri = Uri.add_query_param' uri ("{{{baseName}}}", {{{paramName}}}) in
{{/queryParams}}{{/hasQueryParams}}{{#hasBodyParam}}
{{#bodyParams}}{{#isBodyParam}}let body = Request.build_body {{{vendorExtensions.x-modelModule}}}.to_yojson {{{paramName}}} in{{/isBodyParam}}{{/bodyParams}}{{/hasBodyParam}}
let uri = Request.build_uri "{{{path}}}" in{{#pathParams}}
let uri = Request.replace_path_param uri "{{{baseName}}}" ({{> to_string}}{{{paramName}}}) in{{/pathParams}}{{#queryParams}}
let uri = Uri.add_query_param{{^isListContainer}}'{{/isListContainer}} uri ("{{{baseName}}}", {{> to_string}}{{{paramName}}}) in{{/queryParams}}{{#bodyParams}}
let body = Request.build_body {{{vendorExtensions.x-modelModule}}}.to_yojson {{{paramName}}} in{{/bodyParams}}
Cohttp_lwt_unix.Client.{{{httpMethod}}} uri ~headers{{#hasBodyParam}} ~body{{/hasBodyParam}}

{{/operation}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
(name {{{packageName}}})
(public_name {{{packageName}}})
(libraries cohttp-lwt-unix lwt yojson ppx_deriving_yojson.runtime)
(preprocess (pps ppx_deriving_yojson))
(preprocess (pps ppx_deriving_yojson ppx_deriving.std))
(wrapped true)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{#models}}
{{#model}}
{{#isEnum}}

{{!-- for enum schemas --}}

(** {{{description}}} *)
type {{name}} =
{{#allowableValues}}
{{#values}}
| {{camlEnumValueName}} [@printer fun fmt _ -> Format.pp_print_string fmt "{{{name}}}"] [@name "{{{name}}}"]
{{/values}}
{{/allowableValues}}
[@@deriving yojson, show { with_path = false }];;
{{/isEnum}}
{{/model}}
{{/models}}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* Schema {{{classname}}} : {{{description}}}
*)
{{/description}}
{{^description}}
*
*)
{{/description}}

{{!-- for enum schemas --}}
{{#isEnum}}
Expand All @@ -17,20 +21,6 @@ type t =

{{!-- for non-enum schemas --}}

{{!-- for properties that are of enum type --}}
{{#vars}}
{{#isEnum}}
(** {{{description}}} *)
type {{name}} =
{{#allowableValues}}
{{#enumVars}}
| {{name}}
{{/enumVars}}
{{/allowableValues}}
[@@deriving yojson];;
{{/isEnum}}
{{/vars}}

{{^isEnum}}
type t = {
{{#vars}}
Expand All @@ -39,13 +29,13 @@ type t = {
{{/description}}
{{#isEnum}}
(*{{{name}}}: [{{#allowableValues}}{{#enumVars}}`{{name}}{{^-last}} | {{/-last}}{{/enumVars}}{{/allowableValues}}]{{^isListContainer}}{{#required}}{{#isNullable}} option{{/isNullable}}{{/required}}{{/isListContainer}}{{^isListContainer}}{{^required}} option{{/required}}{{/isListContainer}};*)
{{{name}}}: {{{name}}}{{^isListContainer}}{{#required}}{{#isNullable}} option{{/isNullable}}{{/required}}{{/isListContainer}}{{^isListContainer}}{{^required}} option{{/required}}{{/isListContainer}};
{{{name}}}: Enums.{{{datatypeWithEnum}}}{{^isListContainer}}{{#required}}{{#isNullable}} option{{/isNullable}}{{/required}}{{/isListContainer}}{{^isListContainer}}{{^required}} option{{/required}}{{/isListContainer}};
{{/isEnum}}
{{^isEnum}}
{{{name}}}: {{{dataType}}}{{^isListContainer}}{{#required}}{{#isNullable}} option{{/isNullable}}{{/required}}{{/isListContainer}}{{^isListContainer}}{{^required}} option{{/required}}{{/isListContainer}};
{{/isEnum}}
{{/vars}}
} [@@deriving yojson];;
} [@@deriving yojson, show ];;

{{#description}}
(** {{{description}}} *)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{#isContainer}}{{#items}}{{#isEnum}}List.map {{> to_string}}{{/isEnum}}{{#isModel}}List.map {{> to_string}}{{/isModel}}{{/items}}{{/isContainer}}{{#isString}}{{/isString}}{{#isLong}}Int64.to_string {{/isLong}}{{#isInteger}}Int32.to_string {{/isInteger}}{{#isFloat}}string_of_float {{/isFloat}}{{#isBoolean}}string_of_bool {{/isBoolean}}{{#isModel}}{{{vendorExtensions.x-modelModule}}}.show {{/isModel}}{{^isModel}}{{^isContainer}}{{#isEnum}}Enums.show_{{{datatypeWithEnum}}} {{/isEnum}}{{/isContainer}}{{/isModel}}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.1.0-SNAPSHOT
unset
2 changes: 1 addition & 1 deletion samples/client/petstore/ocaml-client/dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
(name petstore_client)
(public_name petstore_client)
(libraries cohttp-lwt-unix lwt yojson ppx_deriving_yojson.runtime)
(preprocess (pps ppx_deriving_yojson))
(preprocess (pps ppx_deriving_yojson ppx_deriving.std))
(wrapped true)
)
10 changes: 2 additions & 8 deletions samples/client/petstore/ocaml-client/src/apis/pet_api.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,24 @@ let delete_pet pet_id api_key =
let headers = Request.default_headers in
let uri = Request.build_uri "/pet/{petId}" in
let uri = Request.replace_path_param uri "petId" (Int64.to_string pet_id) in

Cohttp_lwt_unix.Client.delete uri ~headers

let find_pets_by_status status =
let headers = Request.default_headers in
let uri = Request.build_uri "/pet/findByStatus" in
let uri = Uri.add_query_param' uri ("status", status) in

let uri = Uri.add_query_param uri ("status", List.map Enums.show_pet_status status) in
Cohttp_lwt_unix.Client.get uri ~headers

let find_pets_by_tags tags =
let headers = Request.default_headers in
let uri = Request.build_uri "/pet/findByTags" in
let uri = Uri.add_query_param' uri ("tags", tags) in

let uri = Uri.add_query_param uri ("tags", tags) in
Cohttp_lwt_unix.Client.get uri ~headers

let get_pet_by_id pet_id =
let headers = Request.default_headers in
let uri = Request.build_uri "/pet/{petId}" in
let uri = Request.replace_path_param uri "petId" (Int64.to_string pet_id) in

Cohttp_lwt_unix.Client.get uri ~headers

let update_pet body =
Expand All @@ -49,14 +45,12 @@ let update_pet_with_form pet_id name status =
let headers = Request.default_headers in
let uri = Request.build_uri "/pet/{petId}" in
let uri = Request.replace_path_param uri "petId" (Int64.to_string pet_id) in

Cohttp_lwt_unix.Client.post uri ~headers

let upload_file pet_id additional_metadata file =
let headers = Request.default_headers in
let uri = Request.build_uri "/pet/{petId}/uploadImage" in
let uri = Request.replace_path_param uri "petId" (Int64.to_string pet_id) in

Cohttp_lwt_unix.Client.post uri ~headers


Expand Down
4 changes: 1 addition & 3 deletions samples/client/petstore/ocaml-client/src/apis/store_api.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
let delete_order order_id =
let headers = Request.default_headers in
let uri = Request.build_uri "/store/order/{orderId}" in
let uri = Request.replace_path_param uri "orderId" order_id in

let uri = Request.replace_path_param uri "orderId" (order_id) in
Cohttp_lwt_unix.Client.delete uri ~headers

let get_inventory =
Expand All @@ -21,7 +20,6 @@ let get_order_by_id order_id =
let headers = Request.default_headers in
let uri = Request.build_uri "/store/order/{orderId}" in
let uri = Request.replace_path_param uri "orderId" (Int64.to_string order_id) in

Cohttp_lwt_unix.Client.get uri ~headers

let place_order body =
Expand Down
10 changes: 3 additions & 7 deletions samples/client/petstore/ocaml-client/src/apis/user_api.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,20 @@ let create_users_with_list_input body =
let delete_user username =
let headers = Request.default_headers in
let uri = Request.build_uri "/user/{username}" in
let uri = Request.replace_path_param uri "username" username in

let uri = Request.replace_path_param uri "username" (username) in
Cohttp_lwt_unix.Client.delete uri ~headers

let get_user_by_name username =
let headers = Request.default_headers in
let uri = Request.build_uri "/user/{username}" in
let uri = Request.replace_path_param uri "username" username in

let uri = Request.replace_path_param uri "username" (username) in
Cohttp_lwt_unix.Client.get uri ~headers

let login_user username password =
let headers = Request.default_headers in
let uri = Request.build_uri "/user/login" in
let uri = Uri.add_query_param' uri ("username", username) in
let uri = Uri.add_query_param' uri ("password", password) in

Cohttp_lwt_unix.Client.get uri ~headers

let logout_user =
Expand All @@ -53,8 +50,7 @@ let logout_user =
let update_user username body =
let headers = Request.default_headers in
let uri = Request.build_uri "/user/{username}" in
let uri = Request.replace_path_param uri "username" username in

let uri = Request.replace_path_param uri "username" (username) in
let body = Request.build_body User.to_yojson body in
Cohttp_lwt_unix.Client.put uri ~headers ~body

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@




type t = {
code: int32 option;
_type: string option;
message: string option;
} [@@deriving yojson];;
} [@@deriving yojson, show ];;

(** Describes the result of uploading an image resource *)
let create () : t = {
Expand Down
3 changes: 1 addition & 2 deletions samples/client/petstore/ocaml-client/src/models/category.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@




type t = {
id: int64 option;
name: string option;
} [@@deriving yojson];;
} [@@deriving yojson, show ];;

(** A category for a pet *)
let create () : t = {
Expand Down
11 changes: 2 additions & 9 deletions samples/client/petstore/ocaml-client/src/models/order.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,16 @@



(** Order Status *)
type status =
| Placed
| Approved
| Delivered
[@@deriving yojson];;

type t = {
id: int64 option;
pet_id: int64 option;
quantity: int32 option;
ship_date: string option;
(* Order Status *)
(*status: [`Placed | `Approved | `Delivered] option;*)
status: status option;
status: Enums.status option;
complete: bool option;
} [@@deriving yojson];;
} [@@deriving yojson, show ];;

(** An order for a pets from the pet store *)
let create () : t = {
Expand Down
11 changes: 2 additions & 9 deletions samples/client/petstore/ocaml-client/src/models/pet.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@



(** pet status in the store *)
type status =
| Available
| Pending
| Sold
[@@deriving yojson];;

type t = {
id: int64 option;
category: Category.t option;
Expand All @@ -23,8 +16,8 @@ type t = {
tags: Tag.t list;
(* pet status in the store *)
(*status: [`Available | `Pending | `Sold] option;*)
status: status option;
} [@@deriving yojson];;
status: Enums.pet_status option;
} [@@deriving yojson, show ];;

(** A pet for sale in the pet store *)
let create (name : string) (photo_urls : string list) : t = {
Expand Down
3 changes: 1 addition & 2 deletions samples/client/petstore/ocaml-client/src/models/tag.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@




type t = {
id: int64 option;
name: string option;
} [@@deriving yojson];;
} [@@deriving yojson, show ];;

(** A tag for a pet *)
let create () : t = {
Expand Down
3 changes: 1 addition & 2 deletions samples/client/petstore/ocaml-client/src/models/user.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@




type t = {
id: int64 option;
username: string option;
Expand All @@ -19,7 +18,7 @@ type t = {
phone: string option;
(* User Status *)
user_status: int32 option;
} [@@deriving yojson];;
} [@@deriving yojson, show ];;

(** A User who is purchasing from the pet store *)
let create () : t = {
Expand Down
16 changes: 16 additions & 0 deletions samples/client/petstore/ocaml-client/src/support/enums.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@


(** *)
type status =
| Placed [@printer fun fmt _ -> Format.pp_print_string fmt "placed"] [@name "placed"]
| Approved [@printer fun fmt _ -> Format.pp_print_string fmt "approved"] [@name "approved"]
| Delivered [@printer fun fmt _ -> Format.pp_print_string fmt "delivered"] [@name "delivered"]
[@@deriving yojson, show { with_path = false }];;


(** *)
type pet_status =
| Available [@printer fun fmt _ -> Format.pp_print_string fmt "available"] [@name "available"]
| Pending [@printer fun fmt _ -> Format.pp_print_string fmt "pending"] [@name "pending"]
| Sold [@printer fun fmt _ -> Format.pp_print_string fmt "sold"] [@name "sold"]
[@@deriving yojson, show { with_path = false }];;