Dorthu / openapi3

A Python3 OpenAPI 3 Spec Parser
BSD 3-Clause "New" or "Revised" License
118 stars 47 forks source link

Support schema of a JSON object has no properties defined #70

Closed strainu closed 2 years ago

strainu commented 2 years ago

Is your feature request related to a problem? Please describe. I'm trying to parse the following the following spec:

"MyType": {
  "type":"object",
  "properties":{
    "page":{
      "type":"integer",
      "format":"int32"
    },
    "data":{
      "type":"object"
    }
  }
}

This fails with:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\strainu\code\apliclient\datamodel.py", line 61, in get
    return self.api.call_queryAllNodeTypes()
  File "C:\Python39\lib\site-packages\openapi3\openapi.py", line 242, in __call__
    return self.operation(self.base_url, *args, security=self.security, **kwargs)
  File "C:\Python39\lib\site-packages\openapi3\paths.py", line 397, in request
    return expected_media.schema.model(result.json())
  File "C:\Python39\lib\site-packages\openapi3\schemas.py", line 157, in model
    return self.get_type()(data, self)
  File "C:\Python39\lib\site-packages\openapi3\schemas.py", line 297, in __init__
    setattr(self, k, object_schema.model(v))
  File "C:\Python39\lib\site-packages\openapi3\schemas.py", line 157, in model
    return self.get_type()(data, self)
  File "C:\Python39\lib\site-packages\openapi3\schemas.py", line 134, in get_type
    {"__slots__": self.properties.keys()},  # pylint: disable=attribute-defined-outside-init
AttributeError: 'NoneType' object has no attribute 'keys'

Fixing this immediate error exposes other follow-up errors.

Describe the solution you'd like I would like to have support for such schemas, as they are standard-compliant. I am aware that this is considered a security risk

Dorthu commented 2 years ago

I agree that this should be supported, and seems related the discussion on additionalProperties in https://github.com/Dorthu/openapi3/pull/63.