While creating OpenAPI 3.0 I need to define a key value pair with value having two fields, first integer and second string like: user: priority, status
(e.g. 'user1': 3, 'available'
). How can I combine two primitive data types for the value? How can I define it's schema?
Asked
Active
Viewed 3,204 times
0

Techie Fort
- 422
- 7
- 18
-
Does this answer your question? [How to define a JSON array with concrete item definition for every index (i.e. a tuple) in OpenAPI?](https://stackoverflow.com/q/57464633/113116) – Helen Jun 18 '21 at 13:08
1 Answers
2
To define a key-value pair, you can use the "additionalProperties"
keyword:
{
"type": "object",
"additionalProperties": {
"type": "object",
"properties": {
"priority": "{"type": "integer"},
"status": {"type": "string"}
}
}
}
This means that the root value should be an object, with no defined properties in "properties"
. But every property value, that isn't defined in "properties"
, should be an object with the two properties you need.
The relevant section of the json schema spec: additionalProperties

erosb
- 2,943
- 15
- 22