Skip to content

Commit

Permalink
README updated
Browse files Browse the repository at this point in the history
  • Loading branch information
nj-vs-vh committed Feb 18, 2021
1 parent 1daeed9 commit 8d20365
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Building OneOfSchema with a decorator
------------------------------------

When creating "one of" schemas with many options it can become cumbersome to maintain `type_schemas` dict manually.
In this case you can leave it empty at first and register member schemas to your OneOfSchema with the following decorator:
In this case you can leave it empty at first and later register member schemas to your OneOfSchema with the decorator:

.. code:: python
Expand All @@ -148,23 +148,19 @@ By default schemas are named with class name with removed "Schema" suffix, which
class MyUberSchema(OneOfSchema):
type_schemas = {}
@staticmethod
def schema_name(schema_class):
return schema_class._model_class.__name__
return schema_class._ModelClass.__name__
@MyUberSchema.register_one_of
class SchemaForDataClass(marshmallow.Schema):
_model_class = Data
_ModelClass = Data
value = fields.String()
@marshmallow.post_load
def make_data(self, data, **kwargs):
return Data(**data)
print(MyUberSchema.type_schemas)
print(MyUberSchema().dump([Data("something"), Data("something else")], many=True))
# => [{'value': 'something', 'type': 'Data'}, {'value': 'something else', 'type': 'Data'}]
return self._ModelClass(**data)
License
-------
Expand Down

0 comments on commit 8d20365

Please sign in to comment.