From af9edca47bab0a3abf3f0865629f1bbbe96a597c Mon Sep 17 00:00:00 2001 From: Ming Lu Date: Wed, 12 Jun 2024 14:52:09 +0800 Subject: [PATCH 1/5] CP-49858: Fix phrasing in readme Signed-off-by: Ming Lu --- ocaml/sdk-gen/go/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ocaml/sdk-gen/go/README.md b/ocaml/sdk-gen/go/README.md index aa173a6b5d1..2cf13fee41b 100644 --- a/ocaml/sdk-gen/go/README.md +++ b/ocaml/sdk-gen/go/README.md @@ -48,12 +48,12 @@ Extract the contents of this archive. A. Navigate to the extracted `XenServer-SDK\XenServerGo\src` directory and copy the whole folder `src` into your Go project directory. -B. To use XenServer Go SDK as a local Go module, update one line into the `go.mod` file under your Go project: +B. To use the XenServer SDK for Go as a local Go module, include the following line into the `go.mod` file under your Go project: ``` replace xenapi => ./src ``` -You can then import this XenServer SDK Go module with the following command: +You can then import the XenServer SDK for Go with the following command: ``` import "xenapi" From a0d73b430c32a4c41bda52c786a52d333c17bf12 Mon Sep 17 00:00:00 2001 From: Ming Lu Date: Wed, 12 Jun 2024 16:02:07 +0800 Subject: [PATCH 2/5] CP-49858: Add licence text on top of Go source files Signed-off-by: Ming Lu --- .../sdk-gen/go/autogen/src/jsonrpc_client.go | 29 +++++++++++++++++++ ocaml/sdk-gen/go/gen_go_binding.ml | 5 +++- ocaml/sdk-gen/go/gen_go_helper.ml | 3 ++ ocaml/sdk-gen/go/gen_go_helper.mli | 2 ++ .../sdk-gen/go/templates/FileHeader.mustache | 4 ++- 5 files changed, 41 insertions(+), 2 deletions(-) diff --git a/ocaml/sdk-gen/go/autogen/src/jsonrpc_client.go b/ocaml/sdk-gen/go/autogen/src/jsonrpc_client.go index 09600a5bd68..ec61b1bb987 100644 --- a/ocaml/sdk-gen/go/autogen/src/jsonrpc_client.go +++ b/ocaml/sdk-gen/go/autogen/src/jsonrpc_client.go @@ -1,3 +1,32 @@ +/* + * Copyright (c) Cloud Software Group, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1) Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2) Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + package xenapi import ( diff --git a/ocaml/sdk-gen/go/gen_go_binding.ml b/ocaml/sdk-gen/go/gen_go_binding.ml index 0203e16966c..eb7bc73a96b 100644 --- a/ocaml/sdk-gen/go/gen_go_binding.ml +++ b/ocaml/sdk-gen/go/gen_go_binding.ml @@ -17,7 +17,7 @@ open Gen_go_helper let render_enums enums destdir = let header = render_template "FileHeader.mustache" - (`O [("modules", `Null)]) + (`O [("modules", `Null); licence]) ~newline:true () in let enums = render_template "Enum.mustache" enums () |> String.trim in @@ -36,6 +36,7 @@ let render_api_versions destdir = ; ("items", `A (List.map name ["errors"; "fmt"])) ] ) + ; licence ] in let rendered = @@ -55,6 +56,7 @@ let render_api_messages_and_errors destdir = ("api_errors", `A Json.api_errors) ; ("api_messages", `A Json.api_messages) ; ("modules", `Null) + ; licence ] in let header = render_template "FileHeader.mustache" obj ~newline:true () in @@ -83,6 +85,7 @@ let render_convert_header () = ) ] ) + ; licence ] in render_template "FileHeader.mustache" obj ~newline:true () diff --git a/ocaml/sdk-gen/go/gen_go_helper.ml b/ocaml/sdk-gen/go/gen_go_helper.ml index cefaaad854a..3e50c39189e 100644 --- a/ocaml/sdk-gen/go/gen_go_helper.ml +++ b/ocaml/sdk-gen/go/gen_go_helper.ml @@ -22,6 +22,8 @@ let templates_dir = "templates" let ( // ) = Filename.concat +let licence = ("licence", `String Licence.bsd_two_clause) + let acronyms = [ "id" @@ -479,6 +481,7 @@ module Json = struct ; ("modules", modules) ; ("messages", `A (messages_of_obj obj)) ; ("option", `A (of_options types)) + ; licence ] in let assoc_list = base_assoc_list @ get_event_session_value obj.name in diff --git a/ocaml/sdk-gen/go/gen_go_helper.mli b/ocaml/sdk-gen/go/gen_go_helper.mli index 623af766361..d7ba644bdf9 100644 --- a/ocaml/sdk-gen/go/gen_go_helper.mli +++ b/ocaml/sdk-gen/go/gen_go_helper.mli @@ -13,6 +13,8 @@ val ( // ) : string -> string -> string +val licence : string * Mustache.Json.value + val snake_to_camel : ?internal:bool -> string -> string val render_template : diff --git a/ocaml/sdk-gen/go/templates/FileHeader.mustache b/ocaml/sdk-gen/go/templates/FileHeader.mustache index a21900ec1c9..de563563d0e 100644 --- a/ocaml/sdk-gen/go/templates/FileHeader.mustache +++ b/ocaml/sdk-gen/go/templates/FileHeader.mustache @@ -1,3 +1,5 @@ +{{{licence}}} + package xenapi {{#modules}} {{#import}} @@ -8,4 +10,4 @@ import ( {{/items}} ) {{/import}} -{{/modules}} \ No newline at end of file +{{/modules}} From cebf2d27f82f6f72461431d96c7f155df7ed5d89 Mon Sep 17 00:00:00 2001 From: Ming Lu Date: Wed, 12 Jun 2024 19:55:35 +0800 Subject: [PATCH 3/5] CP-49858: Unit test: licence template variable Signed-off-by: Ming Lu --- ocaml/sdk-gen/go/test_data/file_header.go | 29 +++++++++++++++++++++++ ocaml/sdk-gen/go/test_gen_go.ml | 1 + 2 files changed, 30 insertions(+) diff --git a/ocaml/sdk-gen/go/test_data/file_header.go b/ocaml/sdk-gen/go/test_data/file_header.go index a40c01a5eb8..cd7cdeb7f7f 100644 --- a/ocaml/sdk-gen/go/test_data/file_header.go +++ b/ocaml/sdk-gen/go/test_data/file_header.go @@ -1,3 +1,32 @@ +/* + * Copyright (c) Cloud Software Group, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1) Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2) Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + package xenapi import ( diff --git a/ocaml/sdk-gen/go/test_gen_go.ml b/ocaml/sdk-gen/go/test_gen_go.ml index 4c06f17d28f..ff83521620f 100644 --- a/ocaml/sdk-gen/go/test_gen_go.ml +++ b/ocaml/sdk-gen/go/test_gen_go.ml @@ -592,6 +592,7 @@ let header : Mustache.Json.t = ) ] ) + ; ("licence", `String Licence.bsd_two_clause) ] let enums : Mustache.Json.t = From f102a4b95fd439c90e0234110fe14b65644c299d Mon Sep 17 00:00:00 2001 From: Ming Lu Date: Wed, 12 Jun 2024 19:12:07 +0800 Subject: [PATCH 4/5] CP-49858: Remove template variables 'first' and 'is_session_id' Prior to this change, the function parameter list is generated by Mustache template. As a result, a template boolean variable 'first' has to be used to determine if a leading comma is presented or not. E.g. when the 'first' is true, a parameter would be rendered as "a string', and then the next parameter with the 'first' being false would be rendered as ", b string". Putting them together would result in "a string, b string". This could work but is difficult to be understood. In this commit, it is changed to construct the whole function parameter list as a string in OCaml code and bind it to the template variable 'func_params'. Similar changes apply to the template variable 'is_session_id'. It is removed in this commit and the expected values are generated by OCaml code. Signed-off-by: Ming Lu --- ocaml/sdk-gen/go/gen_go_helper.ml | 148 ++++++++++++------ .../sdk-gen/go/templates/FileHeader.mustache | 1 - ocaml/sdk-gen/go/templates/Methods.mustache | 10 +- .../go/templates/SessionMethod.mustache | 10 +- 4 files changed, 110 insertions(+), 59 deletions(-) diff --git a/ocaml/sdk-gen/go/gen_go_helper.ml b/ocaml/sdk-gen/go/gen_go_helper.ml index 3e50c39189e..47540f55ef7 100644 --- a/ocaml/sdk-gen/go/gen_go_helper.ml +++ b/ocaml/sdk-gen/go/gen_go_helper.ml @@ -318,38 +318,6 @@ module Json = struct | [] -> failwith "Empty params group should not exist." - let of_param param = - let name_internal name = - let name = snake_to_camel ~internal:true name in - match name with "type" -> "typeKey" | "interface" -> "inter" | _ -> name - in - let suffix_of_type = suffix_of_type param.param_type in - let t, _e = string_of_ty_with_enums param.param_type in - let name = param.param_name in - [ - ("is_session_id", `Bool (name = "session_id")) - ; ("type", `String t) - ; ("name", `String name) - ; ("name_internal", `String (name_internal name)) - ; ("doc", `String param.param_doc) - ; ("func_name_suffix", `String suffix_of_type) - ] - - (* We use ',' to seprate params in Go function, we should ignore ',' before first param, - for example `func(a type1, b type2)` is wanted rather than `func(, a type1, b type2)`. - *) - let of_params = function - | head :: rest -> - let head = `O (("first", `Bool true) :: of_param head) in - let rest = - List.map - (fun item -> `O (("first", `Bool false) :: of_param item)) - rest - in - head :: rest - | [] -> - [] - let of_error e = `O [("name", `String e.err_name); ("doc", `String e.err_doc)] let of_errors = function @@ -393,10 +361,81 @@ module Json = struct else method_name ^ string_of_int (List.length params) - (* Since the param of `session *Session` isn't needed in functions of session object, - we add a special "func_params" field for session object to ignore `session *Session`.*) - let addtion_info_of_session method_name params latest = - let add_session_info method_name = + module ParamInfo = struct + type param_info = { + typ: string + ; func_param: string + ; name: string + ; name_internal: string + ; name_in_serialize_call: string + ; doc: string + ; func_name_suffix: string + } + + let to_param_info ~is_sess_func param = + let suffix_of_type = suffix_of_type param.param_type in + let t, _e = string_of_ty_with_enums param.param_type in + let name = param.param_name in + let is_session_id = name = "session_id" in + let internal_name = + let name' = snake_to_camel ~internal:true name in + match name' with + | "type" -> + "typeKey" + | "interface" -> + "inter" + | _ -> + name' + in + let func_param = + match (is_sess_func, is_session_id) with + | true, _ | false, false -> + Printf.sprintf "%s %s" internal_name t + | false, true -> + "session *Session" + in + let name_in_serialize_call = + match (is_sess_func, is_session_id) with + | false, false | true, false -> + internal_name + | true, true -> + "class.ref" + | false, true -> + "session.ref" + in + { + typ= t + ; func_param + ; name + ; name_internal= internal_name + ; name_in_serialize_call + ; doc= param.param_doc + ; func_name_suffix= suffix_of_type + } + end + + let of_param_info param_info = + let open ParamInfo in + let p = param_info in + `O + [ + ("type", `String p.typ) + ; ("name", `String p.name) + ; ("name_internal", `String p.name_internal) + ; ("name_in_serialize_call", `String p.name_in_serialize_call) + ; ("doc", `String p.doc) + ; ("func_name_suffix", `String p.func_name_suffix) + ] + + let of_param ~is_sess_func param = + ParamInfo.to_param_info ~is_sess_func param |> of_param_info + + let to_func_params params = + List.map (fun p -> p.ParamInfo.func_param) params |> String.concat ", " + + let diverse_info_of_session method_name params msg_session latest = + let is_sess_func = true in + let session_info method_name = match method_name with | "login_with_password" | "slave_local_login_with_password" -> [("session_login", `Bool true); ("session_logout", `Bool false)] @@ -405,21 +444,35 @@ module Json = struct | _ -> [("session_login", `Bool false); ("session_logout", `Bool false)] in - let name = method_name_exported method_name params latest in - ("func_params", `A (of_params params)) + (* In a session function, the session is from the instance rather than parameter list *) + let params' = if msg_session then List.tl params else params in + let name = method_name_exported method_name params' latest in + let func_params = + List.map (ParamInfo.to_param_info ~is_sess_func) params' |> to_func_params + in + ("func_params", `String func_params) + :: ("params", `A (List.map (of_param ~is_sess_func) params)) :: ("method_name_exported", `String name) - :: add_session_info method_name + :: session_info method_name - let addtion_info msg params latest = + (* This is for the variables which are diverse for different messages *) + let diverse_info msg params latest = let method_name = msg.msg_name in - match (String.lowercase_ascii msg.msg_obj_name, msg.msg_session) with - | "session", true -> - addtion_info_of_session method_name (List.tl params) latest - | "session", false -> - addtion_info_of_session method_name params latest + match String.lowercase_ascii msg.msg_obj_name with + | "session" -> + diverse_info_of_session method_name params msg.msg_session latest | _ -> + let is_sess_func = false in + let func_params = + List.map (ParamInfo.to_param_info ~is_sess_func) params + |> to_func_params + in let name = method_name_exported method_name params latest in - [("method_name_exported", `String name)] + [ + ("func_params", `String func_params) + ; ("params", `A (List.map (of_param ~is_sess_func) params)) + ; ("method_name_exported", `String name) + ] let messages_of_obj obj = let ctor_fields = ctor_fields_of_obj obj in @@ -433,14 +486,13 @@ module Json = struct ; ("class_name_exported", `String (snake_to_camel obj.name)) ; ("description", desc_of_msg msg ctor_fields) ; ("result", of_result obj msg) - ; ("params", `A (of_params params)) ; ("errors", of_errors msg.msg_errors) ; ("has_error", `Bool (msg.msg_errors <> [])) ; ("async", `Bool msg.msg_async) ; ("version", `String rel_version) ] in - `O (base_assoc_list @ addtion_info msg params latest) + `O (base_assoc_list @ diverse_info msg params latest) in msg |> group_params |> List.map of_message ) diff --git a/ocaml/sdk-gen/go/templates/FileHeader.mustache b/ocaml/sdk-gen/go/templates/FileHeader.mustache index de563563d0e..d45ecac751c 100644 --- a/ocaml/sdk-gen/go/templates/FileHeader.mustache +++ b/ocaml/sdk-gen/go/templates/FileHeader.mustache @@ -1,5 +1,4 @@ {{{licence}}} - package xenapi {{#modules}} {{#import}} diff --git a/ocaml/sdk-gen/go/templates/Methods.mustache b/ocaml/sdk-gen/go/templates/Methods.mustache index 384b6949499..3adbbb37834 100644 --- a/ocaml/sdk-gen/go/templates/Methods.mustache +++ b/ocaml/sdk-gen/go/templates/Methods.mustache @@ -8,10 +8,10 @@ {{#errors}} // {{name}} - {{doc}} {{/errors}} -func ({{name_internal}}) {{method_name_exported}}({{#params}}{{#first}}session *Session{{/first}}{{^first}}, {{name_internal}} {{type}}{{/first}}{{/params}}) ({{#result}}retval {{type}}, {{/result}}err error) { +func ({{name_internal}}) {{method_name_exported}}({{func_params}}) ({{#result}}retval {{type}}, {{/result}}err error) { method := "{{class_name}}.{{method_name}}" {{#params}} - {{name_internal}}Arg, err := serialize{{func_name_suffix}}(fmt.Sprintf("%s(%s)", method, "{{name}}"), {{#first}}session.ref{{/first}}{{^first}}{{name_internal}}{{/first}}) + {{name_internal}}Arg, err := serialize{{func_name_suffix}}(fmt.Sprintf("%s(%s)", method, "{{name}}"), {{name_in_serialize_call}}) if err != nil { return } @@ -36,10 +36,10 @@ func ({{name_internal}}) {{method_name_exported}}({{#params}}{{#first}}session * {{#errors}} // {{name}} - {{doc}} {{/errors}} -func ({{name_internal}}) Async{{method_name_exported}}({{#params}}{{#first}}session *Session{{/first}}{{^first}}, {{name_internal}} {{type}}{{/first}}{{/params}}) (retval TaskRef, err error) { +func ({{name_internal}}) Async{{method_name_exported}}({{func_params}}) (retval TaskRef, err error) { method := "Async.{{class_name}}.{{method_name}}" {{#params}} - {{name_internal}}Arg, err := serialize{{func_name_suffix}}(fmt.Sprintf("%s(%s)", method, "{{name}}"), {{#first}}session.ref{{/first}}{{^first}}{{name_internal}}{{/first}}) + {{name_internal}}Arg, err := serialize{{func_name_suffix}}(fmt.Sprintf("%s(%s)", method, "{{name}}"), {{name_in_serialize_call}}) if err != nil { return } @@ -53,4 +53,4 @@ func ({{name_internal}}) Async{{method_name_exported}}({{#params}}{{#first}}sess } {{/async}} -{{/messages}} \ No newline at end of file +{{/messages}} diff --git a/ocaml/sdk-gen/go/templates/SessionMethod.mustache b/ocaml/sdk-gen/go/templates/SessionMethod.mustache index 7613c69e75f..a186ec3ffcf 100644 --- a/ocaml/sdk-gen/go/templates/SessionMethod.mustache +++ b/ocaml/sdk-gen/go/templates/SessionMethod.mustache @@ -8,10 +8,10 @@ {{#errors}} // {{name}} - {{doc}} {{/errors}} -func (class *Session) {{method_name_exported}}({{#func_params}}{{^first}}, {{/first}}{{name_internal}} {{type}}{{/func_params}}) ({{#result}}retval {{type}}, {{/result}}err error) { +func (class *Session) {{method_name_exported}}({{func_params}}) ({{#result}}retval {{type}}, {{/result}}err error) { method := "{{class_name}}.{{method_name}}" {{#params}} - {{name_internal}}Arg, err := serialize{{func_name_suffix}}(fmt.Sprintf("%s(%s)", method, "{{name}}"), {{#is_session_id}}class.ref{{/is_session_id}}{{^is_session_id}}{{name_internal}}{{/is_session_id}}) + {{name_internal}}Arg, err := serialize{{func_name_suffix}}(fmt.Sprintf("%s(%s)", method, "{{name}}"), {{name_in_serialize_call}}) if err != nil { return } @@ -46,10 +46,10 @@ func (class *Session) {{method_name_exported}}({{#func_params}}{{^first}}, {{/fi {{#errors}} // {{name}} - {{doc}} {{/errors}} -func (class *Session) Async{{method_name_exported}}({{#func_params}}{{^first}}, {{/first}}{{name_internal}} {{type}}{{/func_params}}) (retval TaskRef, err error) { +func (class *Session) Async{{method_name_exported}}({{func_params}}) (retval TaskRef, err error) { method := "Async.{{class_name}}.{{method_name}}" {{#params}} - {{name_internal}}Arg, err := serialize{{func_name_suffix}}(fmt.Sprintf("%s(%s)", method, "{{name}}"), {{#is_session_id}}class.ref{{/is_session_id}}{{^is_session_id}}{{name_internal}}{{/is_session_id}}) + {{name_internal}}Arg, err := serialize{{func_name_suffix}}(fmt.Sprintf("%s(%s)", method, "{{name}}"), {{name_in_serialize_call}}) if err != nil { return } @@ -63,4 +63,4 @@ func (class *Session) Async{{method_name_exported}}({{#func_params}}{{^first}}, } {{/async}} -{{/messages}} \ No newline at end of file +{{/messages}} From deb15d6daa08936be2ecfbb8fc2f3987da47efac Mon Sep 17 00:00:00 2001 From: Ming Lu Date: Wed, 12 Jun 2024 20:26:43 +0800 Subject: [PATCH 5/5] CP-49858: Unit test: Update for changes on template variables Signed-off-by: Ming Lu --- ocaml/sdk-gen/go/test_gen_go.ml | 65 ++++++++++++--------------------- 1 file changed, 24 insertions(+), 41 deletions(-) diff --git a/ocaml/sdk-gen/go/test_gen_go.ml b/ocaml/sdk-gen/go/test_gen_go.ml index ff83521620f..8683099ff2c 100644 --- a/ocaml/sdk-gen/go/test_gen_go.ml +++ b/ocaml/sdk-gen/go/test_gen_go.ml @@ -98,21 +98,19 @@ let verify_error = function let param_keys = [ - "is_session_id" - ; "type" + "type" ; "name" ; "name_internal" + ; "name_in_serialize_call" ; "doc" ; "func_name_suffix" - ; "first" ] let verify_param_member = function - | "is_session_id", `Bool _ - | "first", `Bool _ | "type", `String _ | "name", `String _ | "name_internal", `String _ + | "name_in_serialize_call", `String _ | "doc", `String _ | "func_name_suffix", `String _ -> true @@ -140,6 +138,8 @@ let verify_message_member = function schema_check result_keys verify_result_member result | "params", `A params -> List.for_all verify_param params + | "func_params", `String _ -> + true | "errors", `A errors -> List.for_all verify_error errors | "async", `Bool _ | "has_error", `Bool _ | "errors", `Null -> @@ -147,7 +147,7 @@ let verify_message_member = function | _ -> false -let verify_sesseion_message_member = function +let verify_session_message_member = function | "method_name", `String _ | "class_name", `String _ | "class_name_exported", `String _ @@ -162,8 +162,8 @@ let verify_sesseion_message_member = function schema_check result_keys verify_result_member result | "params", `A params -> List.for_all verify_param params - | "func_params", `A params -> - List.for_all verify_param params + | "func_params", `String _ -> + true | "errors", `A errors -> List.for_all verify_error errors | "async", `Bool _ @@ -184,14 +184,14 @@ let message_keys = ; "description" ; "result" ; "params" + ; "func_params" ; "errors" ; "has_error" ; "async" ; "version" ] -let session_message_keys = - ["session_login"; "session_logout"; "func_params"] @ message_keys +let session_message_keys = ["session_login"; "session_logout"] @ message_keys let verify_message = function | `O members -> @@ -201,7 +201,7 @@ let verify_message = function if class_name <> `String "session" then schema_check message_keys verify_message_member members else - schema_check session_message_keys verify_sesseion_message_member members + schema_check session_message_keys verify_session_message_member members | _ -> false @@ -302,6 +302,8 @@ let verify_obj_member = function true | "modules", `O members -> schema_check modules_keys verify_modules_member members + | "licence", `String _ -> + true | _ -> false @@ -316,6 +318,7 @@ let obj_keys = ; "event" ; "session" ; "option" + ; "licence" ] let verify_obj = function @@ -834,28 +837,7 @@ let session_messages : Mustache.Json.t = ) ; ("async", `Bool false) ; ("version", `String "miami") - ; ( "func_params" - , `A - [ - `O - [ - ("type", `String "string") - ; ("name", `String "uname") - ; ("name_internal", `String "uname") - ; ("func_name_suffix", `String "String") - ; ("first", `Bool true) - ; ("is_session_id", `Bool false) - ] - ; `O - [ - ("type", `String "string") - ; ("name", `String "pwd") - ; ("name_internal", `String "pwd") - ; ("func_name_suffix", `String "String") - ; ("is_session_id", `Bool false) - ] - ] - ) + ; ("func_params", `String "uname string, pwd string") ; ( "params" , `A [ @@ -864,17 +846,16 @@ let session_messages : Mustache.Json.t = ("type", `String "string") ; ("name", `String "uname") ; ("name_internal", `String "uname") + ; ("name_in_serialize_call", `String "uname") ; ("func_name_suffix", `String "String") - ; ("first", `Bool true) - ; ("is_session_id", `Bool false) ] ; `O [ ("type", `String "string") ; ("name", `String "pwd") ; ("name_internal", `String "pwd") + ; ("name_in_serialize_call", `String "pwd") ; ("func_name_suffix", `String "String") - ; ("is_session_id", `Bool false) ] ] ) @@ -910,7 +891,7 @@ let session_messages : Mustache.Json.t = ; ("method_name_exported", `String "Logout") ; ("description", `String "Logout Log out of a session") ; ("async", `Bool false) - ; ("func_params", `A []) + ; ("func_params", `String "") ; ("version", `String "miami") ; ( "params" , `A @@ -920,8 +901,8 @@ let session_messages : Mustache.Json.t = ("type", `String "SessionRef") ; ("name", `String "session_id") ; ("name_internal", `String "sessionID") + ; ("name_in_serialize_call", `String "class.ref") ; ("func_name_suffix", `String "SessionRef") - ; ("is_session_id", `Bool true) ] ] ) @@ -948,6 +929,7 @@ let messages : Mustache.Json.t = ; ("description", `String "GetLog Get the host log file") ; ("async", `Bool true) ; ("version", `String "miami") + ; ("func_params", `String "session *Session, host HostRef") ; ( "params" , `A [ @@ -956,18 +938,18 @@ let messages : Mustache.Json.t = ("type", `String "SessionRef") ; ("name", `String "session_id") ; ("name_internal", `String "sessionID") + ; ("name_in_serialize_call", `String "session.ref") ; ("func_name_suffix", `String "SessionRef") ; ("session", `Bool true) ; ("session_class", `Bool false) - ; ("first", `Bool true) ] ; `O [ ("type", `String "HostRef") ; ("name", `String "host") ; ("name_internal", `String "host") + ; ("name_in_serialize_call", `String "host") ; ("func_name_suffix", `String "HostRef") - ; ("first", `Bool false) ] ] ) @@ -1116,7 +1098,8 @@ module TemplatesTest = Generic.MakeStateless (struct end) module TestGeneratedJson = struct - let verify description verify_func actual = + let verify name verify_func actual = + let description = Printf.sprintf "Object name: %s" name in Alcotest.(check bool) description true (verify_func actual) let test_enums () =