Reputation: 3336
I need to define a swagger property that doesn't have a known name.
{
"type": "object",
"properties": {
"?????": {
"type": "array",
"items": { "$ref": "#/definitions/ModelRelease" }
}
}
The ????? portion of my definition is an integer of an unknown value. Any ideas?
Upvotes: 27
Views: 19954
Reputation: 5331
You could use additionalProperties
to define a hashmap ("?????" being a key in this hashmap without the need to define it):
{
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"$ref": "#/definitions/ModelRelease"
}
}
}
In the general case, hashmaps can have an arbitrary number of items, but you can use minProperties
and maxProperties
to limit the item count. For example, if your object must have just one property:
{
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"$ref": "#/definitions/ModelRelease"
}
},
"minProperties": 1,
"maxProperties": 1
}
Upvotes: 40