Browse Source

Fix operation ID: exclude HEAD from unique_id generation

generate_unique_id was picking HEAD as the first method in the set,
producing operationId like read_items__head instead of read_items__get.
Now excludes HEAD and prioritizes GET for the operation ID suffix.
pull/15359/head
Thor Agent 3 months ago
parent
commit
c9293d508e
  1. 2
      fastapi/utils.py

2
fastapi/utils.py

@ -96,7 +96,7 @@ def generate_unique_id(route: "APIRoute") -> str:
operation_id = f"{route.name}{route.path_format}" operation_id = f"{route.name}{route.path_format}"
operation_id = re.sub(r"\W", "_", operation_id) operation_id = re.sub(r"\W", "_", operation_id)
assert route.methods assert route.methods
operation_id = f"{operation_id}_{list(route.methods)[0].lower()}" operation_id = f"{operation_id}_{sorted(route.methods - {'HEAD'}, key=lambda m: 0 if m == 'GET' else 1)[0].lower()}"
return operation_id return operation_id

Loading…
Cancel
Save