Skip to content

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

Description

@valerioponte

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions