From 1eff848a67ba3bf53ce8f2ee10f18d7282dd0808 Mon Sep 17 00:00:00 2001 From: luolingchun Date: Sat, 10 May 2025 12:14:37 +0800 Subject: [PATCH] operation_id_callback with blueprint name and func name --- flask_openapi3/blueprint.py | 2 +- tests/test_api_blueprint.py | 2 +- tests/test_options_in_viewfunc.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/flask_openapi3/blueprint.py b/flask_openapi3/blueprint.py index b0b85c39..4719caa9 100644 --- a/flask_openapi3/blueprint.py +++ b/flask_openapi3/blueprint.py @@ -163,7 +163,7 @@ def _collect_openapi_info( # Unique string used to identify the operation. operation.operationId = operation_id or self.operation_id_callback( - name=self.name, path=rule, method=method + name=f"{self.name}&{func.__name__}", path=rule, method=method ) # Only set `deprecated` if True, otherwise leave it as None diff --git a/tests/test_api_blueprint.py b/tests/test_api_blueprint.py index 4ca6bfcc..ff106f0a 100644 --- a/tests/test_api_blueprint.py +++ b/tests/test_api_blueprint.py @@ -104,7 +104,7 @@ def test_openapi(client): assert resp.status_code == 200 assert resp.json == app.api_doc assert resp.json["paths"]["/api/book/{bid}"]["put"]["operationId"] == "update" - assert resp.json["paths"]["/api/book/{bid}"]["delete"]["operationId"] == "_book_book__int_bid__delete" + assert resp.json["paths"]["/api/book/{bid}"]["delete"]["operationId"] == "_book_delete_book_book__int_bid__delete" def test_post(client): diff --git a/tests/test_options_in_viewfunc.py b/tests/test_options_in_viewfunc.py index b22e920e..b48dec75 100644 --- a/tests/test_options_in_viewfunc.py +++ b/tests/test_options_in_viewfunc.py @@ -49,7 +49,7 @@ def test_openapi(client): assert resp.status_code == 200 assert resp.json == app.api_doc assert resp.json["paths"]["/book"]["get"]["operationId"] == "get_book_book_get" # Default operation_id generator - assert resp.json["paths"]["/api/book"]["post"]["operationId"] == "/book" # Custom callback operation_id + assert resp.json["paths"]["/api/book"]["post"]["operationId"] == "/book&create_book" # Custom callback operation_id def test_get(client):