OpenAPITools / OpenAPITools/openapi-generator

[BUG] Java: error: ... has private access in ...

Open
#19,537 3 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)?
  • yes but it has circular references, see below
  • 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

openapi.json from a Youtrack Cloud instance generates Java code that is invalid - subclasses refer to private members of their (grand)parents.

openapi-generator version

7.9.0-SNAPSHOT

OpenAPI declaration file content or url

https://ktbyteops.youtrack.cloud/api/openapi.json

(I put this through the validator and got an error - This API is valid, but it cannot be shown because it contains circular references - not sure if that is related.)

Generation Details

Run:

docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate \
    -i https://ktbyteops.youtrack.cloud/api/openapi.json \
    -g java \
    -o /local

Then:

mvn package

Output is filled with errors, such as:

[ERROR] /Users/crummy/code/earth/youtrack_api/src/main/java/org/openapitools/client/model/CustomFieldActivityItem.java:[118,8] error: targetMember has private access in ActivityItem
Related issues/PRs

Same bug appears to be reported here: https://github.com/OpenAPITools/openapi-generator/issues/16797

That bug is reported to be fixed on Jan 5, and 7.8.0 was released 2 weeks ago so I expect the fix is in my 7.9.0-SNAPSHOT version.

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 linked openapi.json and reproduce the generation using the provided Docker command with the Java generator. Run mvn package on the generated project and compare the private-access errors with related issue 16797. Done means the generated Java code compiles without errors such as subclasses accessing private members of ActivityItem.

Written by the indexing model from the issue text.

Assessment

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