Merge ~lloydwaltersj/maas:fix-oapi-docs into maas:master

Proposed by Jack Lloyd-Walters
Status: Merged
Approved by: Jack Lloyd-Walters
Approved revision: 2800e6eef6cddee649e2ca135c4c9b5a03ab30d7
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~lloydwaltersj/maas:fix-oapi-docs
Merge into: maas:master
Diff against target: 217 lines (+33/-61)
7 files modified
.gitignore (+1/-0)
Makefile (+4/-1)
src/maasserver/api/doc_oapi.py (+1/-27)
src/maasserver/api/tests/test_oapi.py (+1/-18)
src/maasserver/management/commands/generate_oapi_spec.py (+17/-0)
src/maasserver/templates/openapi.html (+7/-7)
src/maasserver/urls.py (+2/-8)
Reviewer Review Type Date Requested Status
MAAS Lander Approve
Adam Collard (community) Approve
Alexsander de Souza Approve
Review via email: mp+427900@code.launchpad.net

Commit message

Add oapi spec to makefile for external usage

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

UNIT TESTS
-b fix-oapi-docs lp:~lloydwaltersj/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/271/consoleText
COMMIT: 1f7779db0113d9e0925d279f31449bafd8aa6298

review: Needs Fixing
~lloydwaltersj/maas:fix-oapi-docs updated
23a1cb3... by Jack Lloyd-Walters

fix leftover argument

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

UNIT TESTS
-b fix-oapi-docs lp:~lloydwaltersj/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/272/consoleText
COMMIT: 23a1cb3260ef16b9443af2ca23b979f0f8da5130

review: Needs Fixing
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 fix-oapi-docs lp:~lloydwaltersj/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/273/consoleText
COMMIT: 23a1cb3260ef16b9443af2ca23b979f0f8da5130

review: Needs Fixing
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 fix-oapi-docs lp:~lloydwaltersj/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/274/consoleText
COMMIT: 23a1cb3260ef16b9443af2ca23b979f0f8da5130

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

I have no idea what's happening here

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 fix-oapi-docs lp:~lloydwaltersj/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/275/consoleText
COMMIT: 23a1cb3260ef16b9443af2ca23b979f0f8da5130

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

please change the file name

review: Needs Fixing
~lloydwaltersj/maas:fix-oapi-docs updated
00ce99a... by Jack Lloyd-Walters

change filename

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

UNIT TESTS
-b fix-oapi-docs lp:~lloydwaltersj/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/315/consoleText
COMMIT: 00ce99a9c4653ca5fd70d7b12a6018aeb5faadbb

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

+1

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

jenkins: !test

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

UNIT TESTS
-b fix-oapi-docs lp:~lloydwaltersj/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/324/consoleText
COMMIT: 00ce99a9c4653ca5fd70d7b12a6018aeb5faadbb

review: Needs Fixing
~lloydwaltersj/maas:fix-oapi-docs updated
8605451... by Jack Lloyd-Walters

switch to lambda expression

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

UNIT TESTS
-b fix-oapi-docs lp:~lloydwaltersj/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/328/consoleText
COMMIT: 8605451efb8340487131676b3f076e713ff9e06d

review: Needs Fixing
~lloydwaltersj/maas:fix-oapi-docs updated
9fd1f8d... by Jack Lloyd-Walters

checking without context

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

UNIT TESTS
-b fix-oapi-docs lp:~lloydwaltersj/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/331/consoleText
COMMIT: 9fd1f8d033a62ca0947698acae55889ac3402a23

review: Needs Fixing
~lloydwaltersj/maas:fix-oapi-docs updated
35e1728... by Jack Lloyd-Walters

fix twisted error

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

UNIT TESTS
-b fix-oapi-docs lp:~lloydwaltersj/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/332/consoleText
COMMIT: 35e1728e3a9260804da8eaa521aecb1eac8f4163

review: Needs Fixing
~lloydwaltersj/maas:fix-oapi-docs updated
e286c8a... by Jack Lloyd-Walters

