You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is the correct description. Remember that Swagger is describing JSON structures and not C# types. In JSON, there's no equivalent of Dictionary<int, string>. The closest representation would be the following:
{
"1": "foo",
"2": "bar"
}
And sure enough if you return an object of this type from a WebAPI action, it will be serialized exactly like this - try for yourself. Furthermore, the JSON Schema that Swashbuckle is generating describes this structure accurately:
I have a web api which returns a object that contains dictionary property
public Dictionary<int, string> Roles { get; set; }
I use swashbuckle to publish it into swagger format and this is what I get:
"Roles":{"type":"object","additionalProperties":{"type":"string"}}
I am not really sure this is correct? As I thought at least it should be something like
"Roles":{"type":"object","additionalProperties":{"type":"int", "type":"string"}}
How can represent my dictionary correctly in swagger format?
The text was updated successfully, but these errors were encountered: