<p dir="auto"><strong>Describe the bug</strong></p>
<p dir="auto">There is a bug when API is organized with different versions (FastAPI apps) which mounted via global <code class="notranslate">app.mount</code>.</p>
<p dir="auto">ReDoc duplicates mount's prefix. For example, <code class="notranslate">http://127.0.0.1:8000/v1/v1/test</code>.</p>
<p dir="auto">It works well in default OpenAPI Docs.</p>
<p dir="auto"><strong>Environment:</strong></p>
<ul dir="auto">
<li>OS: [e.g. Linux / Windows / macOS]</li>
<li>FastAPI Version [e.g. 0.3.0], get it with: 0.40.0</li>
</ul>
<p dir="auto"><strong>Additional context</strong></p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import fastapi
from fastapi import APIRouter

app = fastapi.FastAPI(docs_url=None, redoc_url=None)
router = APIRouter()


@router.get(&quot;/users/&quot;, tags=[&quot;users&quot;])
async def read_users():
    return [{&quot;username&quot;: &quot;Foo&quot;}, {&quot;username&quot;: &quot;Bar&quot;}]

apiV1 = fastapi.FastAPI(openapi_prefix=&quot;/v1&quot;, version=&quot;1.0.0&quot;)
apiV1.include_router(router)
app.mount(&quot;/v1&quot;, apiV1)"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">fastapi</span>
<span class="pl-k">from</span> <span class="pl-s1">fastapi</span> <span class="pl-k">import</span> <span class="pl-v">APIRouter</span>

<span class="pl-s1">app</span> <span class="pl-c1">=</span> <span class="pl-s1">fastapi</span>.<span class="pl-v">FastAPI</span>(<span class="pl-s1">docs_url</span><span class="pl-c1">=</span><span class="pl-c1">None</span>, <span class="pl-s1">redoc_url</span><span class="pl-c1">=</span><span class="pl-c1">None</span>)
<span class="pl-s1">router</span> <span class="pl-c1">=</span> <span class="pl-v">APIRouter</span>()


<span class="pl-en">@<span class="pl-s1">router</span>.<span class="pl-en">get</span>(<span class="pl-s">"/users/"</span>, <span class="pl-s1">tags</span><span class="pl-c1">=</span>[<span class="pl-s">"users"</span>])</span>
<span class="pl-k">async</span> <span class="pl-k">def</span> <span class="pl-en">read_users</span>():
    <span class="pl-k">return</span> [{<span class="pl-s">"username"</span>: <span class="pl-s">"Foo"</span>}, {<span class="pl-s">"username"</span>: <span class="pl-s">"Bar"</span>}]

<span class="pl-s1">apiV1</span> <span class="pl-c1">=</span> <span class="pl-s1">fastapi</span>.<span class="pl-v">FastAPI</span>(<span class="pl-s1">openapi_prefix</span><span class="pl-c1">=</span><span class="pl-s">"/v1"</span>, <span class="pl-s1">version</span><span class="pl-c1">=</span><span class="pl-s">"1.0.0"</span>)
<span class="pl-s1">apiV1</span>.<span class="pl-en">include_router</span>(<span class="pl-s1">router</span>)
<span class="pl-s1">app</span>.<span class="pl-en">mount</span>(<span class="pl-s">"/v1"</span>, <span class="pl-s1">apiV1</span>)</pre></div>
<h1 dir="auto">Screenshot</h1>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/1760209/66273438-aa2a5300-e87c-11e9-9d14-8f3981de5c73.png"><img src="https://user-images.githubusercontent.com/1760209/66273438-aa2a5300-e87c-11e9-9d14-8f3981de5c73.png" alt="Screen Shot 2019-10-06 at 21 02 37" style="max-width: 100%;"></a></p>
<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>
</ul>
<h3 dir="auto">Commit to Help</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I commit to help with one of those options <g-emoji class="g-emoji" alias="point_up_2" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f446.png">👆</g-emoji></li>
</ul>
<h3 dir="auto">Example Code</h3>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from fastapi import FastAPI, Header, Request, HTTPException

app = FastAPI()

@app.get(&quot;/greet&quot;)
def greet_version(request: Request, X_API_Version: int = Header(int(1))):
    &quot;&quot;&quot;
    This request uses X-API-Version header to determine version

    - **X-API-Version**: request must have a version either 1 or 2 is accepted.
    &quot;&quot;&quot;
    version = request.headers.get('X-API-Version')
    if version == '1': 
        return {'message': &quot;Hello&quot;}
    if version == '2': 
        return {'notice': &quot;Hello&quot;}
    else: 
        raise HTTPException(status_code=404, detail=&quot;Version not found&quot;)"><pre class="notranslate"><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">Header</span>, <span class="pl-v">Request</span>, <span class="pl-v">HTTPException</span>

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

