Skip to content

Add support for @ParameterObject with POST endpoints #693

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
svetlana-nikitina opened this issue May 27, 2020 · 6 comments
Closed

Add support for @ParameterObject with POST endpoints #693

svetlana-nikitina opened this issue May 27, 2020 · 6 comments
Labels
enhancement New feature or request

Comments

@svetlana-nikitina
Copy link

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

@bnasslahsen
Copy link
Collaborator

@svetlana-nikitina,

@ParameterObject is designed for HTTP GET Methods.
Please have a look at the documentation:

@svetlana-nikitina
Copy link
Author

@bnasslahsen is there any way to map an object holding query params to query params in swagger for POST? this behaviour is supported by spring and controller itself works fine, but apparently not supported by springdoc-openapi

@bnasslahsen
Copy link
Collaborator

@svetlana-nikitina,

We will add the support for @ParameterObject with POST endpoints for the next release.

@bnasslahsen bnasslahsen changed the title @ParameterObject works not as expected with POST endpoints (@PostMapping) Add support for @ParameterObject with POST endpoints as well May 28, 2020
@bnasslahsen bnasslahsen changed the title Add support for @ParameterObject with POST endpoints as well Add support for @ParameterObject with POST endpoints May 28, 2020
@jarpz
Copy link

jarpz commented Jun 2, 2020

@svetlana-nikitina,

We will add the support for @ParameterObject with POST endpoints for the next release.

Question?, just for post-method? because for put or patch methods are also possible..

Regards

@bnasslahsen
Copy link
Collaborator

@jarpz,

Yes, for other methods you mentionned as well.
This is already deployed with v1.4.0.

@bnasslahsen bnasslahsen added the enhancement New feature or request label Jan 10, 2022
@sh4wn
Copy link

sh4wn commented Mar 31, 2023

How about POST with application/x-www-form-urlencoded conent type?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants