Skip to content

Commit 675ba32

Browse files
committed
Indent to_json.mustache for easier maintenance
1 parent a5f098a commit 675ba32

File tree

7 files changed

+283
-25
lines changed

7 files changed

+283
-25
lines changed
Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,34 @@
1-
{{#isArray}}{{#items}}(JsonSupport.of_list_of {{> to_json}}){{/items}}{{/isArray}}{{#isMap}}{{#items}}(JsonSupport.of_map_of {{> to_json}}){{/items}}{{/isMap}}{{#isString}}JsonSupport.of_string{{/isString}}{{#isLong}}JsonSupport.of_int64{{/isLong}}{{#isInteger}}JsonSupport.of_int32{{/isInteger}}{{#isFloat}}JsonSupport.of_float{{/isFloat}}{{#isNumber}}JsonSupport.of_float{{/isNumber}}{{#isDouble}}JsonSupport.of_float{{/isDouble}}{{#isBoolean}}JsonSupport.of_bool{{/isBoolean}}{{^isEnum}}{{#isModel}}{{#vendorExtensions.x-model-module}}{{{vendorExtensions.x-model-module}}}.to_yojson{{/vendorExtensions.x-model-module}}{{^vendorExtensions.x-model-module}}{{{baseType}}}.to_yojson{{/vendorExtensions.x-model-module}}{{/isModel}}{{/isEnum}}{{^isModel}}{{^isContainer}}{{#isEnum}}Enums.{{{datatypeWithEnum}}}_to_yojson{{/isEnum}}{{/isContainer}}{{/isModel}}
1+
{{#isArray}}
2+
{{#items}}
3+
(JsonSupport.of_list_of {{> to_json}})
4+
{{/items}}
5+
{{/isArray}}
6+
{{#isMap}}
7+
{{#items}}
8+
(JsonSupport.of_map_of {{> to_json}})
9+
{{/items}}
10+
{{/isMap}}
11+
{{#isString}}JsonSupport.of_string{{/isString}}
12+
{{#isLong}}JsonSupport.of_int64{{/isLong}}
13+
{{#isInteger}}JsonSupport.of_int32{{/isInteger}}
14+
{{#isFloat}}JsonSupport.of_float{{/isFloat}}
15+
{{#isNumber}}JsonSupport.of_float{{/isNumber}}
16+
{{#isDouble}}JsonSupport.of_float{{/isDouble}}
17+
{{#isBoolean}}JsonSupport.of_bool{{/isBoolean}}
18+
{{^isEnum}}
19+
{{#isModel}}
20+
{{#vendorExtensions.x-model-module}}
21+
{{{vendorExtensions.x-model-module}}}.to_yojson
22+
{{/vendorExtensions.x-model-module}}
23+
{{^vendorExtensions.x-model-module}}
24+
{{{baseType}}}.to_yojson
25+
{{/vendorExtensions.x-model-module}}
26+
{{/isModel}}
27+
{{/isEnum}}
28+
{{^isModel}}
29+
{{^isContainer}}
30+
{{#isEnum}}
31+
Enums.{{{datatypeWithEnum}}}_to_yojson
32+
{{/isEnum}}
33+
{{/isContainer}}
34+
{{/isModel}}

samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.ml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@ let call_123_test_special_tags ~client_t =
99
let open Lwt.Infix in
1010
let uri = Request.build_uri "/another-fake/dummy" in
1111
let headers = Request.default_headers in
12-
let body = Request.write_as_json_body Client.to_yojson client_t in
12+
let body = Request.write_as_json_body
13+
14+
15+
16+
17+
18+
19+
Client.to_yojson
20+
client_t in
1321
Cohttp_lwt_unix.Client.call `PATCH uri ~headers ~body >>= fun (resp, body) ->
1422
Request.read_json_body_as (JsonSupport.unwrap Client.of_yojson) resp body
1523

samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml

Lines changed: 152 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,71 +27,146 @@ let fake_http_signature_test ~pet_t ?query_1 ?header_1 () =
2727
header_1 in
2828
let uri = Request.maybe_add_query_param uri "query_1" (fun x -> x)
2929
query_1 in
30-
let body = Request.write_as_json_body Pet.to_yojson pet_t in
30+
let body = Request.write_as_json_body
31+
32+
33+
34+
35+
36+
37+
Pet.to_yojson
38+
pet_t in
3139
Cohttp_lwt_unix.Client.call `GET uri ~headers ~body >>= fun (resp, body) ->
3240
Request.handle_unit_response resp
3341

3442
let fake_outer_boolean_serialize ~body () =
3543
let open Lwt.Infix in
3644
let uri = Request.build_uri "/fake/outer/boolean" in
3745
let headers = Request.default_headers in
38-
let body = Request.write_as_json_body JsonSupport.of_bool body in
46+
let body = Request.write_as_json_body
47+
48+
49+
50+
51+
52+
JsonSupport.of_bool
53+
body in
3954
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
4055
Request.read_json_body_as (JsonSupport.to_bool) resp body
4156

4257
let fake_outer_composite_serialize ~outer_composite_t () =
4358
let open Lwt.Infix in
4459
let uri = Request.build_uri "/fake/outer/composite" in
4560
let headers = Request.default_headers in
46-
let body = Request.write_as_json_body Outer_composite.to_yojson outer_composite_t in
61+
let body = Request.write_as_json_body
62+
63+
64+
65+
66+
67+
68+
Outer_composite.to_yojson
69+
outer_composite_t in
4770
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
4871
Request.read_json_body_as (JsonSupport.unwrap Outer_composite.of_yojson) resp body
4972

5073
let fake_outer_number_serialize ~body () =
5174
let open Lwt.Infix in
5275
let uri = Request.build_uri "/fake/outer/number" in
5376
let headers = Request.default_headers in
54-
let body = Request.write_as_json_body JsonSupport.of_float body in
77+
let body = Request.write_as_json_body
78+
79+
80+
81+
JsonSupport.of_float
82+
83+
84+
body in
5585
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
5686
Request.read_json_body_as (JsonSupport.to_float) resp body
5787

5888
let fake_outer_string_serialize ~body () =
5989
let open Lwt.Infix in
6090
let uri = Request.build_uri "/fake/outer/string" in
6191
let headers = Request.default_headers in
62-
let body = Request.write_as_json_body JsonSupport.of_string body in
92+
let body = Request.write_as_json_body JsonSupport.of_string
93+
94+
95+
96+
97+
98+
99+
body in
63100
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
64101
Request.read_json_body_as (JsonSupport.to_string) resp body
65102

66103
let fake_property_enum_integer_serialize ~outer_object_with_enum_property_t =
67104
let open Lwt.Infix in
68105
let uri = Request.build_uri "/fake/property/enum-int" in
69106
let headers = Request.default_headers in
70-
let body = Request.write_as_json_body Outer_object_with_enum_property.to_yojson outer_object_with_enum_property_t in
107+
let body = Request.write_as_json_body
108+
109+
110+
111+
112+
113+
114+
Outer_object_with_enum_property.to_yojson
115+
outer_object_with_enum_property_t in
71116
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
72117
Request.read_json_body_as (JsonSupport.unwrap Outer_object_with_enum_property.of_yojson) resp body
73118

74119
let test_additional_properties_reference ~request_body =
75120
let open Lwt.Infix in
76121
let uri = Request.build_uri "/fake/additionalProperties-reference" in
77122
let headers = Request.default_headers in
78-
let body = Request.write_json_body (JsonSupport.of_map_of ) request_body in
123+
let body = Request.write_json_body (JsonSupport.of_map_of
124+
125+
126+
127+
128+
129+
130+
)
131+
132+
133+
134+
135+
136+
137+
138+
request_body in
79139
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
80140
Request.handle_unit_response resp
81141

82142
let test_body_with_binary ~body =
83143
let open Lwt.Infix in
84144
let uri = Request.build_uri "/fake/body-with-binary" in
85145
let headers = Request.default_headers in
86-
let body = Request.write_as_json_body body in
146+
let body = Request.write_as_json_body
147+
148+
149+
150+
151+
152+
153+
body in
87154
Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) ->
88155
Request.handle_unit_response resp
89156

90157
let test_body_with_file_schema ~file_schema_test_class_t =
91158
let open Lwt.Infix in
92159
let uri = Request.build_uri "/fake/body-with-file-schema" in
93160
let headers = Request.default_headers in
94-
let body = Request.write_as_json_body File_schema_test_class.to_yojson file_schema_test_class_t in
161+
let body = Request.write_as_json_body
162+
163+
164+
165+
166+
167+
168+
File_schema_test_class.to_yojson
169+
file_schema_test_class_t in
95170
Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) ->
96171
Request.handle_unit_response resp
97172

@@ -101,15 +176,31 @@ let test_body_with_query_params ~query ~user_t =
101176
let headers = Request.default_headers in
102177
let uri = Request.add_query_param uri "query" (fun x -> x)
103178
query in
104-
let body = Request.write_as_json_body User.to_yojson user_t in
179+
let body = Request.write_as_json_body
180+
181+
182+
183+
184+
185+
186+
User.to_yojson
187+
user_t in
105188
Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) ->
106189
Request.handle_unit_response resp
107190

108191
let test_client_model ~client_t =
109192
let open Lwt.Infix in
110193
let uri = Request.build_uri "/fake" in
111194
let headers = Request.default_headers in
112-
let body = Request.write_as_json_body Client.to_yojson client_t in
195+
let body = Request.write_as_json_body
196+
197+
198+
199+
200+
201+
202+
Client.to_yojson
203+
client_t in
113204
Cohttp_lwt_unix.Client.call `PATCH uri ~headers ~body >>= fun (resp, body) ->
114205
Request.read_json_body_as (JsonSupport.unwrap Client.of_yojson) resp body
115206

@@ -204,15 +295,38 @@ let test_inline_additional_properties ~request_body =
204295
let open Lwt.Infix in
205296
let uri = Request.build_uri "/fake/inline-additionalProperties" in
206297
let headers = Request.default_headers in
207-
let body = Request.write_as_json_body (JsonSupport.of_map_of JsonSupport.of_string) request_body in
298+
let body = Request.write_as_json_body (JsonSupport.of_map_of JsonSupport.of_string
299+
300+
301+
302+
303+
304+
305+
)
306+
307+
308+
309+
310+
311+
312+
313+
request_body in
208314
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
209315
Request.handle_unit_response resp
210316

211317
let test_inline_freeform_additional_properties ~test_inline_freeform_additional_properties_request_t =
212318
let open Lwt.Infix in
213319
let uri = Request.build_uri "/fake/inline-freeform-additionalProperties" in
214320
let headers = Request.default_headers in
215-
let body = Request.write_as_json_body Test_inline_freeform_additional_properties_request.to_yojson test_inline_freeform_additional_properties_request_t in
321+
let body = Request.write_as_json_body
322+
323+
324+
325+
326+
327+
328+
Test_inline_freeform_additional_properties_request.to_yojson
329+
test_inline_freeform_additional_properties_request_t in
216330
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
217331
Request.handle_unit_response resp
218332

@@ -233,7 +347,15 @@ let test_nullable ~child_with_nullable_t =
233347
let open Lwt.Infix in
234348
let uri = Request.build_uri "/fake/nullable" in
235349
let headers = Request.default_headers in
236-
let body = Request.write_as_json_body Child_with_nullable.to_yojson child_with_nullable_t in
350+
let body = Request.write_as_json_body
351+
352+
353+
354+
355+
356+
357+
Child_with_nullable.to_yojson
358+
child_with_nullable_t in
237359
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
238360
Request.handle_unit_response resp
239361

@@ -268,7 +390,22 @@ let test_string_map_reference ~request_body =
268390
let open Lwt.Infix in
269391
let uri = Request.build_uri "/fake/stringMap-reference" in
270392
let headers = Request.default_headers in
271-
let body = Request.write_as_json_body (JsonSupport.of_map_of JsonSupport.of_string) request_body in
393+
let body = Request.write_as_json_body (JsonSupport.of_map_of JsonSupport.of_string
394+
395+
396+
397+
398+
399+
400+
)
401+
402+
403+
404+
405+
406+
407+
408+
request_body in
272409
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
273410
Request.handle_unit_response resp
274411

samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.ml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@ let test_classname ~client_t =
1010
let uri = Request.build_uri "/fake_classname_test" in
1111
let headers = Request.default_headers in
1212
let uri = Uri.add_query_param' uri ("api_key_query", Request.api_key) in
13-
let body = Request.write_as_json_body Client.to_yojson client_t in
13+
let body = Request.write_as_json_body
14+
15+
16+
17+
18+
19+
20+
Client.to_yojson
21+
client_t in
1422
Cohttp_lwt_unix.Client.call `PATCH uri ~headers ~body >>= fun (resp, body) ->
1523
Request.read_json_body_as (JsonSupport.unwrap Client.of_yojson) resp body
1624

samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@ let add_pet ~pet_t =
99
let open Lwt.Infix in
1010
let uri = Request.build_uri "/pet" in
1111
let headers = Request.default_headers in
12-
let body = Request.write_as_json_body Pet.to_yojson pet_t in
12+
let body = Request.write_as_json_body
13+
14+
15+
16+
17+
18+
19+
Pet.to_yojson
20+
pet_t in
1321
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
1422
Request.handle_unit_response resp
1523

@@ -58,7 +66,15 @@ let update_pet ~pet_t =
5866
let open Lwt.Infix in
5967
let uri = Request.build_uri "/pet" in
6068
let headers = Request.default_headers in
61-
let body = Request.write_as_json_body Pet.to_yojson pet_t in
69+
let body = Request.write_as_json_body
70+
71+
72+
73+
74+
75+
76+
Pet.to_yojson
77+
pet_t in
6278
Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) ->
6379
Request.handle_unit_response resp
6480

samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,15 @@ let place_order ~order_t =
3535
let open Lwt.Infix in
3636
let uri = Request.build_uri "/store/order" in
3737
let headers = Request.default_headers in
38-
let body = Request.write_as_json_body Order.to_yojson order_t in
38+
let body = Request.write_as_json_body
39+
40+
41+
42+
43+
44+
45+
Order.to_yojson
46+
order_t in
3947
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
4048
Request.read_json_body_as (JsonSupport.unwrap Order.of_yojson) resp body
4149

0 commit comments

Comments
 (0)