Skip to content

[BUG][OCaml] Exploded form query param leads to compilation error in generated code #21307

@sir4ur0n

Description

@sir4ur0n

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

The generator generates OCaml code that does not compile when a query param is of type form and exploded.

See https://swagger.io/docs/specification/v3_0/serialization/#query-parameters

The generated code is

let connections_controller_get_data_location_spec ~connection_id_or_key
    ~data_location_key ?(collection_params = []) () =
  let open Lwt.Infix in
  let uri =
    Request.build_uri "/connections/{connectionIdOrKey}/data/{dataLocationKey}"
  in
  let headers = Request.default_headers in
  let uri =
    Request.replace_path_param uri "connectionIdOrKey"
      (fun x -> x)
      connection_id_or_key
  in
  let uri =
    Request.replace_path_param uri "dataLocationKey"
      (fun x -> x)
      data_location_key
  in
  let uri =
    Request.add_query_param uri "collectionParams"
      (List.map (fun x -> x))
      collection_params
  in
  Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) ->
  Request.read_json_body_as
    (JsonSupport.unwrap Data_collection_spec_dto.of_yojson)
    resp body

The compilation error is:

File "integration-app-api/apis/connections_api.ml", line 56, characters 6-29:
56 |       (List.map (fun x -> x))
           ^^^^^^^^^^^^^^^^^^^^^^^
Error: This expression has type 'a list -> 'a list
       but an expression was expected of type 'a list -> string
       Type 'a list is not compatible with type string

Also:

  • The generated code should not make mention of collectionParams since the OpenAPI spec says explode: true
openapi-generator version

7.12.0 (latest)

OpenAPI declaration file content or url

https://api.integration.app/docs-json

In particular (notice the collectionParams query param):

"/connections/{connectionIdOrKey}/data/{dataLocationKey}": {
      "get": {
        "operationId": "ConnectionsController_getDataLocationSpec",
        "parameters": [
          {
            "name": "connectionIdOrKey",
            "required": true,
            "in": "path",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "dataLocationKey",
            "required": true,
            "in": "path",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "collectionParams",
            "required": false,
            "in": "query",
            "description": "Data Collection parameters",
            "style": "form",
            "explode": true,
            "schema": {
              "type": "object",
              "additionalProperties": {
                "type": "string"
              }
            }
          }
        ],
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DataCollectionSpecDto"
                }
              }
            }
          }
        },
        "summary": "Get connection data collection",
        "tags": [
          "Connections"
        ]
      }
    }
Generation Details
$ openapi-generator-cli generate \
  --generator-name ocaml \
  --input-spec docs-json
Steps to reproduce
$ openapi-generator-cli generate \
  --generator-name ocaml \
  --input-spec docs-json
Related issues/PRs

None.

Suggest a fix

A suggestion of generated code that seems to do the trick:

  let uri =
    List.fold_left
      (fun uri (param_name, param_value) ->
        Request.add_query_param uri param_name (fun x -> x) param_value)
      uri collection_params
  in

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions