question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for @ParameterObject with POST endpoints

See original GitHub issue

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 https://github.com/springdoc/springdoc-openapi/pull/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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bnasslahsencommented, Jun 2, 2020

@jarpz,

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

0reactions
jarpzcommented, 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

Read more comments on GitHub >

github_iconTop Results From Across the Web

POST body parameter object - Stack Overflow
There is two way to put parameters with POST request. First, you can use the @FieldMap, check out the link Retrofit Javadoc, the...
Read more >
REST API Design Best Practices for Parameter and Query ...
The simplest way to add in all parameter data is to put everything in the body. Many APIs work this way. Every endpoint...
Read more >
Creating request parameters via REST API - Ivanti Community
I guess one way to do it would be to create the params directly in the Service Req Parameter object and linking them...
Read more >
Documenting a Spring REST API Using OpenAPI 3.0 - Baeldung
Learn how to generate OpenAPI 3.0 specifications for a Spring REST API using SpringDoc.
Read more >
OpenAPI Specification - Version 3.0.3 - Swagger
The OpenAPI Specification defines a standard interface to RESTful APIs which allows both humans and computers to understand service capabilities without ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found