OpenAPITools / OpenAPITools/openapi-generator

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

Open
#1,377 5 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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: https://github.com/OpenAPITools/openapi-generator/pull/1262
Swagger Code Generator: https://github.com/swagger-api/swagger-codegen/pull/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

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 by reproducing the Java generation from the YAML schema in the description, then trace how schemas combining additionalProperties with properties are handled. Verify the generated Links model and its JSON serialization, using the expected behavior from the linked Stack Overflow examples as the completion criterion.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, 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.