OpenAPITools / OpenAPITools/openapi-generator

[BUG] [JAVA] Maven plugin creates incorrect java objects

Open
#21,049 5 comments 0 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
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)

`

Description

When using the given yaml, the open api maven generator plugin generates wrong objects.
In the example we get three classes:

  • Date
  • User
  • UserBirthdate

With the openapi generator cli, there are only 2 classes: User and Date, which is corret

openapi-generator version

7.12.0

OpenAPI declaration file content or url
openapi: 3.1.1
info:
  title: Minimum example
  version:

paths:
  /users/{userId}:
    get:
      parameters:
        - in: path
          name: userId
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Get user
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/User'


components:
  schemas:
    User:
      type: object
      properties:
        name:
          type: string
        firstname:
          type: string
        birthdate:
          $ref: '#/components/schemas/Date'
        gender:
          type: string
        deathdate:
          $ref: '#/components/schemas/Date'

    Date:
      type: object
      properties:
        value:
          type: string
          format: date
Generation Details

java -jar openapi-generator-cli-7.12.0.jar generate -g java -o out -i minexample.yaml --global-property models --additional-properties=serializationLibrary=jackson,useJakartaEe=true,dateLibrary=java8,library=feign

is working correctly

                    <groupId>org.openapitools</groupId>
                    <artifactId>openapi-generator-maven-plugin</artifactId>
                    <version>7.12.0</version>
                    <executions>
                        <execution>
                            <id>partnermanagement</id>
                            <goals>
                                <goal>generate</goal>
                            </goals>
                            <phase>generate-sources</phase>
                            <configuration>
                                <generatorName>java</generatorName>
                                <verbose>true</verbose>
                                <output>src/gen/java</output>
                                <inputSpec>${project.baseUri}/src/gen/resources/minexample.yaml</inputSpec>
                                <configOptions>
                                    <useJakartaEe>true</useJakartaEe>
                                    <sourceFolder>.</sourceFolder>
                                    <serializationLibrary>jackson</serializationLibrary>
                                    <dateLibrary>java8</dateLibrary>
                                    <resolveFully>false</resolveFully>
                                </configOptions>
                                <library>feign</library>
                                <generateSupportingFiles>false</generateSupportingFiles>
                                <generateModels>true</generateModels>
                                <generateApis>false</generateApis>
                                <generateApiTests>false</generateApiTests>
                                <generateModelTests>false</generateModelTests>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

is not working

Line 1102 in CodeGenMojo always sets the parseOptions with setResolve(true). That seems to be the different to the openapi-generator-cli

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 at line 1102 in CodeGenMojo, then compare its parseOptions handling with the CLI generation command. Reproduce using the supplied OpenAPI YAML and Maven plugin configuration, and verify that Maven generates only the User and Date classes, matching the CLI output rather than adding UserBirthdate.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.