OpenAPITools / OpenAPITools/openapi-generator

[BUG][JAVA][SPRING] Missing `@RequestParam` annotation for complex query parameters which are not an array or an enum

Open
#22,556 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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

I have the issue that when I define a GET request with a complex query parameter (see examples below), the parameter in the generated API class is missing the @RequestParam annotation. Due to that, the parameter is not properly resolved by Spring (not entering the Custom Converter, using the "default" instance).

However this seems only to occur, if the complex query parameter is not an enum or an array.

I would expect that all parameters have the @RequestParam annotation.

It also works if it's not a query parameter but a path variables.

openapi-generator version

7.17.0

OpenAPI declaration file content or url

See full project here: https://github.com/DManstrator/Reproducable-Example-OpenAPI-Missing-RequestParam-Annotation/tree/4713f51f01033cc297f953679c45770db763e380

Generation Details

Install the project with default Maven commands (e.g. mvn clean install) .

Steps to reproduce
  1. Install the project with Maven.
  2. Checkout missing_annotation\src\generated\java\tk\dmanstrator\openapi\missing_annotation\api\MissingAnnotationExampleApi.java and look for the missing annotation.

Alternatively:
Start the application and open http://localhost:8080/rest/query-custom-version-search?version=3.2.1. You should get an info, that all version attributes are null.

If you open for example

  • http://localhost:8080/rest/fixed-version-search?version=1.5.7
  • http://localhost:8080/rest/custom-versions-search?versions=1.2.3,4.5.6
  • http://localhost:8080/rest/path-custom-version-search/3.2.1

you will see that the Custom Converters will be entered. This won't happen in the first case.

Related issues/PRs

Perhaps #3248 (this is however over 6 years old and already had a fix).

Suggest a fix

N/A

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 the linked OpenAPI definition and generated MissingAnnotationExampleApi.java, then run the reproduction project with Maven using the documented query and path cases. Compare the generated annotations for complex, enum, array, and path parameters; done means the complex query parameter receives @RequestParam and the custom converter is entered as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.