From 41b280c730d34738c2163c772fd1293d16799f98 Mon Sep 17 00:00:00 2001 From: Huang Haibin Date: Mon, 15 Oct 2018 16:31:23 +0800 Subject: Upgrade swagger v1 for ocata Change-Id: I658c509c2897fcdb94042fe3ef98f04e6abf092a Issue-ID: MULTICLOUD-378 Signed-off-by: Huang Haibin --- ocata/ocata/swagger/urls.py | 2 ++ ocata/ocata/swagger/views.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/ocata/ocata/swagger/urls.py b/ocata/ocata/swagger/urls.py index 03dd79f7..9f12227f 100644 --- a/ocata/ocata/swagger/urls.py +++ b/ocata/ocata/swagger/urls.py @@ -16,9 +16,11 @@ from django.conf.urls import patterns, url from rest_framework.urlpatterns import format_suffix_patterns from ocata.swagger.views import SwaggerJsonView +from ocata.swagger.views import APIv1SwaggerJsonView urlpatterns = [ url(r'^api/multicloud-ocata/v0/swagger.json$', SwaggerJsonView.as_view()), + url(r'^api/multicloud-ocata/v1/swagger.json$', APIv1SwaggerJsonView.as_view()), ] urlpatterns = format_suffix_patterns(urlpatterns) diff --git a/ocata/ocata/swagger/views.py b/ocata/ocata/swagger/views.py index 42f596aa..27ea3653 100644 --- a/ocata/ocata/swagger/views.py +++ b/ocata/ocata/swagger/views.py @@ -45,4 +45,20 @@ class SwaggerJsonView(newton_json_view.SwaggerJsonView): else: return Response(data={'error':'internal error'}, status=500) +class APIv1SwaggerJsonView(newton_json_view.SwaggerJsonView): + def get(self, request): + ''' + reuse newton code and update the basePath + :param request: + :return: + ''' + + resp = super(APIv1SwaggerJsonView,self).get(request) + json_data = resp.data if resp else None + if json_data: + json_data["basePath"] = "/api/multicloud-ocata/v1/" + json_data["info"]["title"] = "Service NBI v1 of MultiCloud plugin for Ocata" + return Response(data=json_data, status=200) + else: + return Response(data={'error':'internal error'}, status=500) -- cgit 1.2.3-korg