Skip to content

When using ParameterObject, description is taken from superclass instead of subclass #2784

Closed
@MosheElisha

Description

@MosheElisha

Describe the bug

When I use @ParameterObject the OpenAPI spec schema description of the fields is taken from the super class and not from the subclass.

@PostMapping("/parameter-object")
public Application createWithParameterObject(
         @RequestBody @Valid @ParameterObject @Parameter(description = "The request") SubClass request
);

SuperClass:

public class SuperClass {
    @Size(min = 1, max = 30)
    @Schema(description = "Description from the super class")
    private String name;

SubClass:

@Schema(description = "Used to create a new application")
public class SubClass extends SuperClass {

    public SubClass(String name) {
        super(name);
    }

    @Override
    @Schema(description = "Overriding the description in sub class")
    public String getName() {
        return super.getName();
    }
}

To Reproduce
Steps to reproduce the behavior:

  • What version of spring-boot you are using?
    3.3.5 (also tried with 3.2.2)

  • What modules and versions of springdoc-openapi are you using?
    springdoc-openapi-starter-webmvc-ui=2.6.0

  • What is the actual and the expected result using OpenAPI Description (yml or json)?
    actual.json

  • Provide with a sample code (HelloController) or Test that reproduces the problem
    spring-demo.zip

Expected behavior

  • A clear and concise description of what you expected to happen.
    Expectation is that the subclass can override the schema definition like it works when not using @ParameterObject. The description of the SubClass.name field should be "Overriding the description in sub class" instead of "Description from the super class".

  • What is the expected result using OpenAPI Description (yml or json)?
    expected.json

Screenshots

With ParameterObject:

image

Without ParameterObject (works as expected):

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions