(self, obj, field)
return schema
Support nested field.
Support nested field.
Support nested field .
def _from_nested_schema(self, obj, field):
        """Support nested field."""
        if isinstance(field.nested, (str, bytes)):
            nested = get_class(field.nested)
        else:
            nested = field.nested

        if isclass(nested) and issubclass(nested, Schema):
            name = nested.__name__
            only = field.only
            exclude = field.exclude
            nested_cls = nested
            nested_instance = nested(only=only, exclude=exclude, context=obj.context)
        else:
            nested_cls = nested.__class__
            name = nested_cls.__name__
            nested_instance = nested

        outer_name = obj.__class__.__name__
        # If this is not a schema we've seen, and it's not this schema (checking this for recursive schemas),
        # put it in our list of schema defs
        if name not in self._nested_schema_classes and name != outer_name:
            wrapped_nested = self.__class__(nested=True)
            wrapped_dumped = wrapped_nested.dump(nested_instance)

            wrapped_dumped["additionalProperties"] = _resolve_additional_properties(
                nested_cls
            )

            self._nested_schema_classes[name] = wrapped_dumped

            self._nested_schema_classes.update(wrapped_nested._nested_schema_classes)

        # and the schema is just a reference to the def
        schema = {"type": "object", "$ref": "#/definitions/{}".format(name)}

        # NOTE: doubled up to maintain backwards compatibility
        metadata = field.metadata.get("metadata", {})
        metadata.update(field.metadata)

        for md_key, md_val in metadata.items():
            if md_key in ("metadata", "name"):
                continue
            schema[md_key] = md_val

        if field.default is not missing and not callable(field.default):
            schema["default"] = nested_instance.dump(field.default)

        if field.many:
            schema = {
                "type": "array" if field.required else ["array", "null"],
                "items": schema,
            }

        return schema
def _from_nested_schema ( self , obj , field ) : if isinstance ( field . nested , ( str , bytes ) ) : nested = get_class ( field . nested ) else : nested = field . nested if isclass ( nested ) and issubclass ( nested , Schema ) : name = nested . __name__ only = field . only exclude = field . exclude nested_cls = nested nested_instance = nested ( only = only , exclude = exclude , context = obj . context ) else : nested_cls = nested . __class__ name = nested_cls . __name__ nested_instance = nested outer_name = obj . __class__ . __name__ # If this is not a schema we've seen, and it's not this schema (checking this for recursive schemas), # put it in our list of schema defs if name not in self . _nested_schema_classes and name != outer_name : wrapped_nested = self . __class__ ( nested = True ) wrapped_dumped = wrapped_nested . dump ( nested_instance ) wrapped_dumped [ "additionalProperties" ] = _resolve_additional_properties ( nested_cls ) self . _nested_schema_classes [ name ] = wrapped_dumped self . _nested_schema_classes . update ( wrapped_nested . _nested_schema_classes ) # and the schema is just a reference to the def schema = { "type" : "object" , "$ref" : "#/definitions/{}" . format ( name ) } # NOTE: doubled up to maintain backwards compatibility metadata = field . metadata . get ( "metadata" , { } ) metadata . update ( field . metadata ) for md_key , md_val in metadata . items ( ) : if md_key in ( "metadata" , "name" ) : continue schema [ md_key ] = md_val if field . default is not missing and not callable ( field . default ) : schema [ "default" ] = nested_instance . dump ( field . default ) if field . many : schema = { "type" : "array" if field . required else [ "array" , "null" ] , "items" : schema , } return schema