Skip to content

[BUG] [SPRING-CLOUD] Unnecessary package imports in clientConfiguration #5144

@sakanaou

Description

@sakanaou

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

Using the spring-cloud library of the spring generator results in a ClientConfiguration.java file generated and referenced by a Feign-Client API interface that lists unnecessary packages. Without specifying these packages as "compile-time" dependencies the service cannot be compiled. Making the package import definitions conditional this is mitigated.

openapi-generator version

4.2.2. No regression.

OpenAPI declaration file content or url
openapi: "3.0.0"
info:
  version: 0.1.0
  title: frontend-v1
  license:
    name: MIT

paths:
  /echo:
    post:
      summary: Echoes back your own words.
      requestBody:
        description: The sound to echo.
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/EchoRequest"
      responses:
        "200":
          description: Your echo as requested.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/EchoResponse"

components:
  schemas:
    EchoRequest:
      properties:
        sound:
          type: string
          description: The sound to echo.
      required:
        - sound        
    EchoResponse:
      properties:
        echo:
          type: string
          description: The actual echo.
      required:
        - echo
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. Try to compile the generated code with minimal dependencies.
Related issues/PRs

The same seemed to happen in typescript-rxjs generator
#3339

Suggest a fix

Import packages conditionally.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions