GET requests that use complex objects
See original GitHub issueHey 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:
- Created 6 years ago
- Reactions:10
- Comments:13 (4 by maintainers)
Top GitHub Comments
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).
Hi. I assume no updates on this perhaps?