From b45b6aec49527624e774cd3557b1cb1e2a63f5de Mon Sep 17 00:00:00 2001 From: Harish Karumuthil Date: Mon, 10 Oct 2022 02:24:39 +0530 Subject: [PATCH] Fix: Replace '/' with _ in operationId Fixes #263 Signed-off-by: Harish Karumuthil --- spectree/spec.py | 2 +- tests/test_plugin.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spectree/spec.py b/spectree/spec.py index c2f32a3b..b2cae016 100644 --- a/spectree/spec.py +++ b/spectree/spec.py @@ -277,7 +277,7 @@ def _generate_spec(self) -> Dict[str, Any]: routes[path][method.lower()] = { "summary": summary or f"{name} <{method}>", - "operationId": f"{method.lower()}_{path}", + "operationId": f"{method.lower()}_{path.replace('/', '_')}", "description": desc or "", "tags": [str(x) for x in getattr(func, "tags", ())], "parameters": parse_params(func, parameters[:], self.models), diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 9645ce18..840b5ed2 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -69,7 +69,7 @@ def test_plugin_spec(api): assert ping["parameters"][0]["in"] == "header" assert ping["summary"] == "summary" assert ping["description"] == "description" - assert ping["operationId"] == "get_/ping" + assert ping["operationId"] == "get__ping" user = api.spec["paths"]["/api/user/{name}"]["post"] assert user["tags"] == ["API", "test"]