Search code examples
javaspring-bootswaggerspringdoc-openapi-ui

Convert object into multi query parameter Swagger


I'm trying to generate swagger documentation with query parameters from an object but I'm not sure if it's possible with springdoc-openapi. I know this is possible with io.springfox.

What I want is to create a single object, add all the fields to this object and then have these fields presented in the swagger documentation as individual query parameters.

E.g of test cases:

  1. Test case 1
    For following code:
    enter image description here
    The following swagger documentation is generated:
    enter image description here

  2. Test case 2: For the following code:
    enter image description here
    The following swagger documentation is generated:
    enter image description here

In both situations the services works as expected with query parameters. What I want is to have code from test case 2 to generate the same documentation from test case 1. I know this is possible with springfox but I can not figure out how to do it in springdoc-openapi.


Solution

  • To achieve this, you need to decorate the TestCase class with the @ParameterObject annotation :

    @ParameterObject
    public class TestCase {
        @Parameter
        String field1;
        @Parameter
        String field2;
        @Parameter
        String field1;
    }