Skip to content

List query parameters are exploded on the Feign client even when explode is false #493

@rvinzent

Description

@rvinzent

Problem

I have the following OpenAPI 3.1 schema:

{
  ..., 
  "/v1/resource/": {
    "get": {
      "operationId": "getPage",
      "parameters": [
        {
          "in": "query",
          "name": "slug",
          "schema": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
       "explode": false,
       "style": "form"
      }
    ]
  }
}

According to the OpenAPI docs, "style": "form" with "explode": false should produce a comma separated list of values, e.g. ?slug=one,two,three, but the generated Feign client ends up creating a request with exploded parameters.

Generated client method looks something like this:

@RequestLine("GET /v1/reagent/?slug={slug}")
@Headers("Accept: application/json")
public fun getResourcePage(
  @Param("slug") slug: List<String>? = null,
  @HeaderMap additionalHeaders: Map<String, String> = emptyMap(),
  @QueryMap additionalQueryParameters: Map<String, String> = emptyMap(),
): PaginatedResource

The suggested fix for Spring OpenFeign clients is to use the @CollectionFormat(feign.CollectionFormat.CSV) annotation to the @FeignClient class (docs), however, this seems to only work for methods/classes annotated with @RequestMapping (source).

@RequestLine instead accepts a collectionFormat parameter on the annotation to provide this configuration (source), however, each parameter in an OpenAPI spec can define explode independently, and feign doesn't seem to have the same collectionFormat configuration available on the @Param annotation. Instead, to configure the behavior on a per parameter basis, we'd probably have to utilize the expand parameter on the @Param annotation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions