You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[OCaml] Introduce support for oneOf/anyOf, fix default value for non-required maps (OpenAPITools#21798)
* Add OCaml fake-petstore to test corner cases
* Prefix List functions with Stdlib as the fake petstore generates a List module
* Handle decimal and any types
* Indent to_json.mustache for easier maintenance
* Indent api-impl.mustache a bit more for readability before fix
* Fix: do not call `to_json` for free forms and byte arrays
FixesOpenAPITools#21312
* Fix compilation for binary types
The implementation may not be correct, but at least it compiles. To be checked
if someday someone actually uses it/complains.
* Indent to_string.mustache
* Add support for exploded form-style object query params
FixesOpenAPITools#21307
* Add ocaml-fake-petstore to CI
* Fix free-form body params
* Cohttp_lwt.Response is deprecated, use Cohttp.Response instead
* Safe Java code cleanup
* Split into model-record.mustache
* Add some support for oneOf/anyOf
* Re-generate all OCaml samples
* Fix: correctly mark non-required maps with default empty list
* Fix: Correctly encode/decode maps
* Refresh documentation
* Refresh after merging master
Copy file name to clipboardExpand all lines: modules/openapi-generator/src/main/resources/ocaml/api-impl.mustache
+5-2Lines changed: 5 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -30,7 +30,7 @@ let {{{operationId}}} {{^hasParams}}(){{/hasParams}}{{#allParams}}{{> to_param}}
30
30
let uri = Request.{{> to_optional_prefix}}replace_path_param uri "{{{baseName}}}" {{> to_string}} {{{paramName}}} in
31
31
{{/pathParams}}
32
32
{{#queryParams}}
33
-
let uri = Request.{{> to_optional_prefix}}add_query_param{{#isArray}}_list{{/isArray}} uri "{{{baseName}}}" {{> to_string}} {{{paramName}}} in
33
+
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
34
34
{{/queryParams}}
35
35
{{#hasAuthMethods}}
36
36
{{#authMethods}}
@@ -42,7 +42,10 @@ let {{{operationId}}} {{^hasParams}}(){{/hasParams}}{{#allParams}}{{> to_param}}
42
42
{{/authMethods}}
43
43
{{/hasAuthMethods}}
44
44
{{#bodyParams}}
45
-
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
| {{{nameInPascalCase}}} v -> [%to_yojson: {{{ datatypeWithEnum }}}] v
10
+
{{/composedSchemas.oneOf}}
11
+
12
+
(* Manual implementations because the derived one encodes into a tuple list where the first element is the constructor name. *)
13
+
14
+
let of_yojson json =
15
+
[
16
+
{{#composedSchemas.oneOf}}
17
+
[%of_yojson: {{{ datatypeWithEnum }}}] json
18
+
|> Stdlib.Result.to_option
19
+
|> Stdlib.Option.map (fun v -> {{{nameInPascalCase}}} v);
20
+
{{/composedSchemas.oneOf}}
21
+
]
22
+
|> Stdlib.List.filter_map (Fun.id)
23
+
|> function
24
+
| [t] -> Ok t
25
+
| [] -> Error ("Failed to parse JSON " ^ Yojson.Safe.show json ^ " into a value of type {{{ classname }}}")
26
+
| ts -> let parsed_ts = ts
27
+
|> Stdlib.List.map show
28
+
|> Stdlib.String.concat " | "
29
+
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 ^ "]")
0 commit comments