OpenAPITools / OpenAPITools/openapi-generator

[BUG] allVars contains only properties from allOf if allOf and local properties are used in a schema

Open
#12,778 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

If a schema defines properties using "allOf" and the "properties" block both, the properties from the "properties" block are only in "vars" but not in "allVars". That is not the case if the properties from the "properties" block are declared in an anonymous schema object within the "allOf" block instead.

See MyResourceA and MyResourceB in the example (gist; see below).

openapi-generator version

5.4.0 but the faulty line (see "Suggested fix" below) is still present in the master (6.0.1)

OpenAPI declaration file content

https://gist.github.com/fkser/835b9e6a896ef368c1409d643fddb231

Related issues/PRs

Not sure, but the following issues might be related:

Suggested fix

The bug is in the method DefaultCodegen.updateModelForComposedSchema

        // TODO revise the logic below to set discriminator, xml attributes
        if (supportsInheritance || supportsMixins) {
            m.allVars = new ArrayList<>();
            if (composed.getAllOf() != null) {

where the allVars-Member is reset to an empty ArrayList. Since the CodegenModell.allVars is always created with an empty List as default, the problematic code line can be removed.

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 at DefaultCodegen.updateModelForComposedSchema and inspect the CodegenModel.allVars initialization around composed allOf handling. Reproduce the MyResourceA and MyResourceB cases from the linked OpenAPI declaration, then verify that allVars includes both local properties and allOf properties without resetting the existing list.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.