OpenAPITools / OpenAPITools/openapi-generator

[BUG] [JAVA] Missing importing @Valid cause compilation issue on client creation

Open
#17,617 8 comments 3 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
  • [v] Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • [v] Have you tested with the latest master to confirm the issue still exists?
  • [v] Have you searched for related issues/PRs?
  • [v] What's the actual output vs expected output?
    • Actual output: Compilation issue - cannot find symbol [ERROR] symbol: class Valid
    • Expected output: Valid API client code
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When the query parameter type is declare in a different yaml file but imported as reference and when the type is Array of Enum, it was notice that the client generation produces a not compiling java code.
In the client code, the method argument matching the query parameter is now annotated with @Valid (this was introduced in the openapi version 7.2.0) however the class does not import the annotation resulting in a "cannot find symbol" compilation issue.

openapi-generator version

The version 7.2.0 introduced this issue.

OpenAPI declaration file content or url

Content of first.yaml file

...
paths:
  /resource:
    get:
      parameters:
        - in: query
          name: queryParamListOfEnum
          required: false
          schema:
            type: array
            items:
              $ref: './second.yaml#/components/schemas/QueryParamListOfEnum'
      responses:
        '200':
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Resource'
...

Content of second.yaml file

...
components:
  schemas:    
    QueryParamListOfEnum:
      type: string
      enum:
        - "ABC"
        - "DEF"
...
Generation Details

openapi-generator-maven-plugin

configuration:

<useJakartaEe>true</useJakartaEe>
<library>webclient</library>
<useTags>true</useTags>
<dateLibrary>java8</dateLibrary>
<hideGenerationTimestamp>true</hideGenerationTimestamp>
<apiPackage>${api.package}.client</apiPackage>
<modelPackage>${api.package}.client.models</modelPackage>
Suggest a fix

Include the missing "import jakarta.validation.Valid;" import in the generated client class.

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 Java client generation with the two YAML files, openapi-generator-maven-plugin, and the webclient library described in the issue. Inspect the generated client imports where @Valid is emitted; done means the generated code includes the appropriate jakarta.validation.Valid import and compiles successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
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.