We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Pydantic __root__ model - incorrect handling
### Describe the bug

https://pydantic-docs.helpmanual.io/usage/models/#custom-root-types
Pydantic allows to create models with only `__root__` field. In such scenario the model behaves as transparent wrapper for this single type.

When such model is used in response (request also?) fastapi does not treat it correctly and renders it as object with `__root__` field.

Object is treated correctly by pydantic itself.

### To Reproduce

```
from typing import List
from fastapi import FastAPI
from pydantic.main import BaseModel

app = FastAPI()


class RootTestClass(BaseModel):
    __root__: List[str]


@app.get("/")
async def root():
    response = RootTestClass(__root__=['a', 'b', 'c'])
    print(response.json())  # ["a", "b", "c"] so it's OK
    print(RootTestClass.schema())  # {'title': 'RootTestClass', 'type': 'array', 'items': {'type': 'string'}} this is also OK
    return response  # Wrong value in http response
```

### Expected behavior

The response should be:
```
["a", "b", "c"]
```

but at the moment is:
```
{"__root__":["a","b","c"]}
```

### Screenshots

N/A

### Environment

- OS: Linux
- FastAPI Version: 0.47.1
- Python version: Python 3.7.5

### Additional context

N/A


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `fastapi/encoders.py`
Content:
```
1 from enum import Enum
2 from pathlib import PurePath
3 from types import GeneratorType
4 from typing import Any, Callable, Dict, List, Set, Tuple, Union
5 
6 from fastapi.logger import logger
7 from fastapi.utils import PYDANTIC_1
8 from pydantic import BaseModel
9 from pydantic.json import ENCODERS_BY_TYPE
10 
11 SetIntStr = Set[Union[int, str]]
12 DictIntStrAny = Dict[Union[int, str], Any]
13 
14 
15 def generate_encoders_by_class_tuples(
16     type_encoder_map: Dict[Any, Callable]
17 ) -> Dict[Callable, Tuple]:
18     encoders_by_classes: Dict[Callable, List] = {}
19     for type_, encoder in type_encoder_map.items():
20         encoders_by_classes.setdefault(encoder, []).append(type_)
21     encoders_by_class_tuples: Dict[Callable, Tuple] = {}
22     for encoder, classes in encoders_by_classes.items():
23         encoders_by_class_tuples[encoder] = tuple(classes)
24     return encoders_by_class_tuples
25 
26 
27 encoders_by_class_tuples = generate_encoders_by_class_tuples(ENCODERS_BY_TYPE)
28 
29 
30 def jsonable_encoder(
31     obj: Any,
32     include: Union[SetIntStr, DictIntStrAny] = None,
33     exclude: Union[SetIntStr, DictIntStrAny] = set(),
34     by_alias: bool = True,
35     skip_defaults: bool = None,
36     exclude_unset: bool = False,
37     exclude_defaults: bool = False,
38     exclude_none: bool = False,
39     custom_encoder: dict = {},
40     sqlalchemy_safe: bool = True,
41 ) -> Any:
42     if skip_defaults is not None:
43         logger.warning(  # pragma: nocover
44             "skip_defaults in jsonable_encoder has been deprecated in favor of "
45             "exclude_unset to keep in line with Pydantic v1, support for it will be "
46             "removed soon."
47         )
48     if include is not None and not isinstance(include, set):
49         include = set(include)
50     if exclude is not None and not isinstance(exclude, set):
51         exclude = set(exclude)
52     if isinstance(obj, BaseModel):
53         encoder = getattr(obj.Config, "json_encoders", {})
54         if custom_encoder:
55             encoder.update(custom_encoder)
56         if PYDANTIC_1:
57             obj_dict = obj.dict(
58                 include=include,
59                 exclude=exclude,
60                 by_alias=by_alias,
61                 exclude_unset=bool(exclude_unset or skip_defaults),
62                 exclude_none=exclude_none,
63                 exclude_defaults=exclude_defaults,
64             )
65         else:  # pragma: nocover
66             if exclude_defaults:
67                 raise ValueError("Cannot use exclude_defaults")
68             obj_dict = obj.dict(
69                 include=include,
70                 exclude=exclude,
71                 by_alias=by_alias,
72                 skip_defaults=bool(exclude_unset or skip_defaults),
73             )
74         return jsonable_encoder(
75             obj_dict,
76             exclude_none=exclude_none,
77             exclude_defaults=exclude_defaults,
78             custom_encoder=encoder,
79             sqlalchemy_safe=sqlalchemy_safe,
80         )
81     if isinstance(obj, Enum):
82         return obj.value
83     if isinstance(obj, PurePath):
84         return str(obj)
85     if isinstance(obj, (str, int, float, type(None))):
86         return obj
87     if isinstance(obj, dict):
88         encoded_dict = {}
89         for key, value in obj.items():
90             if (
91                 (
92                     not sqlalchemy_safe
93                     or (not isinstance(key, str))
94                     or (not key.startswith("_sa"))
95                 )
96                 and (value is not None or not exclude_none)
97                 and ((include and key in include) or key not in exclude)
98             ):
99                 encoded_key = jsonable_encoder(
100                     key,
101                     by_alias=by_alias,
102                     exclude_unset=exclude_unset,
103                     exclude_none=exclude_none,
104                     custom_encoder=custom_encoder,
105                     sqlalchemy_safe=sqlalchemy_safe,
106                 )
107                 encoded_value = jsonable_encoder(
108                     value,
109                     by_alias=by_alias,
110                     exclude_unset=exclude_unset,
111                     exclude_none=exclude_none,
112                     custom_encoder=custom_encoder,
113                     sqlalchemy_safe=sqlalchemy_safe,
114                 )
115                 encoded_dict[encoded_key] = encoded_value
116         return encoded_dict
117     if isinstance(obj, (list, set, frozenset, GeneratorType, tuple)):
118         encoded_list = []
119         for item in obj:
120             encoded_list.append(
121                 jsonable_encoder(
122                     item,
123                     include=include,
124                     exclude=exclude,
125                     by_alias=by_alias,
126                     exclude_unset=exclude_unset,
127                     exclude_defaults=exclude_defaults,
128                     exclude_none=exclude_none,
129                     custom_encoder=custom_encoder,
130                     sqlalchemy_safe=sqlalchemy_safe,
131                 )
132             )
133         return encoded_list
134 
135     if custom_encoder:
136         if type(obj) in custom_encoder:
137             return custom_encoder[type(obj)](obj)
138         else:
139             for encoder_type, encoder in custom_encoder.items():
140                 if isinstance(obj, encoder_type):
141                     return encoder(obj)
142 
143     if type(obj) in ENCODERS_BY_TYPE:
144         return ENCODERS_BY_TYPE[type(obj)](obj)
145     for encoder, classes_tuple in encoders_by_class_tuples.items():
146         if isinstance(obj, classes_tuple):
147             return encoder(obj)
148 
149     errors: List[Exception] = []
150     try:
151         data = dict(obj)
152     except Exception as e:
153         errors.append(e)
154         try:
155             data = vars(obj)
156         except Exception as e:
157             errors.append(e)
158             raise ValueError(errors)
159     return jsonable_encoder(
160         data,
161         by_alias=by_alias,
162         exclude_unset=exclude_unset,
163         exclude_defaults=exclude_defaults,
164         exclude_none=exclude_none,
165         custom_encoder=custom_encoder,
166         sqlalchemy_safe=sqlalchemy_safe,
167     )
168
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/fastapi/encoders.py b/fastapi/encoders.py
--- a/fastapi/encoders.py
+++ b/fastapi/encoders.py
@@ -71,6 +71,8 @@
                 by_alias=by_alias,
                 skip_defaults=bool(exclude_unset or skip_defaults),
             )
+        if "__root__" in obj_dict:
+            obj_dict = obj_dict["__root__"]
         return jsonable_encoder(
             obj_dict,
             exclude_none=exclude_none,

{"golden_diff": "diff --git a/fastapi/encoders.py b/fastapi/encoders.py\n--- a/fastapi/encoders.py\n+++ b/fastapi/encoders.py\n@@ -71,6 +71,8 @@\n                 by_alias=by_alias,\n                 skip_defaults=bool(exclude_unset or skip_defaults),\n             )\n+        if \"__root__\" in obj_dict:\n+            obj_dict = obj_dict[\"__root__\"]\n         return jsonable_encoder(\n             obj_dict,\n             exclude_none=exclude_none,\n", "issue": "Pydantic __root__ model - incorrect handling\n### Describe the bug\r\n\r\nhttps://pydantic-docs.helpmanual.io/usage/models/#custom-root-types\r\nPydantic allows to create models with only `__root__` field. In such scenario the model behaves as transparent wrapper for this single type.\r\n\r\nWhen such model is used in response (request also?) fastapi does not treat it correctly and renders it as object with `__root__` field.\r\n\r\nObject is treated correctly by pydantic itself.\r\n\r\n### To Reproduce\r\n\r\n```\r\nfrom typing import List\r\nfrom fastapi import FastAPI\r\nfrom pydantic.main import BaseModel\r\n\r\napp = FastAPI()\r\n\r\n\r\nclass RootTestClass(BaseModel):\r\n    __root__: List[str]\r\n\r\n\r\n@app.get(\"/\")\r\nasync def root():\r\n    response = RootTestClass(__root__=['a', 'b', 'c'])\r\n    print(response.json())  # [\"a\", \"b\", \"c\"] so it's OK\r\n    print(RootTestClass.schema())  # {'title': 'RootTestClass', 'type': 'array', 'items': {'type': 'string'}} this is also OK\r\n    return response  # Wrong value in http response\r\n```\r\n\r\n### Expected behavior\r\n\r\nThe response should be:\r\n```\r\n[\"a\", \"b\", \"c\"]\r\n```\r\n\r\nbut at the moment is:\r\n```\r\n{\"__root__\":[\"a\",\"b\",\"c\"]}\r\n```\r\n\r\n### Screenshots\r\n\r\nN/A\r\n\r\n### Environment\r\n\r\n- OS: Linux\r\n- FastAPI Version: 0.47.1\r\n- Python version: Python 3.7.5\r\n\r\n### Additional context\r\n\r\nN/A\r\n\n", "before_files": [{"content": "from enum import Enum\nfrom pathlib import PurePath\nfrom types import GeneratorType\nfrom typing import Any, Callable, Dict, List, Set, Tuple, Union\n\nfrom fastapi.logger import logger\nfrom fastapi.utils import PYDANTIC_1\nfrom pydantic import BaseModel\nfrom pydantic.json import ENCODERS_BY_TYPE\n\nSetIntStr = Set[Union[int, str]]\nDictIntStrAny = Dict[Union[int, str], Any]\n\n\ndef generate_encoders_by_class_tuples(\n    type_encoder_map: Dict[Any, Callable]\n) -> Dict[Callable, Tuple]:\n    encoders_by_classes: Dict[Callable, List] = {}\n    for type_, encoder in type_encoder_map.items():\n        encoders_by_classes.setdefault(encoder, []).append(type_)\n    encoders_by_class_tuples: Dict[Callable, Tuple] = {}\n    for encoder, classes in encoders_by_classes.items():\n        encoders_by_class_tuples[encoder] = tuple(classes)\n    return encoders_by_class_tuples\n\n\nencoders_by_class_tuples = generate_encoders_by_class_tuples(ENCODERS_BY_TYPE)\n\n\ndef jsonable_encoder(\n    obj: Any,\n    include: Union[SetIntStr, DictIntStrAny] = None,\n    exclude: Union[SetIntStr, DictIntStrAny] = set(),\n    by_alias: bool = True,\n    skip_defaults: bool = None,\n    exclude_unset: bool = False,\n    exclude_defaults: bool = False,\n    exclude_none: bool = False,\n    custom_encoder: dict = {},\n    sqlalchemy_safe: bool = True,\n) -> Any:\n    if skip_defaults is not None:\n        logger.warning(  # pragma: nocover\n            \"skip_defaults in jsonable_encoder has been deprecated in favor of \"\n            \"exclude_unset to keep in line with Pydantic v1, support for it will be \"\n            \"removed soon.\"\n        )\n    if include is not None and not isinstance(include, set):\n        include = set(include)\n    if exclude is not None and not isinstance(exclude, set):\n        exclude = set(exclude)\n    if isinstance(obj, BaseModel):\n        encoder = getattr(obj.Config, \"json_encoders\", {})\n        if custom_encoder:\n            encoder.update(custom_encoder)\n        if PYDANTIC_1:\n            obj_dict = obj.dict(\n                include=include,\n                exclude=exclude,\n                by_alias=by_alias,\n                exclude_unset=bool(exclude_unset or skip_defaults),\n                exclude_none=exclude_none,\n                exclude_defaults=exclude_defaults,\n            )\n        else:  # pragma: nocover\n            if exclude_defaults:\n                raise ValueError(\"Cannot use exclude_defaults\")\n            obj_dict = obj.dict(\n                include=include,\n                exclude=exclude,\n                by_alias=by_alias,\n                skip_defaults=bool(exclude_unset or skip_defaults),\n            )\n        return jsonable_encoder(\n            obj_dict,\n            exclude_none=exclude_none,\n            exclude_defaults=exclude_defaults,\n            custom_encoder=encoder,\n            sqlalchemy_safe=sqlalchemy_safe,\n        )\n    if isinstance(obj, Enum):\n        return obj.value\n    if isinstance(obj, PurePath):\n        return str(obj)\n    if isinstance(obj, (str, int, float, type(None))):\n        return obj\n    if isinstance(obj, dict):\n        encoded_dict = {}\n        for key, value in obj.items():\n            if (\n                (\n                    not sqlalchemy_safe\n                    or (not isinstance(key, str))\n                    or (not key.startswith(\"_sa\"))\n                )\n                and (value is not None or not exclude_none)\n                and ((include and key in include) or key not in exclude)\n            ):\n                encoded_key = jsonable_encoder(\n                    key,\n                    by_alias=by_alias,\n                    exclude_unset=exclude_unset,\n                    exclude_none=exclude_none,\n                    custom_encoder=custom_encoder,\n                    sqlalchemy_safe=sqlalchemy_safe,\n                )\n                encoded_value = jsonable_encoder(\n                    value,\n                    by_alias=by_alias,\n                    exclude_unset=exclude_unset,\n                    exclude_none=exclude_none,\n                    custom_encoder=custom_encoder,\n                    sqlalchemy_safe=sqlalchemy_safe,\n                )\n                encoded_dict[encoded_key] = encoded_value\n        return encoded_dict\n    if isinstance(obj, (list, set, frozenset, GeneratorType, tuple)):\n        encoded_list = []\n        for item in obj:\n            encoded_list.append(\n                jsonable_encoder(\n                    item,\n                    include=include,\n                    exclude=exclude,\n                    by_alias=by_alias,\n                    exclude_unset=exclude_unset,\n                    exclude_defaults=exclude_defaults,\n                    exclude_none=exclude_none,\n                    custom_encoder=custom_encoder,\n                    sqlalchemy_safe=sqlalchemy_safe,\n                )\n            )\n        return encoded_list\n\n    if custom_encoder:\n        if type(obj) in custom_encoder:\n            return custom_encoder[type(obj)](obj)\n        else:\n            for encoder_type, encoder in custom_encoder.items():\n                if isinstance(obj, encoder_type):\n                    return encoder(obj)\n\n    if type(obj) in ENCODERS_BY_TYPE:\n        return ENCODERS_BY_TYPE[type(obj)](obj)\n    for encoder, classes_tuple in encoders_by_class_tuples.items():\n        if isinstance(obj, classes_tuple):\n            return encoder(obj)\n\n    errors: List[Exception] = []\n    try:\n        data = dict(obj)\n    except Exception as e:\n        errors.append(e)\n        try:\n            data = vars(obj)\n        except Exception as e:\n            errors.append(e)\n            raise ValueError(errors)\n    return jsonable_encoder(\n        data,\n        by_alias=by_alias,\n        exclude_unset=exclude_unset,\n        exclude_defaults=exclude_defaults,\n        exclude_none=exclude_none,\n        custom_encoder=custom_encoder,\n        sqlalchemy_safe=sqlalchemy_safe,\n    )\n", "path": "fastapi/encoders.py"}], "after_files": [{"content": "from enum import Enum\nfrom pathlib import PurePath\nfrom types import GeneratorType\nfrom typing import Any, Callable, Dict, List, Set, Tuple, Union\n\nfrom fastapi.logger import logger\nfrom fastapi.utils import PYDANTIC_1\nfrom pydantic import BaseModel\nfrom pydantic.json import ENCODERS_BY_TYPE\n\nSetIntStr = Set[Union[int, str]]\nDictIntStrAny = Dict[Union[int, str], Any]\n\n\ndef generate_encoders_by_class_tuples(\n    type_encoder_map: Dict[Any, Callable]\n) -> Dict[Callable, Tuple]:\n    encoders_by_classes: Dict[Callable, List] = {}\n    for type_, encoder in type_encoder_map.items():\n        encoders_by_classes.setdefault(encoder, []).append(type_)\n    encoders_by_class_tuples: Dict[Callable, Tuple] = {}\n    for encoder, classes in encoders_by_classes.items():\n        encoders_by_class_tuples[encoder] = tuple(classes)\n    return encoders_by_class_tuples\n\n\nencoders_by_class_tuples = generate_encoders_by_class_tuples(ENCODERS_BY_TYPE)\n\n\ndef jsonable_encoder(\n    obj: Any,\n    include: Union[SetIntStr, DictIntStrAny] = None,\n    exclude: Union[SetIntStr, DictIntStrAny] = set(),\n    by_alias: bool = True,\n    skip_defaults: bool = None,\n    exclude_unset: bool = False,\n    exclude_defaults: bool = False,\n    exclude_none: bool = False,\n    custom_encoder: dict = {},\n    sqlalchemy_safe: bool = True,\n) -> Any:\n    if skip_defaults is not None:\n        logger.warning(  # pragma: nocover\n            \"skip_defaults in jsonable_encoder has been deprecated in favor of \"\n            \"exclude_unset to keep in line with Pydantic v1, support for it will be \"\n            \"removed soon.\"\n        )\n    if include is not None and not isinstance(include, set):\n        include = set(include)\n    if exclude is not None and not isinstance(exclude, set):\n        exclude = set(exclude)\n    if isinstance(obj, BaseModel):\n        encoder = getattr(obj.Config, \"json_encoders\", {})\n        if custom_encoder:\n            encoder.update(custom_encoder)\n        if PYDANTIC_1:\n            obj_dict = obj.dict(\n                include=include,\n                exclude=exclude,\n                by_alias=by_alias,\n                exclude_unset=bool(exclude_unset or skip_defaults),\n                exclude_none=exclude_none,\n                exclude_defaults=exclude_defaults,\n            )\n        else:  # pragma: nocover\n            if exclude_defaults:\n                raise ValueError(\"Cannot use exclude_defaults\")\n            obj_dict = obj.dict(\n                include=include,\n                exclude=exclude,\n                by_alias=by_alias,\n                skip_defaults=bool(exclude_unset or skip_defaults),\n            )\n        if \"__root__\" in obj_dict:\n            obj_dict = obj_dict[\"__root__\"]\n        return jsonable_encoder(\n            obj_dict,\n            exclude_none=exclude_none,\n            exclude_defaults=exclude_defaults,\n            custom_encoder=encoder,\n            sqlalchemy_safe=sqlalchemy_safe,\n        )\n    if isinstance(obj, Enum):\n        return obj.value\n    if isinstance(obj, PurePath):\n        return str(obj)\n    if isinstance(obj, (str, int, float, type(None))):\n        return obj\n    if isinstance(obj, dict):\n        encoded_dict = {}\n        for key, value in obj.items():\n            if (\n                (\n                    not sqlalchemy_safe\n                    or (not isinstance(key, str))\n                    or (not key.startswith(\"_sa\"))\n                )\n                and (value is not None or not exclude_none)\n                and ((include and key in include) or key not in exclude)\n            ):\n                encoded_key = jsonable_encoder(\n                    key,\n                    by_alias=by_alias,\n                    exclude_unset=exclude_unset,\n                    exclude_none=exclude_none,\n                    custom_encoder=custom_encoder,\n                    sqlalchemy_safe=sqlalchemy_safe,\n                )\n                encoded_value = jsonable_encoder(\n                    value,\n                    by_alias=by_alias,\n                    exclude_unset=exclude_unset,\n                    exclude_none=exclude_none,\n                    custom_encoder=custom_encoder,\n                    sqlalchemy_safe=sqlalchemy_safe,\n                )\n                encoded_dict[encoded_key] = encoded_value\n        return encoded_dict\n    if isinstance(obj, (list, set, frozenset, GeneratorType, tuple)):\n        encoded_list = []\n        for item in obj:\n            encoded_list.append(\n                jsonable_encoder(\n                    item,\n                    include=include,\n                    exclude=exclude,\n                    by_alias=by_alias,\n                    exclude_unset=exclude_unset,\n                    exclude_defaults=exclude_defaults,\n                    exclude_none=exclude_none,\n                    custom_encoder=custom_encoder,\n                    sqlalchemy_safe=sqlalchemy_safe,\n                )\n            )\n        return encoded_list\n\n    if custom_encoder:\n        if type(obj) in custom_encoder:\n            return custom_encoder[type(obj)](obj)\n        else:\n            for encoder_type, encoder in custom_encoder.items():\n                if isinstance(obj, encoder_type):\n                    return encoder(obj)\n\n    if type(obj) in ENCODERS_BY_TYPE:\n        return ENCODERS_BY_TYPE[type(obj)](obj)\n    for encoder, classes_tuple in encoders_by_class_tuples.items():\n        if isinstance(obj, classes_tuple):\n            return encoder(obj)\n\n    errors: List[Exception] = []\n    try:\n        data = dict(obj)\n    except Exception as e:\n        errors.append(e)\n        try:\n            data = vars(obj)\n        except Exception as e:\n            errors.append(e)\n            raise ValueError(errors)\n    return jsonable_encoder(\n        data,\n        by_alias=by_alias,\n        exclude_unset=exclude_unset,\n        exclude_defaults=exclude_defaults,\n        exclude_none=exclude_none,\n        custom_encoder=custom_encoder,\n        sqlalchemy_safe=sqlalchemy_safe,\n    )\n", "path": "fastapi/encoders.py"}]}