<h3 dir="auto">First check</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I added a very descriptive title to this issue.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I used the GitHub search to find a similar issue and didn't find it.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I searched the FastAPI documentation, with the integrated search.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already searched in Google "How to X in FastAPI" and didn't find any information.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already read and followed all the tutorial in the docs and didn't find an answer.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already checked if it is not related to FastAPI but to <a href="https://github.com/samuelcolvin/pydantic">Pydantic</a>.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already checked if it is not related to FastAPI but to <a href="https://github.com/swagger-api/swagger-ui">Swagger UI</a>.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already checked if it is not related to FastAPI but to <a href="https://github.com/Redocly/redoc">ReDoc</a>.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> After submitting this, I commit to one of:
<ul dir="auto">
<li>Read open issues with questions until I find 2 issues where I can help someone and add a comment to help there.</li>
<li>I already hit the "watch" button in this repository to receive notifications and I commit to help at least 2 people that ask questions in the future.</li>
<li>Implement a Pull Request for a confirmed bug.</li>
</ul>
</li>
</ul>
<h3 dir="auto">Example</h3>
<p dir="auto">Here's a self-contained, <a href="https://stackoverflow.com/help/minimal-reproducible-example" rel="nofollow">minimal, reproducible, example</a> with my use case:</p>

<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from pydantic import BaseModel
from typing import Set
from fastapi import FastAPI

app = FastAPI()


class Request(BaseModel):
    request_id: str

    def __hash__(self):
        return hash(self.request_id)


class Requests(BaseModel):
    request_ids: Set[Request]


@app.post(&quot;/test&quot;, response_model=Requests)
def read_root(data: Requests):
    return data
"><pre class="notranslate"><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">typing</span> <span class="pl-k">import</span> <span class="pl-v">Set</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-s1">app</span> <span class="pl-c1">=</span> <span class="pl-v">FastAPI</span>()


<span class="pl-k">class</span> <span class="pl-v">Request</span>(<span class="pl-v">BaseModel</span>):
    <span class="pl-s1">request_id</span>: <span class="pl-s1">str</span>

    <span class="pl-k">def</span> <span class="pl-en">__hash__</span>(<span class="pl-s1">self</span>):
        <span class="pl-k">return</span> <span class="pl-en">hash</span>(<span class="pl-s1">self</span>.<span class="pl-s1">request_id</span>)


<span class="pl-k">class</span> <span class="pl-v">Requests</span>(<span class="pl-v">BaseModel</span>):
    <span class="pl-s1">request_ids</span>: <span class="pl-v">Set</span>[<span class="pl-v">Request</span>]


<span class="pl-en">@<span class="pl-s1">app</span>.<span class="pl-en">post</span>(<span class="pl-s">"/test"</span>, <span class="pl-s1">response_model</span><span class="pl-c1">=</span><span class="pl-v">Requests</span>)</span>
<span class="pl-k">def</span> <span class="pl-en">read_root</span>(<span class="pl-s1">data</span>: <span class="pl-v">Requests</span>):
    <span class="pl-k">return</span> <span class="pl-s1">data</span></pre></div>
<h3 dir="auto">Description</h3>
<p dir="auto">Thanks to the <a href="https://fastapi.tiangolo.com/tutorial/body-nested-models/?h=duplicate#set-types" rel="nofollow">Set feature</a>, the deduplication step works ok for data IN. however it fails for data OUT:</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="curl -X 'POST'   'http://127.0.0.1:8000/test'   -H 'accept: application/json'   -H 'Content-Type: application/json'   -d '{

  &quot;request_ids&quot;: [
    {
      &quot;request_id&quot;: &quot;c04ca7ee-f62c-4372-b667-73ace53c69c2&quot;
    }
  ]
}'

  File &quot;pydantic/main.py&quot;, line 504, in pydantic.main.BaseModel.dict

  File &quot;pydantic/main.py&quot;, line 869, in _iter
  File &quot;pydantic/main.py&quot;, line 810, in pydantic.main.BaseModel._get_value
