1

I have a Web API which returns a object that contains a dictionary property with integer keys:

public Dictionary<int, string> Roles { get; set; }

I use Swashbuckle to publish it into OpenAPI/Swagger format and this is what I get:

"Roles": {
  "type": "object",
  "additionalProperties": {
    "type": "string"
  }
}

I am not really sure this is correct? As there is no indication that my dictionary key is an integer.

How can represent my dictionary correctly in OpenAPI?

Helen
  • 87,344
  • 17
  • 243
  • 314
daxu
  • 3,514
  • 5
  • 38
  • 76

1 Answers1

4

It's not supported because in the JSON objects/(dictionaries) the keys have to be strings.

Another SO Answer

Community
  • 1
  • 1
Tóth Tibor
  • 1,526
  • 12
  • 21