openapi-codegen icon indicating copy to clipboard operation
openapi-codegen copied to clipboard

Correct handling of `style` and `explode`.

Open r34son opened this issue 1 year ago • 2 comments

OpenAPI spec:

targets:

  get:
    tags:
      - targets
    operationId: getProductTargets
    parameters:
      - name: searchParameters
        description: "Some description"
        in: query
        required: true
        schema:
          $ref: "..ProductTargetsSearch"
    responses:
      200:
        description: "Some description"
        content:
          application/json:
            schema:
              $ref: "..GetProductTargetsResponse"
      400:
        description: "Some description"
        content:
          application/json:
            schema:
              $ref: "..ErrorDto"
      500:
        description: "Ошибка на сервере"
        content:
          application/json:
            schema:
              $ref: "..ErrorDto"

Generator emits type for queryParams:

export type GetProductTargetsQueryParams = {
    /**
     * Some description
     */
    searchParameters: Schemas.ProductTargetsSearch;
};

But by spec https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#parameter-object parameter in: query has default value of style - form. So explode default value is true for form style. Spec says:

When this is true, parameter values of type array or object generate separate parameters for each value of the array or key-value pair of the map

Should generator emit queryParam type with spreaded params? if no, why?

r34son avatar Mar 19 '24 14:03 r34son

@fabien0102 Hi Fabien! Thanks for the great work! Could you take a look at that?

r34son avatar Mar 19 '24 14:03 r34son

Hey, thx for raising the issue, I don't think the style and explode are implemented here.

Usually, the entire API should follow the same style so you can handle this in your custom fetcher. This is at least the assumption I did ^^ I'm always happy to improve the library to handle more usecase, so if you have time, I'm open to pull-request 😀

fabien0102 avatar Apr 11 '24 13:04 fabien0102