question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Duplicated OperationID when adding route with multiple methods

See original GitHub issue

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

router.add_api_route(
    "/clear",
    clear,
    methods=["POST", "DELETE"]
)

Description

Seems to be caused by #4650.

The new generate_unique_id() function uses list(route.methods)[0].lower() as suffix for the operation_id. Therefore, in my example, both post and delete endpoints get _post suffix for operation_id, causing it to no longer be unique.

It then issues a “UserWarning: Duplicate Operation ID”

Operating System

Windows

Operating System Details

No response

FastAPI Version

0.75.0

Python Version

3.10.2

Additional Context

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:3
  • Comments:12

github_iconTop GitHub Comments

1reaction
stapetrocommented, Aug 23, 2022

Hello @bneijt, I confirm I hit the same issue with fastapi@0.79.1. I’ve decorated a method like this:

@router.api_route(
    "/example",
    methods=["POST", "PUT"],
    status_code=status.HTTP_201_CREATED,
)
async def save_example(...)
  pass
1reaction
bruchar1commented, Apr 19, 2022

No. @mbrav problem is unrelated to this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Openapi - duplicate operationID and extra parameter
When I generate my Openapi schema, a second route with an additional parameter {format} is added for each of my paths, with the...
Read more >
Schemas - Django REST framework
The operationId is camelCase by convention. get_operation_id_base(). If you have several views with the same model name, you may see duplicate operationIds. In ......
Read more >
Step 4: The paths object (OpenAPI tutorial) | Documenting APIs
The paths object has several sub-objects: a path items object, an operations ... (Operations are the GET, POST, PUT, and DELETE methods we ......
Read more >
Links - Swagger
Using links, you can describe how various values returned by one ... This approach can be used for local links only, because the...
Read more >
Seven Tips For Using Swagger And AutoRest Together In ...
For any new or existing project, configure the swagger generator: ... In case a controller has multiple methods with the same verb, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found