OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.84k stars 6.59k forks source link

[BUG][JAVA] nullable object: incompatible types: cannot infer type arguments for java.util.HashMap<> #16519

Closed panovst closed 1 year ago

panovst commented 1 year ago

Bug Report Checklist

Description
openapi-generator version

6.5.0

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: my service
  description: my service
  version: 1.0.0
servers:
  - url: http://localhost:8080
    description: localhost
tags:
  - name: Attribute controller
paths:
  /v1/attribute/{id}:
    get:
      tags:
        - Attribute controller
      parameters:
        - name: id
          description: Attribute id
          required: true
          in: path
          schema:
            type: string
          example: "0006776500"
      responses:
        '200':
          description: Success
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/Attribute'
components:
  schemas:
    Attribute:
      type: object
      properties:
        languageValues:
          nullable: true
          type: object
          additionalProperties:
            type: string
    Error:
      type: object
      properties:
        errors:
          type: array
          items:
            type: object
            properties:
              errorCode:
                type: string
              errorDescription:
                type: string
Generation Details

Maven plugin configuration

            <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>6.5.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>${project.build.outputDirectory}/static/open-api/openapi.yml</inputSpec>
                            <generatorName>spring</generatorName>
                            <modelPackage>dto</modelPackage>
                            <apiPackage>web</apiPackage>
                            <library>spring-cloud</library>
                            <configOptions>
                                <sourceFolder>src/gen/java/main</sourceFolder>
                                <dateLibrary>java8</dateLibrary>
                                <useTags>true</useTags>
                                <documentationProvider>none</documentationProvider>
                                <additionalModelTypeAnnotations>@lombok.AllArgsConstructor; @lombok.NoArgsConstructor;
                                    @lombok.Builder</additionalModelTypeAnnotations>
                                <generatedConstructorWithRequiredArgs>false</generatedConstructorWithRequiredArgs>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
Steps to reproduce

Generated Attribute.java

public class Attribute {

  @Valid
  private JsonNullable<Map<String, String>> languageValues = JsonNullable.undefined();

  ...

  public Attribute putLanguageValuesItem(String key, String languageValuesItem) {
    if (this.languageValues == null) {
      this.languageValues = new HashMap<>();
    }
    this.languageValues.put(key, languageValuesItem);
    return this;
  }

   ...

for some reason, this method does not use "JsonNullable.of()" when initializing a variable

Related issues/PRs

No related issues found

wing328 commented 1 year ago

6.5.0

please use v7.0.0. I think the issue has been fixed.

panovst commented 1 year ago

6.5.0

please use v7.0.0. I think the issue has been fixed.

I checked for the master version by the manual

image image

wing328 commented 1 year ago

Thanks for providing more info. I've filed https://github.com/OpenAPITools/openapi-generator/pull/16524 to fix it