Skip to content

Alias for path param does not work when hypens are used in it. #5281

@msbhogal

Description

@msbhogal

First 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions