Skip to content

Add support for @ParameterObject with POST endpoints #693

Closed
@svetlana-nikitina

Description

@svetlana-nikitina

springdoc-openapi-ui version: 1.3.9

In my spring web endpoint I have an object which summarise query params
To make it work properly, I see @ParameterObject was introduced in #505
It works for GET requests (@GetMapping) -> all properties of object are parsed as separate query parameters

    @GetMapping("/test")
    public void testGet(@ParameterObject QueryObject queryObject) {
    }
    @Getter
    @Setter
    public class QueryObject {
        private String queryParam1;
        private String queryParam2;
    }

UI:
image

json:

  "parameters": [
    {
      "name": "queryParam1",
      "in": "query",
      "required": false,
      "schema": {
        "type": "string"
      }
    },
    {
      "name": "queryParam2",
      "in": "query",
      "required": false,
      "schema": {
        "type": "string"
      }
    }
  ]

However I don't see this behaviour with POST requests
And object holding query params is parsed as BODY object
Example of my code

  @PostMapping("/test")
    public void testPost(@ParameterObject QueryObject queryObject) {
    }

UI:
image

json:

"requestBody": {
    "content": {
      "application/json": {
        "schema": {
          "type": "object",
          "properties": {
            "queryParam1": {
              "type": "string"
            },
            "queryParam2": {
              "type": "string"
            }
          }
        }
      }
    }
  }

Expected behavior
Objects in POST endpoints annotated with @ParameterObject should behave the same way as for GET and all fields of this object are parsed as query params

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions