OpenAPITools / OpenAPITools/openapi-generator

[BUG] spring generator using maven plugin generates correct code, while cli/gradle generates wrong code

Open
#6,591 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug Server: Spring
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 (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 have a simple sample spec. When invoking the generator from maven plugin, code is generated as expected. But both gradle plugin and cli generate a different code.

on the generated interface com.example.api.DefaultApi, when running from Gradle/CLI, this code is generated:

    ResponseEntity<InlineResponse200> getGreetingsMessage(ServerWebExchange exchange);

Which is wrong as it is using reactive classes, which are disabled on the config file.

When using maven plugin, the following code is generated instead:

    ResponseEntity<InlineResponse200> getGreetingsMessage();

which seems to be the correct code.

openapi-generator version

4.3.1

OpenAPI declaration file content or url
openapi: '3.0.3'
info:
  title: 'Greetings API'
  version: '1.0.0'
paths:
  /api/v1/greetings:
    get:
      operationId: getGreetingsMessage
      responses:
        200:
          description: 'A greetings message'
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
Command line used for generation
openapi-generator generate \
    --input-spec spec.yaml \
    --config config.json \
    --generator-name spring \
    --output . \
    --invoker-package com.example \
    --api-package com.example.api \
    --model-package com.example.model
Config file used for generation
{
  "useTags": "true",
  "interfaceOnly": "true",
  "hideGenerationTimestamp": "true",
  "sourceFolder": "src/gen/java",
  "java8": "true",
  "library": "spring-boot",
  "dateLibrary": "java8",
  "reactive": "false",
  "useOptional": "true",
  "useBeanValidation": "true",
  "skipDefaultInterface": "true"
}
Steps to reproduce

copy both spec.yaml and config.json to a folder and run open-api-generator-cli as described above.

Related issues/PRs

No related issues I could find.

Suggest a fix

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 spec.yaml and config.json, then trace the spring generator path used by the CLI and Gradle plugin, comparing it with the Maven plugin behavior. Reproduce the generation command and verify that reactive=false produces DefaultApi.getGreetingsMessage() without ServerWebExchange.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring-boot
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.