OpenAPITools / OpenAPITools/openapi-generator

[BUG] [JAVA] Inheritance: required param of child not correct

Open
#13,158 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

If child defines a parameter as required but parent does not have it as required, it generates a new parameter for the child (name shadowing).

openapi-generator version

6.0.1 (using java)

Generation Details & Steps to reproduce

e.g. with a yaml similar to this:

parent:
  properties:
    param:
      type: string

child:
  allOf:
    $ref: 'parent'
    type: object
    required:
      param

Then the child class has its own attribute 'param' and does not inherit from parent (neither the attribute nor its getter and setter). Hence inheritance is not done properly.

Expected Behavior

I expect the child class to inherit the 'param' and its setter and getter from the parent.

Suggest a fix

I think the 'pojo.mustache' need the {{isInherited}} to call super in those cases.

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 issue with the YAML example and inspect the Java generator's pojo.mustache template, particularly the isInherited handling. Done means the child reuses the parent's param attribute, getter, and setter instead of generating shadowing members.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.