Alias for path param does not work when hypens are used in it.
See original GitHub issueFirst Check
- I added a very descriptive title to this issue.
- I used the GitHub search to find a similar issue and didn’t find it.
- I searched the FastAPI documentation, with the integrated search.
- I already searched in Google “How to X in FastAPI” and didn’t find any information.
- I already read and followed all the tutorial in the docs and didn’t find an answer.
- I already checked if it is not related to FastAPI but to Pydantic.
- I already checked if it is not related to FastAPI but to Swagger UI.
- I already checked if it is not related to FastAPI but to ReDoc.
Commit to Help
- I commit to help with one of those options 👆
Example Code
from fastapi import FastAPI, Path
app = FastAPI()
@app.get("/{my-id}/list")
def list_items(
my_id: str = Path(alias="my-id")
):
return {"aa": my_id}
Description
On hitting
curl -X 'GET' \
'http://localhost:8000/sample/list' \
-H 'accept: application/json'
I get 404 error
{
"detail": "Not Found"
}
Operating System
Windows
Operating System Details
No response
FastAPI Version
0.79.0
Python Version
3.9.10
Additional Context
This behaviour is working fine with Query param alias but not with Path param alias
Issue Analytics
- State:
- Created a year ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Path(alias=) feature doesn't work if the alias has a hyphen in it
Path (alias=) feature doesn't work if the alias has a hyphen in it ... I used the GitHub search to find a similar...
Read more >bash - Are there problems with hyphens in functions, aliases ...
A hyphen is not listed among the characters that must be allowed in either case. So, if they are used, portability is not...
Read more >How to handle path parametes with hyphen(-) in a FastAPI ...
You can use alias in your definitions. It's all documented here. As stated in the comments below, if the links stops working here...
Read more >Hyphens and forward slashes (-/) break Views contextual filters
Problem /Motivation Views contextual filters break when values contain forward slashes or when they contain hyphens and the "Transform spaces ...
Read more >Use of Dash “-” in Command-Line Parameters - Baeldung
In this tutorial, we'll see what the “-” character is about and what purpose it serves. We'll take a look at the most...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This doesn’t make any sense to want; you are trying to create an invalid python variable name with a hyphen, which is never used outside the scope of python itself. Not like for example query parameters, where the name of the parameter is exposed to the end user in the URL.
Can I ask why you would want to do this?
@tiangolo any idea on why it isn’t working when using hyphens in path parameter aliases? is this planned to be fixed?