OpenAPITools / OpenAPITools/openapi-generator

[BUG] Inheritance and Maps canno coexist

Open
#4,789 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug Server: Spring
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
Description

The attached file represents an inheritance containing, in the subclass, a hashmap with a custom type. Well, I don't get this, but I get different results.
As a result I'd expect to get

public class SubObjectDTO extends SuperObjectDTO {
private Map<String, MapElementDTO> additionalMap;
....[getters and setter and whatever more]---
}
public class SuperObjectDTO {
private UUID id;
private String superProperty1;
private String superProperty2;
....[getters and setter and whatever more]---
}

public class MapElementDTO {
private int property1;
private boolean property2;
private String property3;
....[getters and setter and whatever more]---
}

while I get the Super class and the map element ok, the subclass varies depending from the inclusion of the clause of allOf. If I add this, I see the element with the properties of the superclass, but no additionalProperties. If i remove this, I dont get the super class props but just the additional ones.
Is this a bug or I'm doing a mistake?

openapi-generator version

openapi-generator version
4.2.2

OpenAPI declaration file content or url

See attached gist
https://gist.github.com/maxper75/62a7cdac09037679641c56f552bc21ef#file-buggy-openapi-inheritance-map-json

Command line used for generation

openapi-generator generate -g spring -i model.json -o prova

Steps to reproduce

just launch the command :D

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 with the OpenAPI declaration in the linked gist and run the reported spring generator command with openapi-generator 4.2.2. Inspect the generated SubObjectDTO, SuperObjectDTO, and MapElementDTO classes with and without the allOf clause. Done means the subclass preserves inheritance and includes the typed map alongside the superclass properties.

Written by the indexing model from the issue text.

Assessment

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