OpenAPITools / OpenAPITools/openapi-generator

[BUG] Spring generator alloff creates putItem methods with incorrect arguments

Open
#16,245 18 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

Summary: Openapi-generator-maven-plugin 'alloff' tries to create a putItem method, which I dont need, also it cant create properly, and it fails to compile.

As a part of our javax -> jakarta migration we upgraded to version 6.6.0(it was 5.0. before) I see some of the created java classes (by openapi-generator) has errors, I see methods that should not be there (I compare with old version classes and this 'putTypeItem' doesn't exist in old versions). if they must be there, then they should be created properly.

Note the error in 'typeItem' in method parameters below, there is no type! And this method do not exist in old version. I have compilation errors:

public GetResponse putTypeItem(String key,  **typeItem**) {
  if (this.type == null) {
    this.type = new HashMap<>();
  }
  this.type.put(key, typeItem);
  return this;
}

This is my plugin config:

<plugin>
       <groupId>org.openapitools</groupId>
       <artifactId>openapi-generator-maven-plugin</artifactId>
       <version>6.6.0</version>
       <executions>
         <execution>
           <id>generate</id>
           <goals>
             <goal>generate</goal>
           </goals>
           <configuration>
             <inputSpec>${basedir}/../management-swagger.yaml</inputSpec>
             <generateApis>false</generateApis>
             <generateApiTests>false</generateApiTests>
             <generateApiDocumentation>false</generateApiDocumentation>
             <generateModelDocumentation>false</generateModelDocumentation>
             <generateModelTests>false</generateModelTests>
             <generateSupportingFiles>false</generateSupportingFiles>
             <generatorName>spring</generatorName>
             <configOptions>
               <useJakartaEe>true</useJakartaEe>
               <dateLibrary>java8</dateLibrary>
             </configOptions>
             <modelPackage>com.client.model</modelPackage>
             <typeMappings>
               <typeMapping>Double=java.math.BigDecimal</typeMapping>
             </typeMappings>
           </configuration>
         </execution>
       </executions>
     </plugin>

and this is how my full yaml looks like:

swagger: '2.0'
info:
  title: My title
  termsOfService: ''
  version: 19.0.0
host: myhost.com
schemes:
  - https
consumes:
  - application/json
produces:
  - application/json
paths:
  '/url':
    parameters:
      - type: string
        name: some name
        in: path
        required: true
        description: Some description

definitions:
  MyResponseV2:
    properties:
      type:
        description: Some description
        type: object
        properties:
          code:
            type: string
            description: 'blah'
          description:
            type: string
            description: 'blah'
    allOf:
      - $ref: '#/definitions/PartyType'

  PartyType:
    type: object
    properties:
      code:
        type: string
        description: 'Some description'

EDIT: I get the same error using cli tool as well without any maven plugin:

java -jar openapi-generator-cli-6.6.0.jar generate -g java -i myspec.yaml -o /tmp/java-okhttp/ --openapi-normalizer REFACTOR_ALLOF_WITH_PROPERTIES_ONLY=true

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

Reproduce the issue with the supplied Swagger definition, Spring generator configuration, and the CLI command using REFACTOR_ALLOF_WITH_PROPERTIES_ONLY=true. Trace Spring model generation for allOf schemas with properties, then verify that the generated Java model compiles and that putTypeItem is either omitted as intended or has a valid parameter type.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.