One of my HttpGet methods has a [FromUri] parameter, a POCO class that contains some properties that serve as optional filter to fetch database info.
When I try "AutoRest.exe -Input v1 -Namespace API -OutputDirectory API", I get the following error:
[HttpGet]
[Route("/api/calendar")]
public CalendarEvent[] Get([FromUri]GetCalendarEvents filters)
{
return _dao.Get(filters);
}
public class GetCalendarEvents
{
public DateTime? Date { get; set; }
public string Title { get; set; }
}
{
"swagger": "2.0",
"info": {
"version": "v1",
"title": "API"
},
"host": "localhost",
"schemes": ["http"],
"paths": {
"/api/calendar": {
"get": {
"tags": ["Calendar"],
"operationId": "Calendar_Get",
"consumes": [],
"produces": ["application/json", "text/json", "application/xml", "text/xml"],
"parameters": [{
"name": "filters.date",
"in": "query",
"required": false,
"type": "string",
"format": "date-time"
},
{
"name": "filters.title",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "Authorization",
"in": "header",
"required": true,
"type": "string"
}],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/CalendarEvent"
}
}
}
},
"deprecated": false
}
}
},
"definitions": {
"GetCalendarEvents": {
"type": "object",
"properties": {
"Date": {
"format": "date-time",
"type": "string"
},
"Title": {
"type": "string"
}
}
},
"CalendarEvent": {
"type": "object",
"properties": {
"Id": {
"format": "int32",
"type": "integer"
},
"Date": {
"format": "date-time",
"type": "string"
},
"Title": {
"type": "string"
}
}
}
}
}
To every method I added a http header 'Authorization' (as seen on swagger spec) to authorization.
It seems to me that AutoRest doesn't support complex class on query.
An alternative solution would be declaring all filters explicitly as parameters like this:
[HttpGet]
[Route("/api/calendar")]
public CalendarEvent[] Get(DateTime? date, string title)
{
...
}
But this is out of the question to me as I'll have many filters not just these two.
Is there other way to fix this?