trim unnecesary function

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

UNIT TESTS
-b fix-oapi-docs lp:~lloydwaltersj/maas/+git/maas into -b master lp:~maas-committers/maas

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

review: Needs Fixing
~lloydwaltersj/maas:fix-oapi-docs updated
77f804f... by Jack Lloyd-Walters

bring branch up to parity

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

UNIT TESTS
-b fix-oapi-docs lp:~lloydwaltersj/maas/+git/maas into -b master lp:~maas-committers/maas

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

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

UNIT TESTS
-b fix-oapi-docs lp:~lloydwaltersj/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/335/consoleText
COMMIT: 301eaf5f6e2be7f32a646c23c0caf788c7b54c93

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

UNIT TESTS
-b fix-oapi-docs lp:~lloydwaltersj/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/336/consoleText
COMMIT: 4cdc996aafa309d27745e980c7d079e4bbc9d079

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

UNIT TESTS
-b fix-oapi-docs lp:~lloydwaltersj/maas/+git/maas into -b master lp:~maas-committers/maas

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

review: Needs Fixing
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 fix-oapi-docs lp:~lloydwaltersj/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: a0318b288a36740969a4cc473512870d6d69f505

review: Approve
Revision history for this message
Adam Collard (adam-collard) :
review: Needs Fixing
Revision history for this message
Jack Lloyd-Walters (lloydwaltersj) :
~lloydwaltersj/maas:fix-oapi-docs updated
7c3d2f1... by Jack Lloyd-Walters

fix problem with submodule

424bd8e... by Jack Lloyd-Walters

change name in gitignore too

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

UNIT TESTS
-b fix-oapi-docs lp:~lloydwaltersj/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 7c3d2f17c0a5937afc6bd577b2fced474b46627b

review: Approve
~lloydwaltersj/maas:fix-oapi-docs updated
397e0ee... by Jack Lloyd-Walters

remove hash form CSS

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

UNIT TESTS
-b fix-oapi-docs lp:~lloydwaltersj/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/344/consoleText
COMMIT: 397e0eea564944b6f04188aeb032d1749df5aa2a

review: Needs Fixing
~lloydwaltersj/maas:fix-oapi-docs updated
f011fa0... by Jack Lloyd-Walters

linting and formating

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

UNIT TESTS
-b fix-oapi-docs lp:~lloydwaltersj/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: f011fa0bf1232cfee822e6411b7030eb1c18b16f

review: Approve
Revision history for this message
Adam Collard (adam-collard) :
review: Approve
~lloydwaltersj/maas:fix-oapi-docs updated
2800e6e... by Jack Lloyd-Walters

change output stream for yaml dump

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

