Roles are currently specified in the Meta class of kim.serializers.Serializer. They provide a way to affect the fields used at run time in different scenarios. Equally they provide the user with a way to affect which fields are relevant for marshaling/serializing when operating on related objects and data structures.
This has ultimately made the Serializer class more powerful than the underlying mapping that it constructs which was not the original intention. Serializer should remain as syntactic sugar for easily creating Mapping objects in a re-usable way.
This enhancement will allow Mapping objects to accept and make use of roles as a way to manage which Types are mapped. Any Roles defined on the Serializer therefore are just the way to define a role on mapping.
Mapping would then define a method get_iterable which is called with an optional role identifier as a kwarg that would return a mapping constructed from the role or the default (all fields)
Serializer would simply pass any provided role straight onto the underlying mapping here
Roles are currently specified in the Meta class of
kim.serializers.Serializer
. They provide a way to affect the fields used at run time in different scenarios. Equally they provide the user with a way to affect which fields are relevant for marshaling/serializing when operating on related objects and data structures.This has ultimately made the
Serializer
class more powerful than the underlying mapping that it constructs which was not the original intention.Serializer
should remain as syntactic sugar for easily creating Mapping objects in a re-usable way.This enhancement will allow
Mapping
objects to accept and make use of roles as a way to manage which Types are mapped. Any Roles defined on theSerializer
therefore are just the way to define a role on mapping.https://github.com/mikeywaites/kim/blob/master/kim/mapping.py#L15 would accept a new
roles
kwarg which would contain a collection of Role objects as seen previously in the Serializer class.Mapping
would then define a methodget_iterable
which is called with an optionalrole
identifier as a kwarg that would return a mapping constructed from therole
or the default (all fields)Serializer
would simply pass any provided role straight onto the underlying mapping herehttps://github.com/mikeywaites/kim/blob/master/kim/serializers.py#L178