(self, obj, field, pytype)
return json_schema
Get schema definition from python type.
Get schema definition from python type.
Get schema definition from python type .
def _from_python_type(self, obj, field, pytype) -> typing.Dict[str, typing.Any]:
        """Get schema definition from python type."""
        json_schema = {"title": field.attribute or field.name or ""}

        for key, val in PY_TO_JSON_TYPES_MAP[pytype].items():
            json_schema[key] = val

        if field.dump_only:
            json_schema["readOnly"] = True

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

        if ALLOW_ENUMS and isinstance(field, EnumField):
            json_schema["enum"] = self._get_enum_values(field)

        if field.allow_none:
            previous_type = json_schema["type"]
            json_schema["type"] = [previous_type, "null"]

        # 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
            json_schema[md_key] = md_val

        if isinstance(field, fields.List):
            json_schema["items"] = self._get_schema_for_field(obj, field.inner)

        if isinstance(field, fields.Dict):
            json_schema["additionalProperties"] = (
                self._get_schema_for_field(obj, field.value_field)
                if field.value_field
                else {}
            )
        return json_schema
def _from_python_type ( self , obj , field , pytype ) -> typing . Dict [ str , typing . Any ] : json_schema = { "title" : field . attribute or field . name or "" } for key , val in PY_TO_JSON_TYPES_MAP [ pytype ] . items ( ) : json_schema [ key ] = val if field . dump_only : json_schema [ "readOnly" ] = True if field . default is not missing and not callable ( field . default ) : json_schema [ "default" ] = field . default if ALLOW_ENUMS and isinstance ( field , EnumField ) : json_schema [ "enum" ] = self . _get_enum_values ( field ) if field . allow_none : previous_type = json_schema [ "type" ] json_schema [ "type" ] = [ previous_type , "null" ] # 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 json_schema [ md_key ] = md_val if isinstance ( field , fields . List ) : json_schema [ "items" ] = self . _get_schema_for_field ( obj , field . inner ) if isinstance ( field , fields . Dict ) : json_schema [ "additionalProperties" ] = ( self . _get_schema_for_field ( obj , field . value_field ) if field . value_field else { } ) return json_schema