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
Added generated code for modules/openapi-generator/src/test/resources…
…/3_0/petstore-with-fake-endpoints-models-for-testing.yaml.
  • Loading branch information
Christophe Gensoul committed Jul 24, 2019
commit cce21521e04a3cab76614b874843b10cefdb5e95
34 changes: 34 additions & 0 deletions bin/openapi3/ocaml-client-petstore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/sh

SCRIPT="$0"
echo "# START SCRIPT: $SCRIPT"

while [ -h "$SCRIPT" ] ; do
ls=`ls -ld "$SCRIPT"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
SCRIPT="$link"
else
SCRIPT=`dirname "$SCRIPT"`/"$link"
fi
done

if [ ! -d "${APP_DIR}" ]; then
APP_DIR=`dirname "$SCRIPT"`/..
APP_DIR=`cd "${APP_DIR}"; pwd`
fi

executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"

if [ ! -f "$executable" ]
then
mvn -B clean package
fi

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DdebugOperations -DloggerPath=conf/log4j.properties"

args="generate -t modules/openapi-generator/src/main/resources/ocaml-client -i modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml -g ocaml-client -o samples/openapi3/client/petstore/ocaml-client/ --additional-properties packageName=petstore_client $@"

echo "java ${JAVA_OPTS} -jar ${executable} ${args}"
java $JAVA_OPTS -jar $executable $args
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
unset
9 changes: 9 additions & 0 deletions samples/openapi3/client/petstore/ocaml-client/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(include_subdirs unqualified)
(library
(name petstore_client)
(public_name petstore_client)
(flags (:standard -w -27))
(libraries str cohttp-lwt-unix lwt yojson ppx_deriving_yojson.runtime)
(preprocess (pps ppx_deriving_yojson ppx_deriving.std))
(wrapped true)
)
2 changes: 2 additions & 0 deletions samples/openapi3/client/petstore/ocaml-client/dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(lang dune 1.10)
(name petstore_client)
15 changes: 15 additions & 0 deletions samples/openapi3/client/petstore/ocaml-client/petstore_client.opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
opam-version: "2.0"
name: "petstore_client"
version: "1.0.0"
synopsis: ""
description: """
Longer description
"""
maintainer: "Name <email>"
authors: "Name <email>"
license: ""
homepage: ""
bug-reports: ""
dev-repo: ""
depends: [ "ocaml" "ocamlfind" ]
build: ["dune" "build" "-p" name]
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(*
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
*
* @author Christophe Gensoul
*
*)

let call_123_test_special_tags client_t =
let open Lwt in
let uri = Request.build_uri "/another-fake/dummy" in
let headers = Request.default_headers in
let body = Request.write_json_body Client.to_yojson client_t in
Cohttp_lwt_unix.Client.patch uri ~headers ~body >>= fun (_resp, body) ->
Request.read_json_body_as (JsonSupport.unwrap Client.of_yojson) body

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(*
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
*
* @author Christophe Gensoul
*
*)

val call_123_test_special_tags : Client.t -> Client.t Lwt.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(*
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
*
* @author Christophe Gensoul
*
*)

let foo_get () =
let open Lwt in
let uri = Request.build_uri "/foo" in
let headers = Request.default_headers in
Cohttp_lwt_unix.Client.get uri ~headers >>= fun (_resp, body) ->
Request.read_json_body_as (JsonSupport.unwrap Inline_response_default.of_yojson) body

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(*
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
*
* @author Christophe Gensoul
*
*)

val foo_get : unit -> Inline_response_default.t Lwt.t
136 changes: 136 additions & 0 deletions samples/openapi3/client/petstore/ocaml-client/src/apis/fake_api.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
(*
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
*
* @author Christophe Gensoul
*
*)

let fake_health_get () =
let open Lwt in
let uri = Request.build_uri "/fake/health" in
let headers = Request.default_headers in
Cohttp_lwt_unix.Client.get uri ~headers >>= fun (_resp, body) ->
Request.read_json_body_as (JsonSupport.unwrap Health_check_result.of_yojson) body

let fake_outer_boolean_serialize body =
let open Lwt in
let uri = Request.build_uri "/fake/outer/boolean" in
let headers = Request.default_headers in
let body = Request.write_json_body JsonSupport.of_bool body in
Cohttp_lwt_unix.Client.post uri ~headers ~body >>= fun (_resp, body) ->
Request.read_json_body_as (JsonSupport.to_bool) body

let fake_outer_composite_serialize outer_composite_t =
let open Lwt in
let uri = Request.build_uri "/fake/outer/composite" in
let headers = Request.default_headers in
let body = Request.write_json_body Outer_composite.to_yojson outer_composite_t in
Cohttp_lwt_unix.Client.post uri ~headers ~body >>= fun (_resp, body) ->
Request.read_json_body_as (JsonSupport.unwrap Outer_composite.of_yojson) body

let fake_outer_number_serialize body =
let open Lwt in
let uri = Request.build_uri "/fake/outer/number" in
let headers = Request.default_headers in
let body = Request.write_json_body JsonSupport.of_float body in
Cohttp_lwt_unix.Client.post uri ~headers ~body >>= fun (_resp, body) ->
Request.read_json_body_as (JsonSupport.to_float) body

let fake_outer_string_serialize body =
let open Lwt in
let uri = Request.build_uri "/fake/outer/string" in
let headers = Request.default_headers in
let body = Request.write_json_body JsonSupport.of_string body in
Cohttp_lwt_unix.Client.post uri ~headers ~body >>= fun (_resp, body) ->
Request.read_json_body_as (JsonSupport.to_string) body

let test_body_with_file_schema file_schema_test_class_t =
let open Lwt in
let uri = Request.build_uri "/fake/body-with-file-schema" in
let headers = Request.default_headers in
let body = Request.write_json_body File_schema_test_class.to_yojson file_schema_test_class_t in
Cohttp_lwt_unix.Client.put uri ~headers ~body >>= fun (_resp, body) -> return ()

let test_body_with_query_params query user_t =
let open Lwt in
let uri = Request.build_uri "/fake/body-with-query-params" in
let headers = Request.default_headers in
let uri = Uri.add_query_param' uri ("query", query) in
let body = Request.write_json_body User.to_yojson user_t in
Cohttp_lwt_unix.Client.put uri ~headers ~body >>= fun (_resp, body) -> return ()

let test_client_model client_t =
let open Lwt in
let uri = Request.build_uri "/fake" in
let headers = Request.default_headers in
let body = Request.write_json_body Client.to_yojson client_t in
Cohttp_lwt_unix.Client.patch uri ~headers ~body >>= fun (_resp, body) ->
Request.read_json_body_as (JsonSupport.unwrap Client.of_yojson) body

let test_endpoint_parameters number double pattern_without_delimiter byte integer int32 int64 float string binary date date_time password callback =
let open Lwt in
let uri = Request.build_uri "/fake" in
let headers = Request.default_headers in
let body = Request.init_form_encoded_body () in
let body = Request.add_form_encoded_body_param body ("integer", Int32.to_string integer) in
let body = Request.add_form_encoded_body_param body ("int32", Int32.to_string int32) in
let body = Request.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.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.add_form_encoded_body_param body ("string", string) in
let body = Request.add_form_encoded_body_param body ("pattern_without_delimiter", pattern_without_delimiter) in
let body = Request.add_form_encoded_body_param body ("byte", Bytes.to_string byte) in
let body = Request.add_form_encoded_body_param body ("binary", binary) in
let body = Request.add_form_encoded_body_param body ("date", date) in
let body = Request.add_form_encoded_body_param body ("date_time", date_time) in
let body = Request.add_form_encoded_body_param body ("password", password) in
let body = Request.add_form_encoded_body_param body ("callback", callback) in
let body = Request.finalize_form_encoded_body body in
Cohttp_lwt_unix.Client.post uri ~headers ~body >>= fun (_resp, body) -> return ()

let test_enum_parameters enum_header_string_array enum_header_string enum_query_string_array enum_query_string enum_query_integer enum_query_double enum_form_string_array enum_form_string =
let open Lwt in
let uri = Request.build_uri "/fake" in
let headers = Request.default_headers in
let headers = Cohttp.Header.add_multi headers "enum_header_string_array" (List.map Enums.show_inline_object_2_enum_form_string_array enum_header_string_array) in
let headers = Cohttp.Header.add headers "enum_header_string" (Enums.show_enumclass enum_header_string) in
let uri = Uri.add_query_param uri ("enum_query_string_array", List.map Enums.show_inline_object_2_enum_form_string_array enum_query_string_array) in
let uri = Uri.add_query_param' uri ("enum_query_string", Enums.show_enumclass enum_query_string) in
let uri = Uri.add_query_param' uri ("enum_query_integer", Enums.show_enum_query_integer enum_query_integer) in
let uri = Uri.add_query_param' uri ("enum_query_double", Enums.show_enum_number enum_query_double) in
let body = Request.init_form_encoded_body () in
let body = Request.add_form_encoded_body_params body ("enum_form_string_array", List.map Enums.show_inline_object_2_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.get uri ~headers ~body >>= fun (_resp, body) -> return ()

let test_group_parameters required_string_group required_boolean_group required_int64_group string_group boolean_group int64_group =
let open Lwt in
let uri = Request.build_uri "/fake" in
let headers = Request.default_headers in
let headers = Cohttp.Header.add headers "required_boolean_group" (string_of_bool required_boolean_group) in
let headers = Cohttp.Header.add headers "boolean_group" (string_of_bool boolean_group) in
let uri = Uri.add_query_param' uri ("required_string_group", Int32.to_string required_string_group) in
let uri = Uri.add_query_param' uri ("required_int64_group", Int64.to_string required_int64_group) in
let uri = Uri.add_query_param' uri ("string_group", Int32.to_string string_group) in
let uri = Uri.add_query_param' uri ("int64_group", Int64.to_string int64_group) in
Cohttp_lwt_unix.Client.delete uri ~headers >>= fun (_resp, body) -> return ()

let test_inline_additional_properties request_body =
let open Lwt in
let uri = Request.build_uri "/fake/inline-additionalProperties" in
let headers = Request.default_headers in
let body = Request.write_json_body (JsonSupport.of_map_of JsonSupport.of_string) request_body in
Cohttp_lwt_unix.Client.post uri ~headers ~body >>= fun (_resp, body) -> return ()

let test_json_form_data param param2 =
let open Lwt in
let uri = Request.build_uri "/fake/jsonFormData" in
let headers = Request.default_headers in
let body = Request.init_form_encoded_body () in
let body = Request.add_form_encoded_body_param body ("param", param) in
let body = Request.add_form_encoded_body_param body ("param2", param2) in
let body = Request.finalize_form_encoded_body body in
Cohttp_lwt_unix.Client.get uri ~headers ~body >>= fun (_resp, body) -> return ()

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(*
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
*
* @author Christophe Gensoul
*
*)

val fake_health_get : unit -> Health_check_result.t Lwt.t
val fake_outer_boolean_serialize : bool -> bool Lwt.t
val fake_outer_composite_serialize : Outer_composite.t -> Outer_composite.t Lwt.t
val fake_outer_number_serialize : float -> float Lwt.t
val fake_outer_string_serialize : string -> string Lwt.t
val test_body_with_file_schema : File_schema_test_class.t -> unit Lwt.t
val test_body_with_query_params : string -> User.t -> unit Lwt.t
val test_client_model : Client.t -> Client.t Lwt.t
val test_endpoint_parameters : float -> float -> string -> bytes -> int32 -> int32 -> int64 -> float -> string -> string -> string -> string -> string -> string -> unit Lwt.t
val test_enum_parameters : Enums.inline_object_2_enum_form_string_array list -> Enums.enumclass -> Enums.inline_object_2_enum_form_string_array list -> Enums.enumclass -> Enums.enum_query_integer -> Enums.enum_number -> Enums.inline_object_2_enum_form_string_array list -> Enums.enumclass -> unit Lwt.t
val test_group_parameters : int32 -> bool -> int64 -> int32 -> bool -> int64 -> unit Lwt.t
val test_inline_additional_properties : (string * string) list -> unit Lwt.t
val test_json_form_data : string -> string -> unit Lwt.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(*
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
*
* @author Christophe Gensoul
*
*)

let test_classname client_t =
let open Lwt in
let uri = Request.build_uri "/fake_classname_test" in
let headers = Request.default_headers in
let body = Request.write_json_body Client.to_yojson client_t in
Cohttp_lwt_unix.Client.patch uri ~headers ~body >>= fun (_resp, body) ->
Request.read_json_body_as (JsonSupport.unwrap Client.of_yojson) body

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(*
* This file has been generated by the OCamlClientCodegen generator for openapi-generator.
*
* @author Christophe Gensoul
*
*)

val test_classname : Client.t -> Client.t Lwt.t
Loading