Conversation
|
Thanks for the submission! Looking at the OpenAPI definition and the relevant parts of JSON Schema, it looks like I'm going to do more research as to how to interpret what the intended behavior is. However, testing this change, I notice some inconsistencies between the behavior of classes with In [4]: # r has additionalProperties set to true
...: print(r)
{}
In [5]: # lt does not
...: print(lt)
{'id': 'g6-nanode-1', 'label': 'Nanode 1GB', 'disk': 25600, 'class': 'nanode', 'price': {'hourly': 0.0075, 'monthly': 5.0}, 'addons': {'backups': {'price': {'hourly': 0.003, 'monthly': 2.0}}}, 'network_out': 1000, 'memory': 1024, 'successor': None, 'transfer': 1000, 'vcpus': 1, 'gpus': 0}
In [6]: r.__slots__
Out[6]: ['_raw_data', '_schema']
In [7]: lt.__slots__
Out[7]: dict_keys(['id', 'label', 'disk', 'class', 'price', 'addons', 'network_out', 'memory', 'successor', 'transfer', 'vcpus', 'gpus'])
In [8]: r._schema
In [9]: lt._schema
Out[9]: <<class 'openapi3.schemas.Schema'> ['components', 'schemas', 'LinodeType']>
In [10]: r._raw_data
In [11]: lt._raw_data
Out[11]:
{'id': 'g6-nanode-1',
'label': 'Nanode 1GB',
'price': {'hourly': 0.0075, 'monthly': 5.0},
'addons': {'backups': {'price': {'hourly': 0.003, 'monthly': 2.0}}},
'memory': 1024,
'disk': 25600,
'transfer': 1000,
'vcpus': 1,
'gpus': 0,
'network_out': 1000,
'class': 'nanode',
'successor': None}I think that at the very least, these should behave the same way when used as above. |
|
https://github.com/APIs-guru/openapi-directory/search?q=additionalProperties I'm rolling with |
The swagger.io spec (https://swagger.io/specification/#properties) does note the following:
The Understanding JSON article does note:
So this would imply that |
|
Thanks for the excellent references @chriswhite199. In light of that, I think the correct behavior is to:
|
This pull request adds support for validation of OpenAPI specs that make use of the additionalProperties feature.
For an type=object,
additionalPropertiesandpropertiescan both be specified, or only one of them.When a schema defines additionalProperties, no
__slots__is set in the generatedModelclass, so that the additional attributes can be stored in the__dict__of the instance. As with normal properties, no type checking for string/int/... is performed.