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

Closed
MikeMJ opened this issue Feb 19, 2025 · 2 comments
Closed

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

MikeMJ opened this issue Feb 19, 2025 · 2 comments
Labels
invalid This doesn't seem right

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

@bnasslahsen
Copy link
Collaborator

@MikeMJ,

This the generated spec, with the latest release:

openapi: 3.1.0
info:
  title: OpenAPI definition
  version: v0
servers:
  - url: http://localhost:8080
    description: Generated server url
paths:
  /hello:
    get:
      tags:
        - hello-controller
      operationId: getItem
      responses:
        '200':
          description: OK
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/Item'
components:
  schemas:
    Item:
      type: object
      properties:
        itemNo:
          type: string
        material:
          type: string
        quantity:
          type: string
        serials:
          type: array
          items:
            $ref: '#/components/schemas/Serial'
    Serial:
      type: object
      properties:
        serial:
          type: string
        reason:
          type: string

@bnasslahsen bnasslahsen added the invalid This doesn't seem right label Mar 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants