Skip to content

Commit

Permalink
Fixed schemas without properties failing to generate models
Browse files Browse the repository at this point in the history
A Schema defined as:

```
example:
  type: object
```

should generate a Model named `example` with no `__slots__`.

This change allows generation of a model as described, and
closes #70.
  • Loading branch information
Dorthu committed Feb 4, 2022
1 parent d4456c9 commit 80d383f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion openapi3/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,14 @@ def get_type(self):
# this is defined in ObjectBase.__init__ as all slots are
if self._model_type is None: # pylint: disable=access-member-before-definition
type_name = self.title or self.path[-1]
# if there are no defined properites for this model, use an empty dict
# to allow the model to be set up correctly
model_properties = self.properties or {}

self._model_type = type(
type_name,
(Model,),
{"__slots__": self.properties.keys()}, # pylint: disable=attribute-defined-outside-init
{"__slots__": model_properties.keys()}, # pylint: disable=attribute-defined-outside-init
)

return self._model_type
Expand Down

0 comments on commit 80d383f

Please sign in to comment.