Skip to content

Commit

Permalink
Sort methods to stabalize operation id generation
Browse files Browse the repository at this point in the history
The methods attribute accessed by the `generate_unique_id` function is modeled as a python set, which is not ordered and between runs might change. This results in the same fastapi generating different openapi specs if started multiple times.

This also relates to the bigger issue #4740 but is not a solution for that issue.
  • Loading branch information
bneijt committed Jun 8, 2022
1 parent 1876ebc commit 6379d7b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion fastapi/utils.py
Expand Up @@ -142,7 +142,7 @@ def generate_unique_id(route: "APIRoute") -> str:
operation_id = route.name + route.path_format
operation_id = re.sub("[^0-9a-zA-Z_]", "_", operation_id)
assert route.methods
operation_id = operation_id + "_" + list(route.methods)[0].lower()
operation_id = operation_id + "_" + sorted(route.methods)[0].lower()
return operation_id


Expand Down

0 comments on commit 6379d7b

Please sign in to comment.