daxu
daxu

Reputation: 4074

How to represent a C# Dictionary<int, string> in OpenAPI?

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?

Upvotes: 2

Views: 6701

Answers (1)

T&#243;th Tibor
T&#243;th Tibor

Reputation: 1565

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

Another SO Answer

Upvotes: 5

Related Questions