Skip to content

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

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

Closed
MosheElisha opened this issue Nov 19, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@MosheElisha
Copy link

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

@bnasslahsen bnasslahsen added the bug Something isn't working label Nov 23, 2024
@MosheElisha
Copy link
Author

Thanks, @bnasslahsen ! Much appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants