Merge ~lloydwaltersj/maas:oapi-line-break-op-desc into maas:master

Proposed by Jack Lloyd-Walters
Status: Merged
Approved by: Jack Lloyd-Walters
Approved revision: 3b18ced2992ada2ea068ca3c84345b197ec6c6e4
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~lloydwaltersj/maas:oapi-line-break-op-desc
Merge into: maas:master
Diff against target: 128 lines (+60/-7)
2 files modified
src/maasserver/api/doc_oapi.py (+17/-6)
src/maasserver/api/tests/test_oapi.py (+43/-1)
Reviewer Review Type Date Requested Status
MAAS Lander Approve
Adam Collard (community) Approve
Review via email: mp+428727@code.launchpad.net

Commit message

Remove ungrammatical linebreak in operation description

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

UNIT TESTS
-b oapi-line-break-op-desc lp:~lloydwaltersj/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/364/consoleText
COMMIT: 05fd9ccfcdb9b0725509fafb755e91539b2d9c29

review: Needs Fixing
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b oapi-line-break-op-desc lp:~lloydwaltersj/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/365/consoleText
COMMIT: da502e5fd6f5a0e4d399ff41443161312e042dd9

review: Needs Fixing
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b oapi-line-break-op-desc lp:~lloydwaltersj/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 602d019fa8e0c9413ab5212df706a3a0a78b5a4e

review: Approve
Revision history for this message
Christian Grabowski (cgrabowski) :
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b oapi-line-break-op-desc lp:~lloydwaltersj/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/367/consoleText
COMMIT: 2fc42091a1a65aa326173ac8f7cf66a3eaf36030

review: Needs Fixing
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b oapi-line-break-op-desc lp:~lloydwaltersj/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 3b18ced2992ada2ea068ca3c84345b197ec6c6e4

review: Approve
Revision history for this message
Adam Collard (adam-collard) :
review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

LANDING
-b oapi-line-break-op-desc lp:~lloydwaltersj/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED BUILD
LOG: http://maas-ci.internal:8080/job/maas-tester/377/consoleText

Revision history for this message
Jack Lloyd-Walters (lloydwaltersj) wrote :

jenkins: !test

Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b oapi-line-break-op-desc lp:~lloydwaltersj/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 3b18ced2992ada2ea068ca3c84345b197ec6c6e4

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 543c571..c579acd 100644
--- a/src/maasserver/api/doc_oapi.py
+++ b/src/maasserver/api/doc_oapi.py
@@ -9,6 +9,7 @@ This definition follows the rules and limitations of the ReST documentation.
99
10from inspect import getdoc10from inspect import getdoc
11import json11import json
12import re
12from textwrap import dedent13from textwrap import dedent
1314
14from django.http import HttpResponse15from django.http import HttpResponse
@@ -135,13 +136,21 @@ def _new_path_item(params):
135 return path_item136 return path_item
136137
137138
139def _prettify(doc):
140 """Cleans up text by replacing newlines with spaces, so that sentences are
141 not broken apart prematurely.
142 Respects paragraphing by not replacing newlines that occur after periods.
143 """
144 return re.sub("(?<![.\n])[\n]+", " ", dedent(doc)).strip()
145
146
138def _render_oapi_oper_item(http_method, op, doc, uri_params, function):147def _render_oapi_oper_item(http_method, op, doc, uri_params, function):
139 oper_id = op or support.OperationsResource.crudmap.get(http_method)148 oper_id = op or support.OperationsResource.crudmap.get(http_method)
140 oper_obj = {149 oper_obj = {
141 "operationId": f"{doc.name}_{oper_id}",150 "operationId": f"{doc.name}_{oper_id}",
142 "tags": [doc.handler.api_doc_section_name],151 "tags": [doc.handler.api_doc_section_name],
143 "summary": f"{doc.name} {oper_id}",152 "summary": f"{doc.name} {oper_id}",
144 "description": dedent(doc.doc).strip(),153 "description": _prettify(doc.doc),
145 "responses": {},154 "responses": {},
146 }155 }
147 oper_docstring = _oapi_item_from_docstring(156 oper_docstring = _oapi_item_from_docstring(
@@ -192,9 +201,9 @@ def _oapi_item_from_docstring(function, http_method, uri_params):
192 ap.parse(docstring)201 ap.parse(docstring)
193 ap_dict = ap.get_dict()202 ap_dict = ap.get_dict()
194 oper_obj["summary"] = ap_dict["description_title"].strip()203 oper_obj["summary"] = ap_dict["description_title"].strip()
195 oper_obj["description"] = ap_dict["description"].strip()204 oper_obj["description"] = _prettify(ap_dict["description"])
196 for param in ap_dict["params"]:205 for param in ap_dict["params"]:
197 description = param["description_stripped"]206 description = _prettify(param["description_stripped"])
198 name = param["name"].strip("}{")207 name = param["name"].strip("}{")
199 required = param["options"]["required"].lower() == "true"208 required = param["options"]["required"].lower() == "true"
200 if param["name"][0] == "{":209 if param["name"][0] == "{":
@@ -222,8 +231,10 @@ def _oapi_item_from_docstring(function, http_method, uri_params):
222231
223 for (status, content) in _response_pair(ap_dict):232 for (status, content) in _response_pair(ap_dict):
224 response = {233 response = {
225 "description": content.get(234 "description": _prettify(
226 "description_stripped", status["description_stripped"]235 content.get(
236 "description_stripped", status["description_stripped"]
237 )
227 ),238 ),
228 }239 }
229 match content.get("type", "").lower():240 match content.get("type", "").lower():
@@ -254,7 +265,7 @@ def _oapi_item_from_docstring(function, http_method, uri_params):
254265
255 status_code = status["name"]266 status_code = status["name"]
256 if not status_code.isdigit():267 if not status_code.isdigit():
257 status_code = status["description_stripped"]268 status_code = _prettify(status["description_stripped"])
258 oper_obj.setdefault("responses", {}).update(269 oper_obj.setdefault("responses", {}).update(
259 {status_code: response},270 {status_code: response},
260 )271 )
diff --git a/src/maasserver/api/tests/test_oapi.py b/src/maasserver/api/tests/test_oapi.py
index 0e27da9..d22c2cc 100644
--- a/src/maasserver/api/tests/test_oapi.py
+++ b/src/maasserver/api/tests/test_oapi.py
@@ -5,7 +5,12 @@ import json
55
6import yaml6import yaml
77
8from maasserver.api.doc_oapi import _render_oapi_paths, endpoint, landing_page8from maasserver.api.doc_oapi import (
9 _prettify,
10 _render_oapi_paths,
11 endpoint,
12 landing_page,
13)
9from maasserver.models.config import Config14from maasserver.models.config import Config
10from maasserver.testing.factory import factory15from maasserver.testing.factory import factory
11from maasserver.testing.testcase import MAASServerTestCase16from maasserver.testing.testcase import MAASServerTestCase
@@ -105,3 +110,40 @@ class TestOAPISpec(MAASServerTestCase):
105 for k, v in _get_all_key_values(_render_oapi_paths()):110 for k, v in _get_all_key_values(_render_oapi_paths()):
106 if k == "type":111 if k == "type":
107 self.assertIn(v, self.oapi_types)112 self.assertIn(v, self.oapi_types)
113
114
115class TestPrettify(MAASTestCase):
116 maxDiff = None
117
118 def test_cleans_newlines(self):
119 before = """\
120Returns system details -- for example, LLDP and
121
122``lshw`` XML dumps.
123
124
125Returns a ``{detail_type: xml, ...}`` map, where
126
127``detail_type`` is something like "lldp" or "lshw".
128
129
130Note that this is returned as BSON and not JSON. This is for
131
132efficiency, but mainly because JSON can''t do binary content without
133
134applying additional encoding like base-64. The example output below is
135
136represented in ASCII using ``bsondump example.bson`` and is for
137
138demonstrative purposes."""
139
140 after = """\
141Returns system details -- for example, LLDP and ``lshw`` XML dumps.
142
143
144Returns a ``{detail_type: xml, ...}`` map, where ``detail_type`` is something like "lldp" or "lshw".
145
146
147Note that this is returned as BSON and not JSON. This is for efficiency, but mainly because JSON can''t do binary content without applying additional encoding like base-64. The example output below is represented in ASCII using ``bsondump example.bson`` and is for demonstrative purposes."""
148
149 self.assertEqual(_prettify(before), after)

Subscribers

People subscribed via source and target branches