Skip to content

Commit 38060f9

Browse files
committed
Fix: do not call to_json for free forms and byte arrays
Fixes #21312
1 parent 3ea004a commit 38060f9

File tree

10 files changed

+96
-111
lines changed

10 files changed

+96
-111
lines changed

modules/openapi-generator/src/main/resources/ocaml/api-impl.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ let {{{operationId}}} {{^hasParams}}(){{/hasParams}}{{#allParams}}{{> to_param}}
4343
{{/hasAuthMethods}}
4444
{{#bodyParams}}
4545
let body = Request.
46-
{{#isFreeFormObject}}write_json_body{{/isFreeFormObject}}
47-
{{#isByteArray}}write_string_body{{/isByteArray}}
48-
{{^isFreeFormObject}}{{^isByteArray}}write_as_json_body{{/isByteArray}}{{/isFreeFormObject}}
49-
{{> to_json}} {{{paramName}}} in
46+
{{#isFreeFormObject}}write_json_body {{{paramName}}}{{/isFreeFormObject}}
47+
{{#isByteArray}}write_string_body {{{paramName}}}{{/isByteArray}}
48+
{{^isFreeFormObject}}{{^isByteArray}}write_as_json_body {{> to_json}} {{{paramName}}}{{/isByteArray}}{{/isFreeFormObject}}
49+
in
5050
{{/bodyParams}}
5151
{{^hasBodyParam}}
5252
{{#hasFormParams}}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ let call_123_test_special_tags ~client_t =
1212
let body = Request.
1313

1414

15-
write_as_json_body
16-
15+
write_as_json_body
1716

1817

1918

2019

2120

2221

2322
Client.to_yojson
24-
client_t in
23+
client_t
24+
in
2525
Cohttp_lwt_unix.Client.call `PATCH uri ~headers ~body >>= fun (resp, body) ->
2626
Request.read_json_body_as (JsonSupport.unwrap Client.of_yojson) resp body
2727

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

Lines changed: 44 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ let fake_http_signature_test ~pet_t ?query_1 ?header_1 () =
3030
let body = Request.
3131

3232

33-
write_as_json_body
34-
33+
write_as_json_body
3534

3635

3736

3837

3938

4039

4140
Pet.to_yojson
42-
pet_t in
41+
pet_t
42+
in
4343
Cohttp_lwt_unix.Client.call `GET uri ~headers ~body >>= fun (resp, body) ->
4444
Request.handle_unit_response resp
4545

@@ -50,15 +50,15 @@ let fake_outer_boolean_serialize ~body () =
5050
let body = Request.
5151

5252

53-
write_as_json_body
54-
53+
write_as_json_body
5554

5655

5756

5857

5958

6059
JsonSupport.of_bool
61-
body in
60+
body
61+
in
6262
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
6363
Request.read_json_body_as (JsonSupport.to_bool) resp body
6464

@@ -69,16 +69,16 @@ let fake_outer_composite_serialize ~outer_composite_t () =
6969
let body = Request.
7070

7171

72-
write_as_json_body
73-
72+
write_as_json_body
7473

7574

7675

7776

7877

7978

8079
Outer_composite.to_yojson
81-
outer_composite_t in
80+
outer_composite_t
81+
in
8282
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
8383
Request.read_json_body_as (JsonSupport.unwrap Outer_composite.of_yojson) resp body
8484

@@ -89,15 +89,15 @@ let fake_outer_number_serialize ~body () =
8989
let body = Request.
9090

9191

92-
write_as_json_body
93-
92+
write_as_json_body
9493

9594

9695

9796
JsonSupport.of_float
9897

9998

100-
body in
99+
body
100+
in
101101
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
102102
Request.read_json_body_as (JsonSupport.to_float) resp body
103103

@@ -108,15 +108,15 @@ let fake_outer_string_serialize ~body () =
108108
let body = Request.
109109

110110

111-
write_as_json_body
112-
JsonSupport.of_string
111+
write_as_json_body JsonSupport.of_string
113112

114113

115114

116115

117116

118117

119-
body in
118+
body
119+
in
120120
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
121121
Request.read_json_body_as (JsonSupport.to_string) resp body
122122

@@ -127,16 +127,16 @@ let fake_property_enum_integer_serialize ~outer_object_with_enum_property_t =
127127
let body = Request.
128128

129129

130-
write_as_json_body
131-
130+
write_as_json_body
132131

133132

134133

135134

136135

137136

138137
Outer_object_with_enum_property.to_yojson
139-
outer_object_with_enum_property_t in
138+
outer_object_with_enum_property_t
139+
in
140140
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
141141
Request.read_json_body_as (JsonSupport.unwrap Outer_object_with_enum_property.of_yojson) resp body
142142

@@ -145,25 +145,10 @@ let test_additional_properties_reference ~request_body =
145145
let uri = Request.build_uri "/fake/additionalProperties-reference" in
146146
let headers = Request.default_headers in
147147
let body = Request.
148-
write_json_body
148+
write_json_body request_body
149149

150150

151-
(JsonSupport.of_map_of
152-
153-
154-
155-
156-
157-
158-
)
159-
160-
161-
162-
163-
164-
165-
166-
request_body in
151+
in
167152
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
168153
Request.handle_unit_response resp
169154

@@ -174,15 +159,15 @@ let test_body_with_binary ~body =
174159
let body = Request.
175160

176161

177-
write_as_json_body
178-
162+
write_as_json_body
179163

180164

181165

182166

183167

184168

185-
body in
169+
body
170+
in
186171
Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) ->
187172
Request.handle_unit_response resp
188173

@@ -193,16 +178,16 @@ let test_body_with_file_schema ~file_schema_test_class_t =
193178
let body = Request.
194179

195180

196-
write_as_json_body
197-
181+
write_as_json_body
198182

199183

200184

201185

202186

203187

204188
File_schema_test_class.to_yojson
205-
file_schema_test_class_t in
189+
file_schema_test_class_t
190+
in
206191
Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) ->
207192
Request.handle_unit_response resp
208193

@@ -215,16 +200,16 @@ let test_body_with_query_params ~query ~user_t =
215200
let body = Request.
216201

217202

218-
write_as_json_body
219-
203+
write_as_json_body
220204

221205

222206

223207

224208

225209

226210
User.to_yojson
227-
user_t in
211+
user_t
212+
in
228213
Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) ->
229214
Request.handle_unit_response resp
230215

@@ -235,16 +220,16 @@ let test_client_model ~client_t =
235220
let body = Request.
236221

237222

238-
write_as_json_body
239-
223+
write_as_json_body
240224

241225

242226

243227

244228

245229

246230
Client.to_yojson
247-
client_t in
231+
client_t
232+
in
248233
Cohttp_lwt_unix.Client.call `PATCH uri ~headers ~body >>= fun (resp, body) ->
249234
Request.read_json_body_as (JsonSupport.unwrap Client.of_yojson) resp body
250235

@@ -342,8 +327,7 @@ let test_inline_additional_properties ~request_body =
342327
let body = Request.
343328

344329

345-
write_as_json_body
346-
(JsonSupport.of_map_of JsonSupport.of_string
330+
write_as_json_body (JsonSupport.of_map_of JsonSupport.of_string
347331

348332

349333

@@ -358,7 +342,8 @@ let test_inline_additional_properties ~request_body =
358342

359343

360344

361-
request_body in
345+
request_body
346+
in
362347
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
363348
Request.handle_unit_response resp
364349

@@ -369,16 +354,16 @@ let test_inline_freeform_additional_properties ~test_inline_freeform_additional_
369354
let body = Request.
370355

371356

372-
write_as_json_body
373-
357+
write_as_json_body
374358

375359

376360

377361

378362

379363

380364
Test_inline_freeform_additional_properties_request.to_yojson
381-
test_inline_freeform_additional_properties_request_t in
365+
test_inline_freeform_additional_properties_request_t
366+
in
382367
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
383368
Request.handle_unit_response resp
384369

@@ -402,16 +387,16 @@ let test_nullable ~child_with_nullable_t =
402387
let body = Request.
403388

404389

405-
write_as_json_body
406-
390+
write_as_json_body
407391

408392

409393

410394

411395

412396

413397
Child_with_nullable.to_yojson
414-
child_with_nullable_t in
398+
child_with_nullable_t
399+
in
415400
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
416401
Request.handle_unit_response resp
417402

@@ -449,8 +434,7 @@ let test_string_map_reference ~request_body =
449434
let body = Request.
450435

451436

452-
write_as_json_body
453-
(JsonSupport.of_map_of JsonSupport.of_string
437+
write_as_json_body (JsonSupport.of_map_of JsonSupport.of_string
454438

455439

456440

@@ -465,7 +449,8 @@ let test_string_map_reference ~request_body =
465449

466450

467451

468-
request_body in
452+
request_body
453+
in
469454
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
470455
Request.handle_unit_response resp
471456

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ let test_classname ~client_t =
1313
let body = Request.
1414

1515

16-
write_as_json_body
17-
16+
write_as_json_body
1817

1918

2019

2120

2221

2322

2423
Client.to_yojson
25-
client_t in
24+
client_t
25+
in
2626
Cohttp_lwt_unix.Client.call `PATCH uri ~headers ~body >>= fun (resp, body) ->
2727
Request.read_json_body_as (JsonSupport.unwrap Client.of_yojson) resp body
2828

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ let add_pet ~pet_t =
1212
let body = Request.
1313

1414

15-
write_as_json_body
16-
15+
write_as_json_body
1716

1817

1918

2019

2120

2221

2322
Pet.to_yojson
24-
pet_t in
23+
pet_t
24+
in
2525
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
2626
Request.handle_unit_response resp
2727

@@ -73,16 +73,16 @@ let update_pet ~pet_t =
7373
let body = Request.
7474

7575

76-
write_as_json_body
77-
76+
write_as_json_body
7877

7978

8079

8180

8281

8382

8483
Pet.to_yojson
85-
pet_t in
84+
pet_t
85+
in
8686
Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) ->
8787
Request.handle_unit_response resp
8888

0 commit comments

Comments
 (0)