<h3 dir="auto">Describe the bug</h3>
<p dir="auto">I want to extract enums from model schema to separate definition, and the solution is:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from enum import Enum

from pydantic import BaseModel
from devtools import debug

class HelloType(str, Enum):
    World = 'World',
    Friend = 'Friend',

class HelloEnum(BaseModel):
    __root__: HelloType

class Foo(BaseModel):
    bar: HelloEnum

debug(HelloEnum.schema())
debug(Foo.schema())"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">enum</span> <span class="pl-k">import</span> <span class="pl-v">Enum</span>

<span class="pl-k">from</span> <span class="pl-s1">pydantic</span> <span class="pl-k">import</span> <span class="pl-v">BaseModel</span>
<span class="pl-k">from</span> <span class="pl-s1">devtools</span> <span class="pl-k">import</span> <span class="pl-s1">debug</span>

<span class="pl-k">class</span> <span class="pl-v">HelloType</span>(<span class="pl-s1">str</span>, <span class="pl-v">Enum</span>):
    <span class="pl-v">World</span> <span class="pl-c1">=</span> <span class="pl-s">'World'</span>,
    <span class="pl-v">Friend</span> <span class="pl-c1">=</span> <span class="pl-s">'Friend'</span>,

<span class="pl-k">class</span> <span class="pl-v">HelloEnum</span>(<span class="pl-v">BaseModel</span>):
    <span class="pl-s1">__root__</span>: <span class="pl-v">HelloType</span>

<span class="pl-k">class</span> <span class="pl-v">Foo</span>(<span class="pl-v">BaseModel</span>):
    <span class="pl-s1">bar</span>: <span class="pl-v">HelloEnum</span>

<span class="pl-en">debug</span>(<span class="pl-v">HelloEnum</span>.<span class="pl-en">schema</span>())
<span class="pl-en">debug</span>(<span class="pl-v">Foo</span>.<span class="pl-en">schema</span>())</pre></div>
<p dir="auto">Output:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="./main.py &lt;module&gt;
    HelloEnum.schema(): {
        'title': 'HelloEnum',
        'enum': [
            'World',
            'Friend',
        ],
        'type': 'string',
    } (dict) len=3
./main.py &lt;module&gt;
    Foo.schema(): {
        'title': 'Foo',
        'type': 'object',
        'properties': {
            'bar': {
                '$ref': '#/definitions/HelloEnum',
            },
        },
        'required': ['bar'],
        'definitions': {
            'HelloEnum': {
                'title': 'HelloEnum',
                'enum': [
                    'World',
                    'Friend',
                ],
                'type': 'string',
            },
        },
    } (dict) len=5"><pre class="notranslate"><code class="notranslate">./main.py &lt;module&gt;
    HelloEnum.schema(): {
        'title': 'HelloEnum',
        'enum': [
            'World',
            'Friend',
        ],
        'type': 'string',
    } (dict) len=3
./main.py &lt;module&gt;
    Foo.schema(): {
        'title': 'Foo',
        'type': 'object',
        'properties': {
            'bar': {
                '$ref': '#/definitions/HelloEnum',
            },
        },
        'required': ['bar'],
        'definitions': {
            'HelloEnum': {
                'title': 'HelloEnum',
                'enum': [
                    'World',
                    'Friend',
                ],
                'type': 'string',
            },
        },
    } (dict) len=5
</code></pre></div>
<p dir="auto">But I can't use <code class="notranslate">HelloEnum</code> in Query parameters:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="@app.get('/')
async def root(hello_type: HelloEnum = Query(...)):
    return {'message': f'Hello {hello_type}'}"><pre class="notranslate"><span class="pl-en">@<span class="pl-s1">app</span>.<span class="pl-en">get</span>(<span class="pl-s">'/'</span>)</span>
<span class="pl-k">async</span> <span class="pl-k">def</span> <span class="pl-en">root</span>(<span class="pl-s1">hello_type</span>: <span class="pl-v">HelloEnum</span> <span class="pl-c1">=</span> <span class="pl-v">Query</span>(...)):
    <span class="pl-k">return</span> {<span class="pl-s">'message'</span>: <span class="pl-s">f'Hello <span class="pl-s1"><span class="pl-kos">{</span><span class="pl-s1">hello_type</span><span class="pl-kos">}</span></span>'</span>}</pre></div>
<p dir="auto">And I get the error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="File &quot;./main.py&quot;, line 28, in &lt;module&gt;
    async def root(hello_type: HelloEnum = Query(...)):
  File &quot;&lt;..&gt;/python3.8/site-packages/fastapi/routing.py&quot;, line 514, in decorator
    self.add_api_route(
  File &quot;&lt;..&gt;/python3.8/site-packages/fastapi/routing.py&quot;, line 453, in add_api_route
    route = route_class(
  File &quot;&lt;..&gt;/python3.8/site-packages/fastapi/routing.py&quot;, line 370, in __init__
    self.dependant = get_dependant(path=self.path_format, call=self.endpoint)
  File &quot;&lt;..&gt;/python3.8/site-packages/fastapi/dependencies/utils.py&quot;, line 308, in get_dependant
    assert isinstance(
AssertionError: Param: hello_type can only be a request body, using Body(...)"><pre class="notranslate"><code class="notranslate">File "./main.py", line 28, in &lt;module&gt;
    async def root(hello_type: HelloEnum = Query(...)):
  File "&lt;..&gt;/python3.8/site-packages/fastapi/routing.py", line 514, in decorator
    self.add_api_route(
  File "&lt;..&gt;/python3.8/site-packages/fastapi/routing.py", line 453, in add_api_route
    route = route_class(
  File "&lt;..&gt;/python3.8/site-packages/fastapi/routing.py", line 370, in __init__
    self.dependant = get_dependant(path=self.path_format, call=self.endpoint)
  File "&lt;..&gt;/python3.8/site-packages/fastapi/dependencies/utils.py", line 308, in get_dependant
    assert isinstance(
AssertionError: Param: hello_type can only be a request body, using Body(...)
</code></pre></div>
<h3 dir="auto">To Reproduce</h3>
<ol dir="auto">
<li>Create a file with:</li>
</ol>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from enum import Enum

from fastapi import FastAPI, Query
from pydantic import BaseModel

app = FastAPI()


class HelloType(str, Enum):
    World = 'World',
    Friend = 'Friend',


class HelloEnum(BaseModel):
    __root__: HelloType

@app.get('/')
async def root(hello_type: HelloEnum = Query(...)):
    return {'message': f'Hello {hello_type}'}
"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">enum</span> <span class="pl-k">import</span> <span class="pl-v">Enum</span>

<span class="pl-k">from</span> <span class="pl-s1">fastapi</span> <span class="pl-k">import</span> <span class="pl-v">FastAPI</span>, <span class="pl-v">Query</span>
<span class="pl-k">from</span> <span class="pl-s1">pydantic</span> <span class="pl-k">import</span> <span class="pl-v">BaseModel</span>

<span class="pl-s1">app</span> <span class="pl-c1">=</span> <span class="pl-v">FastAPI</span>()


<span class="pl-k">class</span> <span class="pl-v">HelloType</span>(<span class="pl-s1">str</span>, <span class="pl-v">Enum</span>):
    <span class="pl-v">World</span> <span class="pl-c1">=</span> <span class="pl-s">'World'</span>,
    <span class="pl-v">Friend</span> <span class="pl-c1">=</span> <span class="pl-s">'Friend'</span>,


<span class="pl-k">class</span> <span class="pl-v">HelloEnum</span>(<span class="pl-v">BaseModel</span>):
    <span class="pl-s1">__root__</span>: <span class="pl-v">HelloType</span>

<span class="pl-en">@<span class="pl-s1">app</span>.<span class="pl-en">get</span>(<span class="pl-s">'/'</span>)</span>
<span class="pl-k">async</span> <span class="pl-k">def</span> <span class="pl-en">root</span>(<span class="pl-s1">hello_type</span>: <span class="pl-v">HelloEnum</span> <span class="pl-c1">=</span> <span class="pl-v">Query</span>(...)):
    <span class="pl-k">return</span> {<span class="pl-s">'message'</span>: <span class="pl-s">f'Hello <span class="pl-s1"><span class="pl-kos">{</span><span class="pl-s1">hello_type</span><span class="pl-kos">}</span></span>'</span>}</pre></div>
<ol start="3" dir="auto">
<li>Run app.</li>
<li>It trows an exception <code class="notranslate">AssertionError: Param: hello_type can only be a request body, using Body(...)</code>.</li>
<li>But I expected it to run successfully.</li>
</ol>
<h3 dir="auto">Expected behavior</h3>
<p dir="auto">Run app successfully, and in openapi schema enum extracted in the separate definition.</p>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>macOS 10.15.4</li>
<li>FastAPI 0.54.2</li>
<li>Python 3.8.2</li>
</ul>
<h3 dir="auto">Describe the bug</h3>
<p dir="auto"><a href="https://pydantic-docs.helpmanual.io/usage/models/#custom-root-types" rel="nofollow">https://pydantic-docs.helpmanual.io/usage/models/#custom-root-types</a><br>
Pydantic allows to create models with only <code class="notranslate">__root__</code> field. In such scenario the model behaves as transparent wrapper for this single type.</p>
<p dir="auto">When such model is used in response (request also?) fastapi does not treat it correctly and renders it as object with <code class="notranslate">__root__</code> field.</p>
<p dir="auto">Object is treated correctly by pydantic itself.</p>
<h3 dir="auto">To Reproduce</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from typing import List
from fastapi import FastAPI
from pydantic.main import BaseModel

app = FastAPI()


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


@app.get(&quot;/&quot;)
async def root():
    response = RootTestClass(__root__=['a', 'b', 'c'])
    print(response.json())  # [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;] 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"><pre class="notranslate"><code class="notranslate">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
</code></pre></div>
<h3 dir="auto">Expected behavior</h3>
<p dir="auto">The response should be:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[&quot;a&quot;, &quot;b&quot;, &quot;c&quot;]"><pre class="notranslate"><code class="notranslate">["a", "b", "c"]
</code></pre></div>
<p dir="auto">but at the moment is:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{&quot;__root__&quot;:[&quot;a&quot;,&quot;b&quot;,&quot;c&quot;]}"><pre class="notranslate"><code class="notranslate">{"__root__":["a","b","c"]}
</code></pre></div>
<h3 dir="auto">Screenshots</h3>
<p dir="auto">N/A</p>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>OS: Linux</li>
<li>FastAPI Version: 0.47.1</li>
<li>Python version: Python 3.7.5</li>
</ul>
<h3 dir="auto">Additional context</h3>
<p dir="auto">N/A</p>