Skip to content

[JAVA] Object type with 'additionalProperties' not annotated/generated properly #1377

@bzb0

Description

@bzb0
Description

We have the following type/object, namely it is a dictionary/map, but it has one custom property, namely 'extras'.

links:
          description: Links object
          type: object
          additionalProperties:
             $ref: "#/components/schemas/hrefType"
          properties:
             extras:
                $ref: "#/components/schemas/hrefType"
 components:
       schemas:
              hrefType:
                    description: Link to a resource
                    type: string
                    example: "/test/1234"

The following code will be generated. If we set the property extras via the builder method, it will not be part of the serialized JSON object.

public class Links extends HashMap<String, String>  {
  @JsonProperty("extras")
  private String extras;

  public Links extras(String extras) {
    this.extras = extras;
    return this;
  }
  // ...
}
openapi-generator version

3.3.1

OpenAPI declaration file content or url

See description.

Command line used for generation

/

Steps to reproduce

/

Related issues/PRs

OpenAPI Generator: #1262
Swagger Code Generator: swagger-api/swagger-codegen#8245

Suggest a fix/enhancement

The generated code, should look like as proposed in the following Stackoverflow answers:
https://stackoverflow.com/a/31321861
https://stackoverflow.com/a/31321821
https://stackoverflow.com/a/44628460

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions