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
diff --git a/src/maasserver/api/doc_oapi.py b/src/maasserver/api/doc_oapi.py
index e2ecfcf..480a223 100644
--- a/src/maasserver/api/doc_oapi.py
+++ b/src/maasserver/api/doc_oapi.py
@@ -22,6 +22,11 @@ from maasserver.djangosettings import settings
22from maasserver.models.config import Config22from maasserver.models.config import Config
23from maasserver.utils import build_absolute_uri23from maasserver.utils import build_absolute_uri
2424
25# LP 2009140: Match a par of brackets enclosing a string, return only the string within the brackets.
26# Functions as a more context aware equivalent to string.strip("}{")
27# ie: '{param}' returns 'param', 'param_{test}' is unnafected
28PARAM_RE = re.compile(r"(?<=\{)\.+(?<=\})")
29
2530
26def landing_page(request):31def landing_page(request):
27 """Render a landing page with pointers for the MAAS API.32 """Render a landing page with pointers for the MAAS API.
@@ -213,8 +218,11 @@ def _oapi_item_from_docstring(
213 oper_obj["deprecated"] = True218 oper_obj["deprecated"] = True
214 for param in ap_dict["params"]:219 for param in ap_dict["params"]:
215 description = _prettify(param["description_stripped"])220 description = _prettify(param["description_stripped"])
216 name = param["name"].strip("}{")221 # LP 2009140
217 path_var = name in uri_params222 stripped_name = PARAM_RE.match(param["name"])
223 name = (
224 param["name"] if not stripped_name else stripped_name.group()
225 )
218 required = (226 required = (
219 param["options"]["required"].lower() == "true"227 param["options"]["required"].lower() == "true"
220 or name != param["name"]228 or name != param["name"]
@@ -223,7 +231,7 @@ def _oapi_item_from_docstring(
223 if name != param["name"]:231 if name != param["name"]:
224 param_dict = {232 param_dict = {
225 "name": name,233 "name": name,
226 "in": "path" if path_var else "query",234 "in": "path" if name in uri_params else "query",
227 "description": description,235 "description": description,
228 "schema": {236 "schema": {
229 "type": _type_to_string(param["type"]),237 "type": _type_to_string(param["type"]),

Subscribers

People subscribed via source and target branches