From 86fd8882e59de5f5118842bbfd23edd72a2b6d5f Mon Sep 17 00:00:00 2001 From: Harish Karumuthil Date: Mon, 10 Oct 2022 08:06:23 +0530 Subject: [PATCH] Fix: Replace slash from generated operationId (#264) Fix: Replace '/' with _ in operationId Fixes #263 Signed-off-by: Harish Karumuthil Signed-off-by: Harish Karumuthil (cherry picked from commit b96a490bd6a2a43e76f34e1b4fe9cecbc0ac5c88) --- 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 833e969e..0a22b45b 100644 --- a/spectree/spec.py +++ b/spectree/spec.py @@ -274,7 +274,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 1fb9c453..376c35e9 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -68,7 +68,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"]