Skip to content

[BUG][spring] schema with both $ref and type: object sometimes results in $ref being ignored #24710

Description

@anthonyvdotbe

Bug Report Checklist

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

For a property like the following:

lifeCycle:
  type: object
  $ref: "LifeCycle"

the generated code might end up using java.lang.Object as the type instead of the generated LifeCycle model.

openapi-generator version

7.24.0

OpenAPI declaration file content or url

openapi.yaml

Generation Details

config.json

Steps to reproduce
  • in a directory X, create openapi.yaml and config.json with the contents as above
  • from within X, run docker run --rm -v .:/local openapitools/openapi-generator-cli:v7.24.0 generate --strict-spec true --input-spec /local/openapi.yaml --generator-name spring --config /local/config.json --output /local/output
  • open the generated BankAccount model: ./output/src/main/java/org/openapitools/model/BankAccount.java

actual: private @Nullable Object lifeCycle = null;
expected: private @Nullable LifeCycle lifeCycle;

Related issues/PRs

#13295

Suggest a fix

Note that the allOf is required to reproduce the bug.

OpenAPINormalizer logs a warning:

[main] WARN o.o.codegen.OpenAPINormalizer - Type(s) cleared (set to null) given $ref is set to #/components/schemas/LifeCycle.

The related issue is not tied to a specific generator, so I assume this issue is generic as well.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions