OpenAPITools / OpenAPITools/openapi-generator

[BUG] JavaClient Generator with feign library does not handle inherited required and readonly attributes correctly

Open
#15,190 0 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

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • 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

See attached yaml file. When generating with
<generatorName>java</generatorName>
<configOptions>
<interfaceOnly>true</interfaceOnly>
<delegatePattern>true</delegatePattern>
<openApiNullable>false</openApiNullable>
<useBeanValidation>true</useBeanValidation>
<library>feign</library>
</configOptions>

The class SecondDerivation contains a constructor that tries to set the fields id and href which are actually in class FirstDerivation. Since the fields are private this can not work.

openapi-generator version

Version 6.5

OpenAPI declaration file content or url

Yaml file attached.

Generation Details
Steps to reproduce

Generate a model from the yaml with the above options.

Related issues/PRs

This issue shows a very similar, or maybe even the same problem:

https://github.com/OpenAPITools/openapi-generator/issues/13253

Suggest a fix

The Spring generator implements the postProcessAllModels method and handles this perfectly by calling the constructor of the base class instead of trying to set the variables. As a temporary fix I changed the pojo.mustache of the Java generator in my project, but I am not sure this fixes all problems.

simpleAPI.zip

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 attached simpleAPI.zip and reproduce generation using the Java generator with the feign library and the listed config options. Read the Java generator's postProcessAllModels implementation and pojo.mustache, then verify that generated SecondDerivation handles inherited id and href fields without attempting to access private fields from FirstDerivation.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.