UNIT TESTS
-b fix-oapi-docs lp:~lloydwaltersj/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 2800e6eef6cddee649e2ca135c4c9b5a03ab30d7

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/.gitignore b/.gitignore
2index d84ca68..31cd627 100644
3--- a/.gitignore
4+++ b/.gitignore
5@@ -26,6 +26,7 @@
6 /develop-eggs
7 /dist
8 /api-docs.rst
9+/openapi.yaml
10 /eggs
11 /etc/maas/rackd.conf
12 /etc/maas/regiond.conf
13diff --git a/Makefile b/Makefile
14index cd8f092..5a5c2af 100644
15--- a/Makefile
16+++ b/Makefile
17@@ -218,7 +218,10 @@ check: clean test
18 api-docs.rst: bin/maas-region src/maasserver/api/doc_handler.py syncdb
19 bin/maas-region generate_api_doc > $@
20
21-doc: api-docs.rst
22+openapi.yaml: bin/maas-region src/maasserver/api/doc_handler.py syncdb
23+ bin/maas-region generate_oapi_spec > $@
24+
25+doc: api-docs.rst openapi.yaml
26 .PHONY: doc
27
28 .run: run-skel
29diff --git a/src/maasserver/api/doc_oapi.py b/src/maasserver/api/doc_oapi.py
30index d747499..1676c57 100644
31--- a/src/maasserver/api/doc_oapi.py
32+++ b/src/maasserver/api/doc_oapi.py
33@@ -19,35 +19,9 @@ from maasserver.api.annotations import APIDocstringParser
34 from maasserver.api.doc import find_api_resources, generate_doc
35 from maasserver.djangosettings import settings
36 from maasserver.models.config import Config
37-from maasserver.models.controllerinfo import get_maas_version
38 from maasserver.utils import build_absolute_uri
39
40
41-def openapi_docs_context(request):
42- """Return the aadditional context needed for the oapi doc template to function"""
43- colourmap = {
44- "bark": "#585841",
45- "blue": "#0060bf",
46- "magenta": "#974097",
47- "olive": "#3d5f11",
48- "prussian green": "#225d5c",
49- "purple": "#7764d8",
50- "red": "#a71b33",
51- "sage": "#4e5f51",
52- "viridian": "#025a3d",
53- }
54- local_server = _get_maas_servers()[0]
55- context = {
56- "openapi_url": local_server["url"] + "openapi.yaml",
57- "maas_colour": colourmap.get(
58- Config.objects.get_config("theme").lower(), "#262626"
59- ),
60- "maas_name": local_server["description"].removesuffix(" API"),
61- "maas_version": get_maas_version(),
62- }
63- return context
64-
65-
66 def landing_page(request):
67 """Render a landing page with pointers for the MAAS API.
68
69@@ -71,6 +45,7 @@ def endpoint(request):
70 with the OpenApi spec 3.0.
71 """
72 description = get_api_endpoint()
73+ description["servers"] = _get_maas_servers()
74 # Return as a YAML document
75 return HttpResponse(
76 yaml.dump(description),
77@@ -125,7 +100,6 @@ def get_api_endpoint():
78 "description": "MAAS API documentation",
79 "url": "/MAAS/docs/api.html",
80 },
81- "servers": _get_maas_servers(),
82 }
83 return description
84
85diff --git a/src/maasserver/api/tests/test_oapi.py b/src/maasserver/api/tests/test_oapi.py
86index 641726d..0e27da9 100644
87--- a/src/maasserver/api/tests/test_oapi.py
88+++ b/src/maasserver/api/tests/test_oapi.py
89@@ -5,12 +5,7 @@ import json
90
91 import yaml
92
93-from maasserver.api.doc_oapi import (
94- _render_oapi_paths,
95- endpoint,
96- landing_page,
97- openapi_docs_context,
98-)
99+from maasserver.api.doc_oapi import _render_oapi_paths, endpoint, landing_page
100 from maasserver.models.config import Config
101 from maasserver.testing.factory import factory
102 from maasserver.testing.testcase import MAASServerTestCase
103@@ -58,18 +53,6 @@ class TestApiEndpoint(MAASServerTestCase):
104 self.assertEqual(maasserver["description"], f"{maas_name} API")
105
106
107-class TestOAPIDocs(MAASServerTestCase):
108- def test_docs_point_to_api(self):
109- request = factory.make_fake_request()
110- page = landing_page(request)
111- content = json.loads(page.content)
112- oapi_res = content["resources"][1]
113- context = openapi_docs_context(request)
114- self.assertEqual(
115- context["openapi_url"], f"http://localhost:5240{oapi_res['path']}"
116- )
117-
118-
119 class TestOAPISpec(MAASServerTestCase):
120 def setUp(self):
121 self.oapi_types = ["boolean", "integer", "number", "object", "string"]
122diff --git a/src/maasserver/management/commands/generate_oapi_spec.py b/src/maasserver/management/commands/generate_oapi_spec.py
123new file mode 100644
124index 0000000..5299fcc
125--- /dev/null
126+++ b/src/maasserver/management/commands/generate_oapi_spec.py
127@@ -0,0 +1,17 @@
128+# Copyright 2022 Canonical Ltd. This software is licensed under the
129+# GNU Affero General Public License version 3 (see the file LICENSE).
130+
131+"""Django command: generate the Open API specification."""
132+
133+
134+from django.core.management.base import BaseCommand
135+import yaml
136+
137+from maasserver.api.doc_oapi import get_api_endpoint
138+
139+
140+class Command(BaseCommand):
141+ def handle(self, *args, **options):
142+ oapi = get_api_endpoint()
143+ oapi["externalDocs"]["url"] = "https://maas.io/docs"
144+ yaml.dump(oapi, self.stdout)
145diff --git a/src/maasserver/templates/openapi.html b/src/maasserver/templates/openapi.html
146index 5381de5..41c492b 100644
147--- a/src/maasserver/templates/openapi.html
148+++ b/src/maasserver/templates/openapi.html
149@@ -4,8 +4,8 @@
150 <head>
151 <meta charset="UTF-8">
152 <title>MAAS API</title>
153- <link href="/MAAS/r/static/css/main.05850fff.css" rel="stylesheet">
154- <link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@4.5.0/swagger-ui.css" />
155+ <link href="https://maas.io/static/css/main.css" rel="stylesheet">
156+ <link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@latest/swagger-ui.css" />
157 <style>
158 html * {
159 font-family: ubuntu !important;
160@@ -23,7 +23,7 @@
161 </head>
162
163 <body>
164- <header class="p-navigation is-dark" style="background-color: {{ maas_colour }};">
165+ <header class="p-navigation is-dark" style="background-color: #262626;">
166 <div class="p-navigation__row">
167 <div class="p-navigation__banner">
168 <div class="p-navigation__tagged-logo">
169@@ -45,16 +45,16 @@
170 </div>
171 <div style="margin: auto; margin-right:0;">
172 <a aria-label="Homepage" class="p-navigation__link" href="/MAAS/api/">
173- <div class="p-navigation__logo-title">{{ maas_name }} MAAS: {{ maas_version }}</div>
174+ <div class="p-navigation__logo-title">MAAS</div>
175 </a>
176 </div>
177 </header>
178- <div id="swagger-ui" style="max-width: 90rem; margin: auto;"></div>
179- <script src="https://unpkg.com/swagger-ui-dist@4.5.0/swagger-ui-bundle.js" crossorigin></script>
180+ <div id="swagger-ui" style="max-width: 72rem; margin: auto;"></div>
181+ <script src="https://unpkg.com/swagger-ui-dist@latest/swagger-ui-bundle.js" crossorigin></script>
182 <script>
183 window.onload = function() {
184 window.ui = SwaggerUIBundle({
185- url: "{{ openapi_url }}",
186+ url: "/MAAS/api/2.0/openapi.yaml",
187 dom_id: '#swagger-ui',
188 deepLinking: true,
189 presets: [
190diff --git a/src/maasserver/urls.py b/src/maasserver/urls.py
191index 63ef2ec..2f3169c 100644
192--- a/src/maasserver/urls.py
193+++ b/src/maasserver/urls.py
194@@ -9,7 +9,7 @@ from django.urls import include, re_path
195 from django.views.generic import TemplateView
196
197 from maasserver import urls_api
198-from maasserver.api.doc_oapi import landing_page, openapi_docs_context
199+from maasserver.api.doc_oapi import landing_page
200 from maasserver.bootresources import (
201 simplestreams_file_handler,
202 simplestreams_stream_handler,
203@@ -78,13 +78,7 @@ urlpatterns += [re_path(r"^accounts/logout/$", logout, name="logout")]
204 # API URLs. If old API requested, provide error message directing to new API.
205 urlpatterns += [
206 re_path(r"^api/$", landing_page),
207- re_path(
208- r"^api/docs/",
209- lambda request: TemplateView.as_view(
210- template_name="openapi.html",
211- extra_context=openapi_docs_context(request),
212- ),
213- ),
214+ re_path(r"^api/docs/", TemplateView.as_view(template_name="openapi.html")),
215 re_path(r"^api/2\.0/", include(urls_api)),
216 re_path(
217 r"^api/version/",

Subscribers

People subscribed via source and target branches