Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MikeMJ opened this issue Feb 19, 2025 · 1 comment
Open

Comments

@MikeMJ
Copy link

MikeMJ commented Feb 19, 2025

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){
   }
}
@MikeMJ
Copy link
Author

MikeMJ commented Feb 19, 2025

Document generated with record named "Item"
Image

Document generated with record named "Item2:
Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant