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.

GET requests that use complex objects

See original GitHub issue

Hey all,

I can’t seem to find a proper solution to dealing with GET requests that use a complex request object rather than individual method calls. Swashbuckle seems to do some flattening of the query parameters already but it prepends the variable name specified in the GET request. For some reason, it also generates a definition for the complex request object but doesn’t use it - which leads to swagger warnings. I did find one other issue which seems to be referencing the same: https://github.com/domaindrivendev/Swashbuckle/issues/70 and https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/66 but I could not find anything in the 5.0 documentation that would lead me to believe this is already handled within Swashbuckle.

Example method:

When using:

[HttpGet]
public async Task<IHttpActionResult> GetThings(GetThingsRequest queryParameters) {}

instead of:

[HttpGet]
public async Task<IHttpActionResult> GetThings(int[] ids, string name, int pageNumber) {}

results in schema:

paths: {
    "/api/things": {
      "get": {
        "summary": "Get some things",
        "operationId": "getThings",
        "parameters": [
          {
            "name": "queryParameters.ids",
            "in": "query",
            "description": "The ids to reference",
          }
    }
}
...
definitions: {
    "GetThingsRequest": {
      "type": "object",
      "properties": {
        "ids": {
          "description": "The list of id's to filter by",
          "type": "array",
          "items": {
            "format": "int32",
            "type": "integer"
          }
        },
        "name": {
          "format": "date-time",
          "description": "The date to filter by",
          "type": "string"
        },
    }
}
...

But really instead of “queryParameters.ids” it should be defining just “ids” as the parameter. Is there a way to do this without invoking a custom OperationFilter?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:10
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
replaysMikecommented, Mar 24, 2017

https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/66 seems to reference that using the [FromUri] attribute on a property will work, but under .Net Web API 2 that attribute can only be applied to Class and Parameters as per https://msdn.microsoft.com/en-us/library/system.web.http.fromuriattribute(v=vs.118).aspx

Maybe this is specific to .Net core? (yes, yes it is).

1reaction
tihomir-kitcommented, Mar 7, 2020

Hi. I assume no updates on this perhaps?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to make GET request with a complex object?
You can pass it as a stringified json or use the request body via post instead of get. Share.
Read more >
What is a proper way to do a complex RESTful search ...
Simply go with a POST request with parameters as provided by the user in order to get the information you require from the...
Read more >
ASP.NET Core 2.2: Complex Object as Parameter in a HttpGet
Is it possible to use a complex object as a parameter of an HttpGet action in ASP.NET Core? Yes, it is. We must...
Read more >
best practice posting complex object to api
It is best practice to implement your use-cases as simply/easy as possible, that means preferably with one call.
Read more >
How do I send a complex JSON in an HTTP GET request?
The only way to send data via a get request is by using URL query string parameters. If you want to send JSON...
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