Skip to content

SpringDoc Incorrectly Generates Schema When Using Record Named "Item" #2907

@MikeMJ

Description

@MikeMJ

Describe the bug

I encountered an issue with SpringDoc OpenAPI when using a Java record named Item. The generated schema incorrectly places the reason field from the Serial record as a direct field of Item, while the serial field is completely ignored. Additionally, the Serial record is not documented as a separate schema at all.

Example record definition:

public record Item(
    String itemNo,
    String material,
    String quantity,
    List<Serial> serials
) {}

public record Serial(
    String serial,
    String reason
) {}

However, when I rename Item to Item2, the schema is generated correctly. This suggests a possible naming conflict affecting schema generation.

Could you please confirm whether this is a bug or an expected limitation?

Let me know if you need more details or sample output.

To Reproduce
Steps to reproduce the behavior:

  • Spring boot: 3.2.0
  • 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0'
  • Expected and actual attached as files

actual.txt

expected.txt

Below are the sample records and the controller that uses the wrapper one. (Item)

public record Item(
    String itemNo,
    String material,
    String quantity,
    List<Serial> serials
) {}

public record Serial(
    String serial,
    String reason
) {}

@RestController
public class ItemsController{
   public void add(@RequestBody Item item){
   }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidThis doesn't seem right

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions