OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Spring] Wrong Api Classes Generated for spring-cloud library (Only DefaultApi, instead of one per endpoint)

Open
#3,165 1 comment 1 reaction 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
  • Whenever spring-cloud library is used for spring generator, only DefaultApi is generated.
  • Whenever spring-boot library is selected, multiple Api classes are generated.

I believe the correct behaviour would be creating separate API classes just like for spring-boot, due to separation of responsabilities.

openapi-generator version

4.0.2

OpenAPI declaration file content or url

openapi: 3.0.2
paths:
  /hello:
    description: Hello World API
    get:
      summary: GET Hello World
      operationId: getHelloWorld
      parameters:
        - in: query
          name: name
          required: true
          schema:
            type: string
      responses:
        200:
          description: oi
          content:
            text/plain:
              schema:
                type: string
  /bye:
    description: Bye World API
    get:
      summary: GET Bye World
      operationId: getByeWorld
      parameters:
        - in: query
          name: name
          required: true
          schema:
            type: string
      responses:
        200:
          description: oi
          content:
            text/plain:
              schema:
                type: string


Command line used for generation
java -jar openapi-generator-cli.jar generate -i spec.yaml -g spring --library spring-cloud
Steps to reproduce
  1. Get the spec
  2. Run the command line
  3. DefaultApi.java will be generated instead of HelloApi.java and ByeApi.java
Related issues/PRs

Couldn't find any similar issues.

Suggest a fix

I couldn't be sure what exactly the error is, but I suspect it is caused by this line, that excludes cloud library from the logic:

https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java#L437

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 by reproducing the issue with the supplied OpenAPI YAML and the java -jar openapi-generator-cli.jar generate -i spec.yaml -g spring --library spring-cloud command. Inspect modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java around line 437, which the report identifies as relevant. Done means the spring-cloud output contains separate HelloApi.java and ByeApi.java classes rather than only DefaultApi.java.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.