Skip to content

NPEs when using @ParameterGroup with custom Pageable and adding descriptions to fields #1333

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
arjunchhabra-invitae opened this issue Nov 11, 2021 · 5 comments
Labels
bug Something isn't working

Comments

@arjunchhabra-invitae
Copy link

Describe the bug

  • When using a custom class that extends from Pageable and receiving it with @ParameterGroup at an endpoint, if you attempt to annotate a field with a description within that class, you will receive an NPE when accessing the generated docs and return a 500.
  • If you use this same class as a @ParameterGroup but remove the reference to Pageable, the docs are generated correctly and the descriptions are displaye.

To Reproduce
Steps to reproduce the behavior:

  • What version of spring-boot you are using? 2.5.5
  • What modules and versions of springdoc-openapi are you using? 1.5.12
  • What is the actual and the expected result using OpenAPI Description (yml or json)? Expect actual yml/json generation, but receive a 500
  • Provide with a sample code (HelloController) or Test that reproduces the problem

in Controller.kt...

    @GetMapping
    fun getSomething(@ParameterObject example: ExampleClass) {

in ExampleClass.kt...

data class ExampleClass (
    @field:Parameter(description = "Anything")
    val something: Int = 0
) : Pageable {

    override fun getPageNumber(): Int {
        TODO("Not yet implemented")
    }

    override fun getPageSize(): Int {
        TODO("Not yet implemented")
    }

    override fun getOffset(): Long {
        TODO("Not yet implemented")
    }

    override fun getSort(): Sort {
        TODO("Not yet implemented")
    }

    override fun next(): Pageable {
        TODO("Not yet implemented")
    }

    override fun previousOrFirst(): Pageable {
        TODO("Not yet implemented")
    }

    override fun first(): Pageable {
        TODO("Not yet implemented")
    }

    override fun withPage(pageNumber: Int): Pageable {
        TODO("Not yet implemented")
    }

    override fun hasPrevious(): Boolean {
        TODO("Not yet implemented")
    }
}

in ExampleClass2.kt...

data class ExampleClass2 (
    @field:Parameter(description = "Anything")
    val something: Int = 0
)

The above will fail with 500. If you replace ExampleClass with ExampleClass2 in Controller.kt, the docs will generate and include the description.

@bnasslahsen
Copy link
Collaborator

@arjun-chhabra,

Not reproducible.
Make sure you provide a minimal reproducible simple as described in the contribution guide.
This ticket will be closed and can be reopened if the relevant information are provided.

@arjunchhabra-invitae

This comment has been minimized.

@arjunchhabra-invitae
Copy link
Author

@bnasslahsen

Here is a self contained reproducer project.

exampleProject.zip

If you stand up the server with ./gradlew bootRun and access the docs, you should receive an NPE and a HTTP500.

If you replace ExamplePageable with ExampleNonPageable in ExampleController, the issue will resolve and the docs will be generated as expected.

Thank you again for your attention into this matter and my apologies if I am simply misconfiguring something.

bnasslahsen added a commit that referenced this issue Nov 11, 2021
@bnasslahsen
Copy link
Collaborator

@arjun-chhabra,

This will be fixed with the next release.
You can already validate the fix, using the latest SNAPSHOT.

@arjunchhabra-invitae
Copy link
Author

Thank you for the quick turnaround on this @bnasslahsen! Much appreciated!

@bnasslahsen bnasslahsen added the bug Something isn't working label Jan 10, 2022
mpleine pushed a commit to mpleine/springdoc-openapi that referenced this issue May 17, 2025
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