Merge ~lloydwaltersj/maas:backport-2009140 into maas:3.3

Proposed by Jack Lloyd-Walters
Status: Merged
Approved by: Alexsander de Souza
Approved revision: a82bad70a081748ffd2021d834d0519d719ece85
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~lloydwaltersj/maas:backport-2009140
Merge into: maas:3.3
Diff against target: 39 lines (+11/-3)
1 file modified
src/maasserver/api/doc_oapi.py (+11/-3)
Reviewer Review Type Date Requested Status
Alexsander de Souza Approve
MAAS Lander Approve
Review via email: mp+438335@code.launchpad.net

Commit message

fix LP:2009140, OpenApi parameter names erroneously stripped of trailing '}'

(cherry picked from commit faeff957c4a3b16ca487e187b64148c92001a84d)

To post a comment you must log in.
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b backport-2009140 lp:~lloydwaltersj/maas/+git/maas into -b 3.3 lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: a82bad70a081748ffd2021d834d0519d719ece85

review: Approve
Revision history for this message
Alexsander de Souza (alexsander-souza) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/api/doc_oapi.py b/src/maasserver/api/doc_oapi.py
2index e2ecfcf..480a223 100644
3--- a/src/maasserver/api/doc_oapi.py
4+++ b/src/maasserver/api/doc_oapi.py
5@@ -22,6 +22,11 @@ from maasserver.djangosettings import settings
6 from maasserver.models.config import Config
7 from maasserver.utils import build_absolute_uri
8
9+# LP 2009140: Match a par of brackets enclosing a string, return only the string within the brackets.
10+# Functions as a more context aware equivalent to string.strip("}{")
11+# ie: '{param}' returns 'param', 'param_{test}' is unnafected
12+PARAM_RE = re.compile(r"(?<=\{)\.+(?<=\})")
13+
14
15 def landing_page(request):
16 """Render a landing page with pointers for the MAAS API.
17@@ -213,8 +218,11 @@ def _oapi_item_from_docstring(
18 oper_obj["deprecated"] = True
19 for param in ap_dict["params"]:
20 description = _prettify(param["description_stripped"])
21- name = param["name"].strip("}{")
22- path_var = name in uri_params
23+ # LP 2009140
24+ stripped_name = PARAM_RE.match(param["name"])
25+ name = (
26+ param["name"] if not stripped_name else stripped_name.group()
27+ )
28 required = (
29 param["options"]["required"].lower() == "true"
30 or name != param["name"]
31@@ -223,7 +231,7 @@ def _oapi_item_from_docstring(
32 if name != param["name"]:
33 param_dict = {
34 "name": name,
35- "in": "path" if path_var else "query",
36+ "in": "path" if name in uri_params else "query",
37 "description": description,
38 "schema": {
39 "type": _type_to_string(param["type"]),

Subscribers

People subscribed via source and target branches