<span class="pl-en">@<span class="pl-s1">app</span>.<span class="pl-en">get</span>(<span class="pl-s">"/greet"</span>)</span>
<span class="pl-k">def</span> <span class="pl-en">greet_version</span>(<span class="pl-s1">request</span>: <span class="pl-v">Request</span>, <span class="pl-v">X_API_Version</span>: <span class="pl-s1">int</span> <span class="pl-c1">=</span> <span class="pl-v">Header</span>(<span class="pl-en">int</span>(<span class="pl-c1">1</span>))):
    <span class="pl-s">"""</span>
<span class="pl-s">    This request uses X-API-Version header to determine version</span>
<span class="pl-s"></span>
<span class="pl-s">    - **X-API-Version**: request must have a version either 1 or 2 is accepted.</span>
<span class="pl-s">    """</span>
    <span class="pl-s1">version</span> <span class="pl-c1">=</span> <span class="pl-s1">request</span>.<span class="pl-s1">headers</span>.<span class="pl-en">get</span>(<span class="pl-s">'X-API-Version'</span>)
    <span class="pl-k">if</span> <span class="pl-s1">version</span> <span class="pl-c1">==</span> <span class="pl-s">'1'</span>: 
        <span class="pl-k">return</span> {<span class="pl-s">'message'</span>: <span class="pl-s">"Hello"</span>}
    <span class="pl-k">if</span> <span class="pl-s1">version</span> <span class="pl-c1">==</span> <span class="pl-s">'2'</span>: 
        <span class="pl-k">return</span> {<span class="pl-s">'notice'</span>: <span class="pl-s">"Hello"</span>}
    <span class="pl-k">else</span>: 
        <span class="pl-k">raise</span> <span class="pl-v">HTTPException</span>(<span class="pl-s1">status_code</span><span class="pl-c1">=</span><span class="pl-c1">404</span>, <span class="pl-s1">detail</span><span class="pl-c1">=</span><span class="pl-s">"Version not found"</span>)</pre></div>
<h3 dir="auto">Description</h3>
<p dir="auto">I want to create FastAPI app with custom header versioning and the only solution I found is to add the check in the request itself what is the header value and based on that return the adjusted response. This approach is not very good in terms of code organization(nested if-else for versioning), data validation ex. what in case version two would require different query parameters, I cannot set both in the same request. Also, this will not be described properly with OpenAPI docs. I would rather have requests under the same path and define them according to version changes based on additional header parameters but I am not sure how to approach this especially since two requests cannot have the same path and I don't want to use redirects ex. with the decorator:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="@app.get(&quot;/greet&quot;)
@header_version(1)
def greet_version(request: Request, X_API_Version: int = Header(int(1))):
        return {'message': &quot;Hello&quot;}

@app.get(&quot;/greet&quot;)
@header_version(2)
def greet_version(request: Request, X_API_Version: int = Header(int(2))):
        return {'notice': &quot;Hello&quot;}"><pre class="notranslate"><span class="pl-en">@<span class="pl-s1">app</span>.<span class="pl-en">get</span>(<span class="pl-s">"/greet"</span>)</span>
<span class="pl-en">@<span class="pl-en">header_version</span>(<span class="pl-c1">1</span>)</span>
<span class="pl-k">def</span> <span class="pl-en">greet_version</span>(<span class="pl-s1">request</span>: <span class="pl-v">Request</span>, <span class="pl-v">X_API_Version</span>: <span class="pl-s1">int</span> <span class="pl-c1">=</span> <span class="pl-v">Header</span>(<span class="pl-en">int</span>(<span class="pl-c1">1</span>))):
        <span class="pl-k">return</span> {<span class="pl-s">'message'</span>: <span class="pl-s">"Hello"</span>}

<span class="pl-en">@<span class="pl-s1">app</span>.<span class="pl-en">get</span>(<span class="pl-s">"/greet"</span>)</span>
<span class="pl-en">@<span class="pl-en">header_version</span>(<span class="pl-c1">2</span>)</span>
<span class="pl-k">def</span> <span class="pl-en">greet_version</span>(<span class="pl-s1">request</span>: <span class="pl-v">Request</span>, <span class="pl-v">X_API_Version</span>: <span class="pl-s1">int</span> <span class="pl-c1">=</span> <span class="pl-v">Header</span>(<span class="pl-en">int</span>(<span class="pl-c1">2</span>))):
        <span class="pl-k">return</span> {<span class="pl-s">'notice'</span>: <span class="pl-s">"Hello"</span>}</pre></div>
<h3 dir="auto">Operating System</h3>
<p dir="auto">Linux</p>
<h3 dir="auto">Operating System Details</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">FastAPI Version</h3>
<p dir="auto">0.66.0</p>
<h3 dir="auto">Python Version</h3>
<p dir="auto">3.8.10</p>
<h3 dir="auto">Additional Context</h3>
<p dir="auto"><em>No response</em></p>