openapi-generator: [BUG][Spring] generated api interface doesn't have @RequestParam annotation

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What’s the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What’s the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

I updated openapi-generator from 4.0.1 to 4.0.2. Then, I found generated api interface from same spec is different between 4.0.1 and 4.0.2.

For some reason, @RequestParam is not generated for api parameters. Here is an example.

  • 4.0.1
@ApiParam(value = "", allowableValues = "json, csv, tsv", defaultValue = "json")
@Valid
@RequestParam(value = "format", required = false, defaultValue = "json")
Format format
  • 4.0.2
@ApiParam(value = "", allowableValues = "json, csv, tsv", defaultValue = "json")
@Valid
Format format
openapi-generator version

4.0.2

OpenAPI declaration file content or url
openapi: 3.0.2
info:
  title: info
  description: info
  version: 0.1.0

paths:
  /example/api:
    get:
      summary: summary
      description: description
      parameters:
      - $ref: '#/components/parameters/requiredQueryParam'
      - $ref: '#/components/parameters/formatParam'
      responses:
        200:
          description: response
          content:
            application/json:
              schema:
                type: string

components:
  parameters:
    requiredQueryParam:
      description: set query
      in: query
      name: query
      required: true
      schema:
        type: string
    formatParam:
      description: set format
      in: query
      name: format
      required: false
      schema:
        $ref: '#/components/schemas/format'

  schemas:
    format:
      default: json
      description: response format
      enum:
      - json
      - csv
      type: string
Command line used for generation
$ mvn clean package
$ java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i ./simple-example-spec/openapi.spec -g spring -o output
Steps to reproduce

Generate api code for spring with 4.0.1 and 4.0.2. Then compare the api parameters of api interface.

Related issues/PRs

I couldn’t find any similar issues.

Suggest a fix

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 3
  • Comments: 27 (23 by maintainers)

Most upvoted comments

Why is the issue not closed? Is the bug still there or isn’t it tested?

Hi guys,

I created a PR as well ( #3857 ). Here’s what I did:

  • I reverted this 146c1fb, but kept the test to ensure that there’s no regression on issue #2655
  • I used isPrimitiveType instead of ^isModel in the mustache template. This seems to be a much simpler solution and a lot less invasive as the solution introduced in 146c1fb
  • I added a couple of tests to ensure enums, localdates and so on are working properly

Cheers, Roger

@macjohnny I don’t know the background of this issue. But, I can try to fix and create a PR, so I will do it next week if no one will fix.

I’ve opened #3855 with a proposed fix. Would someone from this thread be able to test it out and provide feedback?

Blocking for me as well. A fix would be highly appreciated.

This would be very appreciated

@t2y thanks for pinging. I’m very far behind on emails and didn’t see the last mention in the thread.

It looks like property.isModel assignment could add an && !ModelUtils.isEnum(p)? This function doesn’t exist, but may be necessary for this case

@t2y thanks for the analysis a workaround for your problem could be to inline the parameter, i.e.

components:
    formatParam:
      description: set format
      in: query
      name: format
      required: false
      default: json
      description: response format
      enum:
        - json
        - csv
      type: string

I guess either components.schemas should not be used for query params or https://github.com/OpenAPITools/openapi-generator/blob/146c1fb25530699661211bcdd92b76491902b4b7/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java#L2213 should be extended to also check that the type is object @wing328 @jimschubert @jmini what is your opinion?

This is needed by me as well. A fix would be very appreciated.

I also see missing @RequestParam with date-time format.

- name: start
  in: query
  schema:
     type: string
     format: date-time
  required: true
  description: The start time.

If I delete format to have the parameter a String then @RequestParam is present.

@macjohnny Now I made a test environment to run openapi-generator cli for git bisect. I will investigate which revision affects this issue in this weekend.

Currently, my production spec is complicated, so I will try to create simple example spec if possible.