Skip to content

[BUG][quarkus][java][jaxrs-spec] Missing import of java.util.HashMap for spec 3.1 #21760

@aservedio-swi

Description

@aservedio-swi

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • 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 I change my openapi version for my spec from 3.0.3 to 3.1.1 (this is the ONLY change), the jaxrs-spec generator no longer includes an import java.util.HashMap for the code that it generates (it is required because it generates a new HashMap<>() within the code).

The hashmap is used in response to this schema property:

        custom:
          type: string
          additionalProperties:
            type: object

It generates:

  private Map<String, Object> custom = new HashMap<>();

It has the import for the java.util.Map but does NOT have the import for the java.util.HashMap - and so the code cannot compile.

openapi-generator version

7.14.0 and tried against master

OpenAPI declaration file content or url
openapi: 3.1.1
info:
  title: Title here
  description: Description here
  version: 1.0.0
servers:
  - url: https://localhost:8080
    description: Local development server
paths:
  /v1/api:
    post:
      operationId: createApi
      tags:
        - Operation
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MyRequest'
        required: true
      responses:
        '201':
          description: Successful operation creation

components:
  schemas:
    MyRequest:
      type: object
      properties:
        id:
          type: string
          description: Unique identifier
        custom:
          type: string
          additionalProperties:
            type: object
Generation Details
  • Using JDK 21.0.8
  • Maven 3.9.11

pom.xml plugin definition:

            <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>7.14.0</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <inputSpec>${basedir}/openapi.yaml</inputSpec>
                    <generatorName>jaxrs-spec</generatorName>
                    <apiPackage>net.mycompany.operation.api</apiPackage>
                    <modelPackage>net.mycompany.operation.api.model</modelPackage>
                    <invokerPackage>net.mycompany.operation.api.client</invokerPackage>
                    <generateApiTests>false</generateApiTests>
                    <generateModelTests>false</generateModelTests>
                    <verbose>false</verbose>
                    <configOptions>
                        <dateLibrary>java8</dateLibrary>
                        <interfaceOnly>true</interfaceOnly>
                        <library>quarkus</library>
                        <returnResponse>true</returnResponse>
                        <sourceFolder>src/gen/java/main</sourceFolder>
                        <useBeanValidation>true</useBeanValidation>
                        <useJakartaEe>true</useJakartaEe>
                        <useMicroProfileOpenAPIAnnotations>true</useMicroProfileOpenAPIAnnotations>
                        <useSwaggerAnnotations>false</useSwaggerAnnotations>
                        <useTags>true</useTags>
                    </configOptions>
                </configuration>
            </plugin>

I use a mvn clean package to run that plugin. More specifically: mvn -B -T4 -e -U -fae --no-transfer-progress clean package -DskipTests

Steps to reproduce
  1. Create the openapi.yaml file as shown above
  2. Create maven project with plugin definition above
  3. Using JDK 21 and Maven 3.9
  4. Have the code generator run by using mvn clean package (or mvn -B -T4 -e -U -fae --no-transfer-progress clean package -DskipTests
  5. It will not be able to compile the code due to the missing java.util.HashMap import
Related issues/PRs

Do not see any.

Suggest a fix

When the Map is imported, also import the HashMap.

Here is the code that the above openapi.yaml creates:

package net.mycompany.operation.api.model;

import java.util.Map;
import jakarta.validation.constraints.*;
import jakarta.validation.Valid;

import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.annotation.JsonTypeName;



@org.eclipse.microprofile.openapi.annotations.media.Schema(description="")
@JsonTypeName("MyRequest")
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaJAXRSSpecServerCodegen", date = "2025-08-15T14:15:26.494368-04:00[America/New_York]", comments = "Generator version: 7.14.0")
public class MyRequest   {
  private String id;
  private Map<String, Object> custom = new HashMap<>();

  public MyRequest() {
  }

  /**
   * Unique identifier
   **/
  public MyRequest id(String id) {
    this.id = id;
    return this;
  }

  
  @org.eclipse.microprofile.openapi.annotations.media.Schema(description = "Unique identifier")
  @JsonProperty("id")
  public String getId() {
    return id;
  }

  @JsonProperty("id")
  public void setId(String id) {
    this.id = id;
  }

  /**
   **/
  public MyRequest custom(Map<String, Object> custom) {
    this.custom = custom;
    return this;
  }

  
  @org.eclipse.microprofile.openapi.annotations.media.Schema(description = "")
  @JsonProperty("custom")
  public Map<String, Object> getCustom() {
    return custom;
  }

  @JsonProperty("custom")
  public void setCustom(Map<String, Object> custom) {
    this.custom = custom;
  }


  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    MyRequest myRequest = (MyRequest) o;
    return Objects.equals(this.id, myRequest.id) &&
        Objects.equals(this.custom, myRequest.custom);
  }

  @Override
  public int hashCode() {
    return Objects.hash(id, custom);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class MyRequest {\n");
    
    sb.append("    id: ").append(toIndentedString(id)).append("\n");
    sb.append("    custom: ").append(toIndentedString(custom)).append("\n");
    sb.append("}");
    return sb.toString();
  }

  /**
   * Convert the given object to string with each line indented by 4 spaces
   * (except the first line).
   */
  private String toIndentedString(Object o) {
    if (o == null) {
      return "null";
    }
    return o.toString().replace("\n", "\n    ");
  }


}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions