OpenAPITools / OpenAPITools/openapi-generator

[REQ][JAVA][Spring] Add support for SpringQueryMap in Feign clients

Open
#11,624 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Is your feature request related to a problem? Please describe.

When defining a GET APIs we might want to use many different optional query parameters to filter e.g a collection resource like /books. With the current generator one would need to define all the properties as separate query parameters on the operation, resulting in an interface method with a lot of method arguments.

The preferable way would be to have an object that contains all query parameters. This would make the interfaces more stable as method signature would not change if an optional query parameter is added. Also it makes passing the parameters around on both client and backend side a lot nicer.

Describe the solution you'd like

I would like the generator to support defining one single query parameter which is an object contains all the query parameters like below.

paths:
  /books:
    get:
      summary: Search books
      operationId: search-books
      tags:
        - books
      parameters:
        - name: filter
          in: query
          required: true
          description: Search filter
          schema:
            $ref: '#/components/schemas/SearchFilter'
components:
  schemas:
    SearchFilter:
          type: object
          properties:
            publisherId:
              uniqueItems: true
              type: array
              items:
                type: integer
                format: int64
            name:
              type: string
            yearPublished:
              type: integer
              format: int32
            authorId:
              type: integer
              format: int64

Describe alternatives you've considered

Using a POST where payload contains the properties to filter by, but a benefit with GET is that one can see the parameters in access logs.

Additional context

Adding {{#isModel}} @org.springframework.cloud.openfeign.SpringQueryMap{{/isModel}} to queryParams.mustache seems to do the trick.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with modules/openapi-generator/src/main/resources/JavaSpring/queryParams.mustache and review how model query parameters are rendered. Use the provided SearchFilter OpenAPI example to inspect the generated Feign client; done means the model query parameter receives SpringQueryMap support without requiring separate method arguments.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.