TT#121955 django-rest-swagger is deprecated

https: //www.django-rest-framework.org/topics/documenting-your-api/#drf-yasg-yet-another-swagger-generator

* We were getting error on /docs/
  > 'AutoSchema' object has no attribute 'get_link'

* provide /docs/ with swagger UI
  /redoc/ with ReDoc https://github.com/Redocly/redoc

Change-Id: I455e0c392285760d2450f7d3ec3d51209d20bf2a
pull/5/head
Victor Seva 3 years ago
parent 5ca6d5ddb9
commit beb1909fe7

@ -30,7 +30,7 @@ INSTALLED_APPS = [
"django.contrib.staticfiles", "django.contrib.staticfiles",
"rest_framework", "rest_framework",
"rest_framework_api_key", "rest_framework_api_key",
"rest_framework_swagger", "drf_spectacular",
"django_assets", "django_assets",
"django_celery_results", "django_celery_results",
"django_extensions", "django_extensions",
@ -112,15 +112,20 @@ REST_FRAMEWORK = {
"DEFAULT_FILTER_BACKENDS": ( "DEFAULT_FILTER_BACKENDS": (
"django_filters.rest_framework.DjangoFilterBackend", "django_filters.rest_framework.DjangoFilterBackend",
), ),
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
} }
SWAGGER_SETTINGS = { SPECTACULAR_SETTINGS = {
"api_version": "0.1", "TITLE": "RepoApi",
"info": { "DESCRIPTION": "repoapi, one ring to rule them all",
"contact": "dev@sipwise.com", "VERSION": "1.0.0",
"description": "repoapi, one ring to rule them all", "CONTACT": {
"license": "GPL 3.0", "email": "development@sipwise.com",
"title": "RepoApi", "url": "https://www.sipwise.com/",
},
"LICENSE": {
"name": "GPLv3",
"url": "https://www.gnu.org/licenses/gpl-3.0.en.html",
}, },
} }

@ -14,13 +14,17 @@
# with this program. If not, see <http://www.gnu.org/licenses/>. # with this program. If not, see <http://www.gnu.org/licenses/>.
from django.contrib import admin from django.contrib import admin
from django.urls import include from django.urls import include
from django.urls import path
from django.urls import re_path from django.urls import re_path
from drf_spectacular.views import SpectacularAPIView
from drf_spectacular.views import SpectacularRedocView
from drf_spectacular.views import SpectacularSwaggerView
from rest_framework.urlpatterns import format_suffix_patterns from rest_framework.urlpatterns import format_suffix_patterns
from . import views
from build import views as build_views from build import views as build_views
from release_dashboard.views import api as rd_api from release_dashboard.views import api as rd_api
from release_dashboard.views import docker from release_dashboard.views import docker
from repoapi import views
api_patterns = [ api_patterns = [
re_path(r"^$", views.api_root, name="index"), re_path(r"^$", views.api_root, name="index"),
@ -108,7 +112,15 @@ urlpatterns = [
r"^api-auth/", r"^api-auth/",
include("rest_framework.urls", namespace="rest_framework"), include("rest_framework.urls", namespace="rest_framework"),
), ),
re_path(r"^docs/", views.schema_view), path("api-schema/", SpectacularAPIView.as_view(), name="schema"),
path(
"docs/",
SpectacularSwaggerView.as_view(url_name="schema"),
name="swagger-ui",
),
path(
"redoc/", SpectacularRedocView.as_view(url_name="schema"), name="redoc"
),
re_path(r"^panel/", include("panel.urls")), re_path(r"^panel/", include("panel.urls")),
re_path( re_path(
r"^release_panel/", r"^release_panel/",

@ -1,4 +1,4 @@
# Copyright (C) 2020 The Sipwise Team - http://sipwise.com # Copyright (C) 2020-2022 The Sipwise Team - http://sipwise.com
# #
# This program is free software: you can redistribute it and/or modify it # This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free # under the terms of the GNU General Public License as published by the Free
@ -16,25 +16,14 @@ import django_filters
from rest_framework import generics from rest_framework import generics
from rest_framework import status from rest_framework import status
from rest_framework.decorators import api_view from rest_framework.decorators import api_view
from rest_framework.decorators import renderer_classes
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.reverse import reverse from rest_framework.reverse import reverse
from rest_framework.schemas import SchemaGenerator
from rest_framework.views import APIView from rest_framework.views import APIView
from rest_framework_swagger.renderers import OpenAPIRenderer
from rest_framework_swagger.renderers import SwaggerUIRenderer
from . import serializers from . import serializers
from .models import JenkinsBuildInfo as jbi from .models import JenkinsBuildInfo as jbi
@api_view()
@renderer_classes([OpenAPIRenderer, SwaggerUIRenderer])
def schema_view(request):
generator = SchemaGenerator()
return Response(generator.get_schema(request=request))
@api_view(("GET",)) @api_view(("GET",))
def api_root(request, _format=None): def api_root(request, _format=None):
return Response( return Response(

@ -8,15 +8,16 @@ django-extensions
django-filter django-filter
django-import-export django-import-export
django-jsonify django-jsonify
django-rest-swagger
django-structlog django-structlog
django-timezone-field django-timezone-field
djangorestframework>=3.6 djangorestframework>=3.6
drf-spectacular
drfapikey drfapikey
flower>=0.9.5 flower>=0.9.5
markdown markdown
natsort natsort
python-debian python-debian
PyYAML PyYAML
requests
six>=1.9 six>=1.9
webassets webassets

@ -5,7 +5,7 @@ FROM docker.mgm.sipwise.com/sipwise-bullseye:latest
# is updated with the current date. It will force refresh of all # is updated with the current date. It will force refresh of all
# of the base images and things like `apt-get update` won't be using # of the base images and things like `apt-get update` won't be using
# old cached versions when the Dockerfile is built. # old cached versions when the Dockerfile is built.
ENV REFRESHED_AT 2022-01-19 ENV REFRESHED_AT 2022-01-20
RUN apt-get update && apt-get install --assume-yes python3 python3-dev \ RUN apt-get update && apt-get install --assume-yes python3 python3-dev \
python3-pytest python3-pytest-pep8 \ python3-pytest python3-pytest-pep8 \

Loading…
Cancel
Save