@@ -724,20 +724,13 @@ def model_validate(
724724 kwargs .setdefault ("context" , {}).setdefault ("scim" , scim_ctx )
725725 return super ().model_validate (* args , ** kwargs )
726726
727- def model_dump (
727+ def _prepare_model_dump (
728728 self ,
729- * args ,
730729 scim_ctx : Optional [Context ] = Context .DEFAULT ,
731730 attributes : Optional [list [str ]] = None ,
732731 excluded_attributes : Optional [list [str ]] = None ,
733732 ** kwargs ,
734- ) -> dict :
735- """Create a model representation that can be included in SCIM messages by using Pydantic :code:`BaseModel.model_dump`.
736-
737- :param scim_ctx: If a SCIM context is passed, some default values of
738- Pydantic :code:`BaseModel.model_dump` are tuned to generate valid SCIM
739- messages. Pass :data:`None` to get the default Pydantic behavior.
740- """
733+ ):
741734 kwargs .setdefault ("context" , {}).setdefault ("scim" , scim_ctx )
742735 kwargs ["context" ]["scim_attributes" ] = [
743736 validate_attribute_urn (attribute , self .__class__ )
@@ -751,9 +744,48 @@ def model_dump(
751744 if scim_ctx :
752745 kwargs .setdefault ("exclude_none" , True )
753746 kwargs .setdefault ("by_alias" , True )
754- kwargs .setdefault ("mode" , "json" )
755747
756- return super ().model_dump (* args , ** kwargs )
748+ return kwargs
749+
750+ def model_dump (
751+ self ,
752+ * args ,
753+ scim_ctx : Optional [Context ] = Context .DEFAULT ,
754+ attributes : Optional [list [str ]] = None ,
755+ excluded_attributes : Optional [list [str ]] = None ,
756+ ** kwargs ,
757+ ) -> dict :
758+ """Create a model representation that can be included in SCIM messages by using Pydantic :code:`BaseModel.model_dump`.
759+
760+ :param scim_ctx: If a SCIM context is passed, some default values of
761+ Pydantic :code:`BaseModel.model_dump` are tuned to generate valid SCIM
762+ messages. Pass :data:`None` to get the default Pydantic behavior.
763+ """
764+ dump_kwargs = self ._prepare_model_dump (
765+ scim_ctx , attributes , excluded_attributes , ** kwargs
766+ )
767+ if scim_ctx :
768+ dump_kwargs .setdefault ("mode" , "json" )
769+ return super ().model_dump (* args , ** dump_kwargs )
770+
771+ def model_dump_json (
772+ self ,
773+ * args ,
774+ scim_ctx : Optional [Context ] = Context .DEFAULT ,
775+ attributes : Optional [list [str ]] = None ,
776+ excluded_attributes : Optional [list [str ]] = None ,
777+ ** kwargs ,
778+ ) -> dict :
779+ """Create a JSON model representation that can be included in SCIM messages by using Pydantic :code:`BaseModel.model_dump_json`.
780+
781+ :param scim_ctx: If a SCIM context is passed, some default values of
782+ Pydantic :code:`BaseModel.model_dump` are tuned to generate valid SCIM
783+ messages. Pass :data:`None` to get the default Pydantic behavior.
784+ """
785+ dump_kwargs = self ._prepare_model_dump (
786+ scim_ctx , attributes , excluded_attributes , ** kwargs
787+ )
788+ return super ().model_dump_json (* args , ** dump_kwargs )
757789
758790 def get_attribute_urn (self , field_name : str ) -> str :
759791 """Build the full URN of the attribute.
0 commit comments