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
diff --git a/.gitignore b/.gitignore
index d84ca68..31cd627 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,6 +26,7 @@
26/develop-eggs26/develop-eggs
27/dist27/dist
28/api-docs.rst28/api-docs.rst
29/openapi.yaml
29/eggs30/eggs
30/etc/maas/rackd.conf31/etc/maas/rackd.conf
31/etc/maas/regiond.conf32/etc/maas/regiond.conf
diff --git a/Makefile b/Makefile
index cd8f092..5a5c2af 100644
--- a/Makefile
+++ b/Makefile
@@ -218,7 +218,10 @@ check: clean test
218api-docs.rst: bin/maas-region src/maasserver/api/doc_handler.py syncdb218api-docs.rst: bin/maas-region src/maasserver/api/doc_handler.py syncdb
219 bin/maas-region generate_api_doc > $@219 bin/maas-region generate_api_doc > $@
220220
221doc: api-docs.rst221openapi.yaml: bin/maas-region src/maasserver/api/doc_handler.py syncdb
222 bin/maas-region generate_oapi_spec > $@
223
224doc: api-docs.rst openapi.yaml
222.PHONY: doc225.PHONY: doc
223226
224.run: run-skel227.run: run-skel
diff --git a/src/maasserver/api/doc_oapi.py b/src/maasserver/api/doc_oapi.py
index d747499..1676c57 100644
--- a/src/maasserver/api/doc_oapi.py
+++ b/src/maasserver/api/doc_oapi.py
@@ -19,35 +19,9 @@ from maasserver.api.annotations import APIDocstringParser
19from maasserver.api.doc import find_api_resources, generate_doc19from maasserver.api.doc import find_api_resources, generate_doc
20from maasserver.djangosettings import settings20from maasserver.djangosettings import settings
21from maasserver.models.config import Config21from maasserver.models.config import Config
22from maasserver.models.controllerinfo import get_maas_version
23from maasserver.utils import build_absolute_uri22from maasserver.utils import build_absolute_uri
2423
2524
26def openapi_docs_context(request):
27 """Return the aadditional context needed for the oapi doc template to function"""
28 colourmap = {
29 "bark": "#585841",
30 "blue": "#0060bf",
31 "magenta": "#974097",
32 "olive": "#3d5f11",
33 "prussian green": "#225d5c",
34 "purple": "#7764d8",
35 "red": "#a71b33",
36 "sage": "#4e5f51",
37 "viridian": "#025a3d",
38 }
39 local_server = _get_maas_servers()[0]
40 context = {
41 "openapi_url": local_server["url"] + "openapi.yaml",
42 "maas_colour": colourmap.get(
43 Config.objects.get_config("theme").lower(), "#262626"
44 ),
45 "maas_name": local_server["description"].removesuffix(" API"),
46 "maas_version": get_maas_version(),
47 }
48 return context
49
50
51def landing_page(request):25def landing_page(request):
52 """Render a landing page with pointers for the MAAS API.26 """Render a landing page with pointers for the MAAS API.
5327
@@ -71,6 +45,7 @@ def endpoint(request):
71 with the OpenApi spec 3.0.45 with the OpenApi spec 3.0.
72 """46 """
73 description = get_api_endpoint()47 description = get_api_endpoint()
48 description["servers"] = _get_maas_servers()
74 # Return as a YAML document49 # Return as a YAML document
75 return HttpResponse(50 return HttpResponse(
76 yaml.dump(description),51 yaml.dump(description),
@@ -125,7 +100,6 @@ def get_api_endpoint():
125 "description": "MAAS API documentation",100 "description": "MAAS API documentation",
126 "url": "/MAAS/docs/api.html",101 "url": "/MAAS/docs/api.html",
127 },102 },
128 "servers": _get_maas_servers(),
129 }103 }
130 return description104 return description
131105
diff --git a/src/maasserver/api/tests/test_oapi.py b/src/maasserver/api/tests/test_oapi.py
index 641726d..0e27da9 100644
--- a/src/maasserver/api/tests/test_oapi.py
+++ b/src/maasserver/api/tests/test_oapi.py
@@ -5,12 +5,7 @@ import json
55
6import yaml6import yaml
77
8from maasserver.api.doc_oapi import (8from maasserver.api.doc_oapi import _render_oapi_paths, endpoint, landing_page
9 _render_oapi_paths,
10 endpoint,
11 landing_page,
12 openapi_docs_context,
13)
14from maasserver.models.config import Config9from maasserver.models.config import Config
15from maasserver.testing.factory import factory10from maasserver.testing.factory import factory
16from maasserver.testing.testcase import MAASServerTestCase11from maasserver.testing.testcase import MAASServerTestCase
@@ -58,18 +53,6 @@ class TestApiEndpoint(MAASServerTestCase):
58 self.assertEqual(maasserver["description"], f"{maas_name} API")53 self.assertEqual(maasserver["description"], f"{maas_name} API")
5954
6055
61class TestOAPIDocs(MAASServerTestCase):
62 def test_docs_point_to_api(self):
63 request = factory.make_fake_request()
64 page = landing_page(request)
65 content = json.loads(page.content)
66 oapi_res = content["resources"][1]
67 context = openapi_docs_context(request)
68 self.assertEqual(
69 context["openapi_url"], f"http://localhost:5240{oapi_res['path']}"
70 )
71
72
73class TestOAPISpec(MAASServerTestCase):56class TestOAPISpec(MAASServerTestCase):
74 def setUp(self):57 def setUp(self):
75 self.oapi_types = ["boolean", "integer", "number", "object", "string"]58 self.oapi_types = ["boolean", "integer", "number", "object", "string"]
diff --git a/src/maasserver/management/commands/generate_oapi_spec.py b/src/maasserver/management/commands/generate_oapi_spec.py
76new file mode 10064459new file mode 100644
index 0000000..5299fcc
--- /dev/null
+++ b/src/maasserver/management/commands/generate_oapi_spec.py
@@ -0,0 +1,17 @@
1# Copyright 2022 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3
4"""Django command: generate the Open API specification."""
5
6
7from django.core.management.base import BaseCommand
8import yaml
9
10from maasserver.api.doc_oapi import get_api_endpoint
11
12
13class Command(BaseCommand):
14 def handle(self, *args, **options):
15 oapi = get_api_endpoint()
16 oapi["externalDocs"]["url"] = "https://maas.io/docs"
17 yaml.dump(oapi, self.stdout)
diff --git a/src/maasserver/templates/openapi.html b/src/maasserver/templates/openapi.html
index 5381de5..41c492b 100644
--- a/src/maasserver/templates/openapi.html
+++ b/src/maasserver/templates/openapi.html
@@ -4,8 +4,8 @@
4 <head>4 <head>
5 <meta charset="UTF-8">5 <meta charset="UTF-8">
6 <title>MAAS API</title>6 <title>MAAS API</title>
7 <link href="/MAAS/r/static/css/main.05850fff.css" rel="stylesheet">7 <link href="https://maas.io/static/css/main.css" rel="stylesheet">
8 <link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@4.5.0/swagger-ui.css" />8 <link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@latest/swagger-ui.css" />
9 <style>9 <style>
10 html * {10 html * {
11 font-family: ubuntu !important;11 font-family: ubuntu !important;
@@ -23,7 +23,7 @@
23 </head>23 </head>
2424
25 <body>25 <body>
26 <header class="p-navigation is-dark" style="background-color: {{ maas_colour }};">26 <header class="p-navigation is-dark" style="background-color: #262626;">
27 <div class="p-navigation__row">27 <div class="p-navigation__row">
28 <div class="p-navigation__banner">28 <div class="p-navigation__banner">
29 <div class="p-navigation__tagged-logo">29 <div class="p-navigation__tagged-logo">
@@ -45,16 +45,16 @@
45 </div>45 </div>
46 <div style="margin: auto; margin-right:0;">46 <div style="margin: auto; margin-right:0;">
47 <a aria-label="Homepage" class="p-navigation__link" href="/MAAS/api/">47 <a aria-label="Homepage" class="p-navigation__link" href="/MAAS/api/">
48 <div class="p-navigation__logo-title">{{ maas_name }} MAAS: {{ maas_version }}</div>48 <div class="p-navigation__logo-title">MAAS</div>
49 </a>49 </a>
50 </div>50 </div>
51 </header>51 </header>
52 <div id="swagger-ui" style="max-width: 90rem; margin: auto;"></div>52 <div id="swagger-ui" style="max-width: 72rem; margin: auto;"></div>
53 <script src="https://unpkg.com/swagger-ui-dist@4.5.0/swagger-ui-bundle.js" crossorigin></script>53 <script src="https://unpkg.com/swagger-ui-dist@latest/swagger-ui-bundle.js" crossorigin></script>
54 <script>54 <script>
55 window.onload = function() {55 window.onload = function() {
56 window.ui = SwaggerUIBundle({56 window.ui = SwaggerUIBundle({
57 url: "{{ openapi_url }}",57 url: "/MAAS/api/2.0/openapi.yaml",
58 dom_id: '#swagger-ui',58 dom_id: '#swagger-ui',
59 deepLinking: true,59 deepLinking: true,
60 presets: [60 presets: [
diff --git a/src/maasserver/urls.py b/src/maasserver/urls.py
index 63ef2ec..2f3169c 100644
--- a/src/maasserver/urls.py
+++ b/src/maasserver/urls.py
@@ -9,7 +9,7 @@ from django.urls import include, re_path
9from django.views.generic import TemplateView9from django.views.generic import TemplateView
1010
11from maasserver import urls_api11from maasserver import urls_api
12from maasserver.api.doc_oapi import landing_page, openapi_docs_context12from maasserver.api.doc_oapi import landing_page
13from maasserver.bootresources import (13from maasserver.bootresources import (
14 simplestreams_file_handler,14 simplestreams_file_handler,
15 simplestreams_stream_handler,15 simplestreams_stream_handler,
@@ -78,13 +78,7 @@ urlpatterns += [re_path(r"^accounts/logout/$", logout, name="logout")]
78# API URLs. If old API requested, provide error message directing to new API.78# API URLs. If old API requested, provide error message directing to new API.
79urlpatterns += [79urlpatterns += [
80 re_path(r"^api/$", landing_page),80 re_path(r"^api/$", landing_page),
81 re_path(81 re_path(r"^api/docs/", TemplateView.as_view(template_name="openapi.html")),
82 r"^api/docs/",
83 lambda request: TemplateView.as_view(
84 template_name="openapi.html",
85 extra_context=openapi_docs_context(request),
86 ),
87 ),
88 re_path(r"^api/2\.0/", include(urls_api)),82 re_path(r"^api/2\.0/", include(urls_api)),
89 re_path(83 re_path(
90 r"^api/version/",84 r"^api/version/",

Subscribers

People subscribed via source and target branches