<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 👆</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="This route, based on Closed Issue https://github.com/tiangolo/fastapi/issues/131#issuecomment-1177187775, works, and shows how one can alias a path parameter.


@router.get(&quot;/api/users/{id}/profile/&quot;)
def user_profile(user_id: int = Path(None, alias=&quot;id&quot;)):
    return {
        &quot;id&quot;: user_id,
        &quot;username&quot;: &quot;johndoe&quot;
    }"><pre class="notranslate"><span class="pl-v">This</span> <span class="pl-s1">route</span>, <span class="pl-s1">based</span> <span class="pl-s1">on</span> <span class="pl-v">Closed</span> <span class="pl-v">Issue</span> <span class="pl-s1">https</span>:<span class="pl-c1">//</span><span class="pl-s1">github</span>.<span class="pl-s1">com</span><span class="pl-c1">/</span><span class="pl-s1">tiangolo</span><span class="pl-c1">/</span><span class="pl-s1">fastapi</span><span class="pl-c1">/</span><span class="pl-s1">issues</span><span class="pl-c1">/</span><span class="pl-c1">131</span><span class="pl-c">#issuecomment-1177187775, works, and shows how one can alias a path parameter.</span>


<span class="pl-en">@<span class="pl-s1">router</span>.<span class="pl-en">get</span>(<span class="pl-s">"/api/users/{id}/profile/"</span>)</span>
<span class="pl-k">def</span> <span class="pl-en">user_profile</span>(<span class="pl-s1">user_id</span>: <span class="pl-s1">int</span> <span class="pl-c1">=</span> <span class="pl-v">Path</span>(<span class="pl-c1">None</span>, <span class="pl-s1">alias</span><span class="pl-c1">=</span><span class="pl-s">"id"</span>)):
    <span class="pl-k">return</span> {
        <span class="pl-s">"id"</span>: <span class="pl-s1">user_id</span>,
        <span class="pl-s">"username"</span>: <span class="pl-s">"johndoe"</span>
    }</pre></div>
<p dir="auto">This route, using <code class="notranslate">"user-id"</code> instead of <code class="notranslate">"id"</code> as the alias, does not work.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="@router.get(&quot;/api/users1/{user-id}/profile/&quot;)
def user_profile(user_id: int = Path(None, alias=&quot;user-id&quot;)):
    return {
        &quot;id&quot;: user_id,
        &quot;username&quot;: &quot;johndoe&quot;
    }"><pre class="notranslate"><code class="notranslate">@router.get("/api/users1/{user-id}/profile/")
def user_profile(user_id: int = Path(None, alias="user-id")):
    return {
        "id": user_id,
        "username": "johndoe"
    }
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="

### Description

Both `Query()` and `Path()` have an `alias` feature.  `Query()` aliases can contain hyphens, but `Path()` aliases cannot.  This appears to be a bug, as the [doc](https://fastapi.tiangolo.com/tutorial/path-params-numeric-validations/#declare-metadata) says about Path metadata

&gt; You can declare all the same parameters as for Query.

### Operating System

Linux

### Operating System Details

Amazon Linux 2 

### FastAPI Version

0.86.0

### Python Version

3.9.13

### Additional Context

Swagger UI showing working route:
&lt;img width=&quot;801&quot; alt=&quot;path_alias_working&quot; src=&quot;https://user-images.githubusercontent.com/79278744/201563302-a0539e26-af29-4785-b2f5-ec970f3233f1.png&quot;&gt;

Swagger UI showing hyphenated alias Not Found:
&lt;img width=&quot;803&quot; alt=&quot;page_alias_with_hyphen_issue&quot; src=&quot;https://user-images.githubusercontent.com/79278744/201563374-dc3f2198-ca49-42eb-974b-557f3a3a9559.png&quot;&gt;"><pre class="notranslate"><code class="notranslate">

### Description

Both `Query()` and `Path()` have an `alias` feature.  `Query()` aliases can contain hyphens, but `Path()` aliases cannot.  This appears to be a bug, as the [doc](https://fastapi.tiangolo.com/tutorial/path-params-numeric-validations/#declare-metadata) says about Path metadata

&gt; You can declare all the same parameters as for Query.

### Operating System

Linux

### Operating System Details

Amazon Linux 2 

### FastAPI Version

0.86.0

### Python Version

3.9.13

### Additional Context

Swagger UI showing working route:
&lt;img width="801" alt="path_alias_working" src="https://user-images.githubusercontent.com/79278744/201563302-a0539e26-af29-4785-b2f5-ec970f3233f1.png"&gt;

Swagger UI showing hyphenated alias Not Found:
&lt;img width="803" alt="page_alias_with_hyphen_issue" src="https://user-images.githubusercontent.com/79278744/201563374-dc3f2198-ca49-42eb-974b-557f3a3a9559.png"&gt;
</code></pre></div>
<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, Path

app = FastAPI()

@app.get(&quot;/{my-id}/list&quot;)
def list_items(
        my_id: str = Path(alias=&quot;my-id&quot;)
):
    return {&quot;aa&quot;: my_id}"><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">Path</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">"/{my-id}/list"</span>)</span>
<span class="pl-k">def</span> <span class="pl-en">list_items</span>(
        <span class="pl-s1">my_id</span>: <span class="pl-s1">str</span> <span class="pl-c1">=</span> <span class="pl-v">Path</span>(<span class="pl-s1">alias</span><span class="pl-c1">=</span><span class="pl-s">"my-id"</span>)
):
    <span class="pl-k">return</span> {<span class="pl-s">"aa"</span>: <span class="pl-s1">my_id</span>}</pre></div>
<h3 dir="auto">Description</h3>
<p dir="auto">On hitting</p>
<div class="highlight highlight-source-batchfile notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="curl -X 'GET' \
  'http://localhost:8000/sample/list' \
  -H 'accept: application/json'"><pre class="notranslate">curl -X 'GET' \
  'http://localhost:8000/sample/list' \
  -H 'accept: application/json'</pre></div>
<p dir="auto">I get 404 error</p>
<div class="highlight highlight-source-json notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{
  &quot;detail&quot;: &quot;Not Found&quot;
}"><pre class="notranslate">{
  <span class="pl-ent">"detail"</span>: <span class="pl-s"><span class="pl-pds">"</span>Not Found<span class="pl-pds">"</span></span>
}</pre></div>
<h3 dir="auto">Operating System</h3>
<p dir="auto">Windows</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.79.0</p>
<h3 dir="auto">Python Version</h3>
<p dir="auto">3.9.10</p>
<h3 dir="auto">Additional Context</h3>
<p dir="auto">This behaviour is working fine with Query param alias but not with Path param alias</p>