Skip to content

Commit 74c8e30

Browse files
committed
Add support for exploded form-style object query params
Fixes #21307
1 parent 2bc64f7 commit 74c8e30

File tree

12 files changed

+129
-5
lines changed

12 files changed

+129
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ let {{{operationId}}} {{^hasParams}}(){{/hasParams}}{{#allParams}}{{> to_param}}
3030
let uri = Request.{{> to_optional_prefix}}replace_path_param uri "{{{baseName}}}" {{> to_string}} {{{paramName}}} in
3131
{{/pathParams}}
3232
{{#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
3434
{{/queryParams}}
3535
{{#hasAuthMethods}}
3636
{{#authMethods}}

modules/openapi-generator/src/main/resources/ocaml/support.mustache

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,19 @@ let add_query_param_list uri param_name to_string param_value =
8080
let maybe_add_query_param uri param_name to_string param_value =
8181
option_fold (add_query_param uri param_name to_string) uri param_value
8282

83+
(** Corresponds to:
84+
- [style = form]
85+
- [explode = true]
86+
- type [object]
87+
88+
See https://swagger.io/docs/specification/v3_0/serialization/#query-parameters
89+
*)
90+
let add_query_param_exploded_form_object uri _param_name to_string param_value =
91+
Stdlib.List.fold_left
92+
(fun uri (param_name, param_value) -> add_query_param uri param_name to_string param_value)
93+
uri
94+
param_value
95+
8396
let init_form_encoded_body () = ""
8497

8598
let add_form_encoded_body_param params param_name to_string param_value =

modules/openapi-generator/src/main/resources/ocaml/to_string.mustache

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
{{#isContainer}}
1+
{{#isArray}}
22
{{#items}}(Stdlib.List.map {{> to_string}}){{/items}}
3-
{{/isContainer}}
3+
{{/isArray}}
4+
{{#isMap}}{{! For maps, only transform the value, the call site will take care of properly transforming the key-value pairs since it depends on the context. }}
5+
{{#items}}{{> to_string}}{{/items}}
6+
{{/isMap}}
47
{{^isEnum}}
58
{{#isLong}}Int64.to_string{{/isLong}}
69
{{#isInteger}}Int32.to_string{{/isInteger}}
@@ -18,5 +21,6 @@
1821
{{^isModel}}
1922
{{^isContainer}}
2023
{{#isEnum}}Enums.show_{{{datatypeWithEnum}}}{{/isEnum}}
24+
{{#isEnumRef}}(failwith "Unsupported: enum reference"){{/isEnumRef}}
2125
{{/isContainer}}
2226
{{/isModel}}

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

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ let fake_http_signature_test ~pet_t ?query_1 ?header_1 () =
3636

3737

3838

39+
3940
header_1 in
4041
let uri = Request.maybe_add_query_param uri "query_1"
4142

@@ -50,6 +51,7 @@ let fake_http_signature_test ~pet_t ?query_1 ?header_1 () =
5051

5152

5253

54+
5355
query_1 in
5456
let body = Request.
5557

@@ -240,6 +242,7 @@ let test_body_with_query_params ~query ~user_t =
240242

241243

242244

245+
243246
query in
244247
let body = Request.
245248

@@ -297,6 +300,7 @@ let test_endpoint_parameters ~number ~double ~pattern_without_delimiter ~byte ?i
297300

298301

299302

303+
300304
integer in
301305
let body = Request.maybe_add_form_encoded_body_param body "int32"
302306
Int32.to_string
@@ -311,6 +315,7 @@ let test_endpoint_parameters ~number ~double ~pattern_without_delimiter ~byte ?i
311315

312316

313317

318+
314319
int32 in
315320
let body = Request.maybe_add_form_encoded_body_param body "int64" Int64.to_string
316321

@@ -325,6 +330,7 @@ let test_endpoint_parameters ~number ~double ~pattern_without_delimiter ~byte ?i
325330

326331

327332

333+
328334
int64 in
329335
let body = Request.add_form_encoded_body_param body "number"
330336

@@ -339,6 +345,7 @@ let test_endpoint_parameters ~number ~double ~pattern_without_delimiter ~byte ?i
339345

340346

341347

348+
342349
number in
343350
let body = Request.maybe_add_form_encoded_body_param body "float"
344351

@@ -353,6 +360,7 @@ let test_endpoint_parameters ~number ~double ~pattern_without_delimiter ~byte ?i
353360

354361

355362

363+
356364
float in
357365
let body = Request.add_form_encoded_body_param body "double"
358366

@@ -367,6 +375,7 @@ let test_endpoint_parameters ~number ~double ~pattern_without_delimiter ~byte ?i
367375

368376

369377

378+
370379
double in
371380
let body = Request.maybe_add_form_encoded_body_param body "string"
372381

@@ -381,6 +390,7 @@ let test_endpoint_parameters ~number ~double ~pattern_without_delimiter ~byte ?i
381390

382391

383392

393+
384394
string in
385395
let body = Request.add_form_encoded_body_param body "pattern_without_delimiter"
386396

@@ -395,6 +405,7 @@ let test_endpoint_parameters ~number ~double ~pattern_without_delimiter ~byte ?i
395405

396406

397407

408+
398409
pattern_without_delimiter in
399410
let body = Request.add_form_encoded_body_param body "byte"
400411

@@ -409,6 +420,7 @@ let test_endpoint_parameters ~number ~double ~pattern_without_delimiter ~byte ?i
409420
(fun x -> x)
410421

411422

423+
412424
byte in
413425
let body = Request.maybe_add_form_encoded_body_param body "binary"
414426

@@ -423,6 +435,7 @@ let test_endpoint_parameters ~number ~double ~pattern_without_delimiter ~byte ?i
423435

424436

425437

438+
426439
binary in
427440
let body = Request.maybe_add_form_encoded_body_param body "date"
428441

@@ -437,6 +450,7 @@ let test_endpoint_parameters ~number ~double ~pattern_without_delimiter ~byte ?i
437450

438451

439452

453+
440454
date in
441455
let body = Request.maybe_add_form_encoded_body_param body "date_time"
442456

@@ -451,6 +465,7 @@ let test_endpoint_parameters ~number ~double ~pattern_without_delimiter ~byte ?i
451465

452466

453467

468+
454469
date_time in
455470
let body = Request.maybe_add_form_encoded_body_param body "password"
456471

@@ -465,6 +480,7 @@ let test_endpoint_parameters ~number ~double ~pattern_without_delimiter ~byte ?i
465480

466481

467482

483+
468484
password in
469485
let body = Request.maybe_add_form_encoded_body_param body "callback"
470486

@@ -479,6 +495,7 @@ let test_endpoint_parameters ~number ~double ~pattern_without_delimiter ~byte ?i
479495

480496

481497

498+
482499
callback in
483500
let body = Request.finalize_form_encoded_body body in
484501
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
@@ -489,18 +506,24 @@ let test_enum_parameters ?(enum_header_string_array = []) ?(enum_header_string =
489506
let uri = Request.build_uri "/fake" in
490507
let headers = Request.default_headers in
491508
let headers = Request.add_header_multi headers "enum_header_string_array" (Stdlib.List.map Enums.show_enum_form_string_array
509+
492510
)
493511
enum_header_string_array in
494512
let headers = Request.add_header headers "enum_header_string" Enums.show_enumclass
513+
495514
enum_header_string in
496515
let uri = Request.add_query_param_list uri "enum_query_string_array" (Stdlib.List.map Enums.show_enum_form_string_array
516+
497517
)
498518
enum_query_string_array in
499519
let uri = Request.add_query_param uri "enum_query_string" Enums.show_enumclass
520+
500521
enum_query_string in
501522
let uri = Request.maybe_add_query_param uri "enum_query_integer" Enums.show_enum_query_integer
523+
502524
enum_query_integer in
503525
let uri = Request.maybe_add_query_param uri "enum_query_double" Enums.show_enum_number
526+
504527
enum_query_double in
505528
let uri = Request.add_query_param_list uri "enum_query_model_array" (Stdlib.List.map
506529

@@ -515,6 +538,7 @@ let test_enum_parameters ?(enum_header_string_array = []) ?(enum_header_string =
515538

516539

517540

541+
(failwith "Unsupported: enum reference")
518542
)
519543

520544

@@ -531,9 +555,11 @@ let test_enum_parameters ?(enum_header_string_array = []) ?(enum_header_string =
531555
enum_query_model_array in
532556
let body = Request.init_form_encoded_body () in
533557
let body = Request.add_form_encoded_body_param_list body "enum_form_string_array" (Stdlib.List.map Enums.show_enum_form_string_array
558+
534559
)
535560
enum_form_string_array in
536561
let body = Request.add_form_encoded_body_param body "enum_form_string" Enums.show_enumclass
562+
537563
enum_form_string in
538564
let body = Request.finalize_form_encoded_body body in
539565
Cohttp_lwt_unix.Client.call `GET uri ~headers ~body >>= fun (resp, body) ->
@@ -556,6 +582,7 @@ let test_group_parameters ~required_string_group ~required_boolean_group ~requir
556582

557583

558584

585+
559586
required_boolean_group in
560587
let headers = Request.maybe_add_header headers "boolean_group"
561588

@@ -570,6 +597,7 @@ let test_group_parameters ~required_string_group ~required_boolean_group ~requir
570597

571598

572599

600+
573601
boolean_group in
574602
let uri = Request.add_query_param uri "required_string_group"
575603
Int32.to_string
@@ -584,6 +612,7 @@ let test_group_parameters ~required_string_group ~required_boolean_group ~requir
584612

585613

586614

615+
587616
required_string_group in
588617
let uri = Request.add_query_param uri "required_int64_group" Int64.to_string
589618

@@ -598,6 +627,7 @@ let test_group_parameters ~required_string_group ~required_boolean_group ~requir
598627

599628

600629

630+
601631
required_int64_group in
602632
let uri = Request.maybe_add_query_param uri "string_group"
603633
Int32.to_string
@@ -612,6 +642,7 @@ let test_group_parameters ~required_string_group ~required_boolean_group ~requir
612642

613643

614644

645+
615646
string_group in
616647
let uri = Request.maybe_add_query_param uri "int64_group" Int64.to_string
617648

@@ -626,6 +657,7 @@ let test_group_parameters ~required_string_group ~required_boolean_group ~requir
626657

627658

628659

660+
629661
int64_group in
630662
Cohttp_lwt_unix.Client.call `DELETE uri ~headers >>= fun (resp, body) ->
631663
Request.handle_unit_response resp
@@ -698,6 +730,7 @@ let test_json_form_data ~param ~param2 =
698730

699731

700732

733+
701734
param in
702735
let body = Request.add_form_encoded_body_param body "param2"
703736

@@ -712,6 +745,7 @@ let test_json_form_data ~param ~param2 =
712745

713746

714747

748+
715749
param2 in
716750
let body = Request.finalize_form_encoded_body body in
717751
Cohttp_lwt_unix.Client.call `GET uri ~headers ~body >>= fun (resp, body) ->
@@ -755,6 +789,7 @@ let test_query_parameter_collection_format ~pipe ~ioutil ~http ~url ~context ~al
755789

756790

757791

792+
758793
)
759794

760795

@@ -782,6 +817,7 @@ let test_query_parameter_collection_format ~pipe ~ioutil ~http ~url ~context ~al
782817

783818

784819

820+
785821
)
786822

787823

@@ -809,6 +845,7 @@ let test_query_parameter_collection_format ~pipe ~ioutil ~http ~url ~context ~al
809845

810846

811847

848+
812849
)
813850

814851

@@ -836,6 +873,7 @@ let test_query_parameter_collection_format ~pipe ~ioutil ~http ~url ~context ~al
836873

837874

838875

876+
839877
)
840878

841879

@@ -863,6 +901,7 @@ let test_query_parameter_collection_format ~pipe ~ioutil ~http ~url ~context ~al
863901

864902

865903

904+
866905
)
867906

868907

@@ -877,7 +916,8 @@ let test_query_parameter_collection_format ~pipe ~ioutil ~http ~url ~context ~al
877916

878917

879918
context in
880-
let uri = Request.add_query_param uri "language" (Stdlib.List.map
919+
let uri = Request.add_query_param_exploded_form_object uri "language"
920+
881921

882922

883923

@@ -890,7 +930,8 @@ let test_query_parameter_collection_format ~pipe ~ioutil ~http ~url ~context ~al
890930

891931

892932

893-
)
933+
934+
894935

895936

896937

@@ -917,6 +958,7 @@ let test_query_parameter_collection_format ~pipe ~ioutil ~http ~url ~context ~al
917958

918959

919960

961+
920962
allow_empty in
921963
Cohttp_lwt_unix.Client.call `PUT uri ~headers >>= fun (resp, body) ->
922964
Request.handle_unit_response resp

0 commit comments

Comments
 (0)