TypeError: unhashable type: 'dict'"><pre class="notranslate">curl -X <span class="pl-s"><span class="pl-pds">'</span>POST<span class="pl-pds">'</span></span>   <span class="pl-s"><span class="pl-pds">'</span>http://127.0.0.1:8000/test<span class="pl-pds">'</span></span>   -H <span class="pl-s"><span class="pl-pds">'</span>accept: application/json<span class="pl-pds">'</span></span>   -H <span class="pl-s"><span class="pl-pds">'</span>Content-Type: application/json<span class="pl-pds">'</span></span>   -d <span class="pl-s"><span class="pl-pds">'</span>{</span>
<span class="pl-s"></span>
<span class="pl-s">  "request_ids": [</span>
<span class="pl-s">    {</span>
<span class="pl-s">      "request_id": "c04ca7ee-f62c-4372-b667-73ace53c69c2"</span>
<span class="pl-s">    }</span>
<span class="pl-s">  ]</span>
<span class="pl-s">}<span class="pl-pds">'</span></span>

  File <span class="pl-s"><span class="pl-pds">"</span>pydantic/main.py<span class="pl-pds">"</span></span>, line 504, <span class="pl-k">in</span> pydantic.main.BaseModel.dict

  File <span class="pl-s"><span class="pl-pds">"</span>pydantic/main.py<span class="pl-pds">"</span></span>, line 869, <span class="pl-k">in</span> _iter
  File <span class="pl-s"><span class="pl-pds">"</span>pydantic/main.py<span class="pl-pds">"</span></span>, line 810, <span class="pl-k">in</span> pydantic.main.BaseModel._get_value
TypeError: unhashable type: <span class="pl-s"><span class="pl-pds">'</span>dict<span class="pl-pds">'</span></span></pre></div>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>OS: Ubuntu 20.04.2 LTS</li>
<li>FastAPI Version [e.g. 0.3.0]: 0.63.0</li>
<li>Python Version: 3.8.5</li>
</ul>
<p dir="auto">I'm developing a public api where we'll probably want to nest routes at least a couple of levels deep, using the initial route to determine the 'app' that the rest of the content belongs to.</p>
<p dir="auto">our target url structure is along the lines of</p>
<p dir="auto"><code class="notranslate">/api/v1/apps/{shortcode}</code><br>
<code class="notranslate">/api/v1/apps/{shortcode}/people/</code><br>
<code class="notranslate">/api/v1/apps/{shortcode}/people/{id}</code></p>
<p dir="auto">etc. etc...</p>
<p dir="auto">I'd really like to take advantage of the APIRouter classes to do this as we're likely to have a lot of endpoints and models but I can't find a way to ensure the 'shortcode' parameter here is passed to child routers, is there any way to do that?</p>
<p dir="auto">currently I'm doing stuff like this:</p>
<h1 dir="auto">app.py</h1>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from app.people.routes import router as people_router
from app.routes import router as main_router

app = FastAPI()
app.debug = settings.DEBUG

main_router.include_router(people_router, prefix='/{shortcode}/people')
app.include_router(main_router, prefix='/apps')"><pre class="notranslate"><code class="notranslate">from app.people.routes import router as people_router
from app.routes import router as main_router

app = FastAPI()
app.debug = settings.DEBUG

main_router.include_router(people_router, prefix='/{shortcode}/people')
app.include_router(main_router, prefix='/apps')
</code></pre></div>
<p dir="auto">This works ok, but the <code class="notranslate">{shortcode}</code> parameter is not included in the auto-generated documentation ( though it is available in the view functions ). I'd rather not have to define every view function individually with prefixed like <code class="notranslate">@router.route('/{shortcode}/people/{id}) ...</code> if I can avoid it somehow?</p>