Skip to content

[BUG] Generated code references non-existent classes on "duplicate" property definitions #24817

Description

@bvschaik

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

Given the following openapi spec: https://github.com/bvschaik/openapi-nonexistent-class-reproducer/blob/main/spec.json

  • One definition of catName as string in CatFields, with title "Given name"
  • One Cat with a name property that references CatFields/catName
  • One definition of dogName as string in DogFields, also with title "Given name"
  • One Dog with a nickname property that references DogFields/dogName

The issue: starting from the OpenAPI generator 7.23.0, this generates a Java Dog class with a property nickname of type DogName. The DogName class is not generated:

public class Dog  {
  @JsonbProperty("nickname")
  protected DogName nickname = null;
  ...
}

In 7.22.0 and lower, the Dog class just has a nickname property of String:

public class Dog  {
  @JsonbProperty("nickname")
  protected String nickname;
  ...
}

Observations:

  • If I change the title of either of the field definitions, the issue is not there.
  • If I change the type of one of the fields to for example integer, the issue is not there.

Conclusion:

If there are two field definitions with the same type and the same title, the OpenAPI generator will generate code using non-existent classes for one of them.

openapi-generator version

Tested and breaks in: 7.23.0, 7.25.0, latest master

This is a regression: it works fine in 7.22.0

OpenAPI declaration file content or url

https://github.com/bvschaik/openapi-nonexistent-class-reproducer/blob/main/spec.json

Generation Details

Use any typed language (tested with Java, Kotlin):

java -jar openapi-generator.jar generate -g java -i https://raw.githubusercontent.com/bvschaik/openapi-nonexistent-class-reproducer/refs/heads/main/spec.json

Steps to reproduce
  1. Generate spec using command above
  2. Inspect the Cat and Dog classes - Dog has a property of type DogName, which doesn't exist
  3. Compile the code - fails
Related issues/PRs

Might be related to: #24004

Suggest a fix

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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