-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for additionalProperties #63
base: master
Are you sure you want to change the base?
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,
additionalProperties
andproperties
can both be specified, or only one of them.When a schema defines additionalProperties, no
__slots__
is set in the generatedModel
class, 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.