Reputation: 6692
I want to define an object with a key and a value but can't figure out how to define it as a property in a swagger 2.0 definition. Frankly, I am not sure if this is even possible if one wants to be able to define strongly typed clients. However, I figure I'd ask to see if this is even possible/allowable.
Basically, I want to be able to store the following object:
{ "currencies":
{ "usd" : 1.10,
"eur" : 2.25
}
}
But I don't want usd, and eur to have to be defined in the schema. I can do the below but I don't want usd or eur to be predefined. I want it to accept any value for the keys of the object.
"Product": {
"properties": {
"currencies": {
"type": "currencyObj"
},
}
},
},
"currencyObj": {
"id": "currencyObj",
"properties": {
"eur": {
"type": "float"
},
"usd": {
"type": "float"
}
}
}
Upvotes: 1
Views: 1935
Reputation: 5441
Swagger 2.0 allows you to define a string to type mapping, you need to use additionalProperties. Use following notation to define a map :
"currencyObj": {
"type": "object",
"additionalProperties": {
"type": "number"
}
}
Upvotes: 2