I am looking at an OpenAPI specification which makes use of additionalProperties
to create a schema that maps user-specified names to objects (the type of object is unimportant). Here is a simplified example of what it is doing:
components:
schemas:
CityData:
type: object
properties:
population:
type: integer
is_capital:
type: boolean
Country:
type: object
properties:
name:
type: string
cities:
type: object
description: A mapping of city names to data about those cities
additionalProperties:
$ref: '#/components/schemas/CityData'
So an example of a Country
object would be:
{ "name": "Germany", "cities": { "Essen": { "population": 583109, "is_capital": false } } }
I know that I can place limits to require that each country has a minimum or maximum number of cities, by using minProperties
and maxProperties
. Is there a way to place any restrictions on the property keys themselves (the city names, in the above example)? For example, what if I wanted to ensure that a city name had between 1-100 characters? Is it possible to restrict the length of the property keys with additionalProperties
?
I realize that this example could be refactored so that the city names were an explicit string property inside of the CityData
schema, in which case it would then be straightforward to impose these restrictions using minLength
and maxLength
. I am working with an existing schema where I do not have the freedom to do such refactoring.
Is any way to encode these restrictions in OpenAPI 3, or if the best that can be done is to verbally communicate them (in the description text, for example).