Skip to content

Commit

Permalink
supports OpenAPI 3 schema for API documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
smirolo committed Dec 27, 2023
1 parent 110bb2e commit 0da54e4
Show file tree
Hide file tree
Showing 22 changed files with 316 additions and 252 deletions.
8 changes: 4 additions & 4 deletions saas/api/accounts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2022, DjaoDjin inc.
# Copyright (c) 2023, DjaoDjin inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -30,7 +30,7 @@
from .serializers import (OrganizationSerializer, OrganizationCreateSerializer,
OrganizationDetailSerializer)
from .. import filters, settings
from ..docs import OpenAPIResponse, swagger_auto_schema
from ..docs import OpenApiResponse, extend_schema
from ..mixins import (OrganizationCreateMixin, OrganizationSmartListMixin,
OrganizationMixin, OrganizationDecorateMixin, UserSmartListMixin)
from ..pagination import TypeaheadPagination
Expand Down Expand Up @@ -264,8 +264,8 @@ def get_serializer_class(self):
return OrganizationCreateSerializer
return super(ProfilesTypeaheadAPIView, self).get_serializer_class()

@swagger_auto_schema(responses={
201: OpenAPIResponse("Create successful", OrganizationDetailSerializer)})
@extend_schema(responses={
201: OpenApiResponse(OrganizationDetailSerializer)})
def post(self, request, *args, **kwargs):
"""
Creates a shadow profile
Expand Down
14 changes: 7 additions & 7 deletions saas/api/agreements.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

from .serializers import (AgreementSerializer, AgreementCreateSerializer,
AgreementDetailSerializer, AgreementUpdateSerializer)
from ..docs import swagger_auto_schema, OpenAPIResponse
from ..docs import extend_schema, OpenApiResponse
from ..filters import OrderingFilter, SearchFilter
from ..models import Agreement
from ..utils import handle_uniq_error
Expand Down Expand Up @@ -129,8 +129,8 @@ def get_serializer_class(self):
return AgreementCreateSerializer
return super(AgreementListCreateAPIView, self).get_serializer_class()

@swagger_auto_schema(responses={
201: OpenAPIResponse("created", AgreementSerializer)})
@extend_schema(responses={
201: OpenApiResponse(AgreementSerializer)})
def post(self, request, *args, **kwargs): #pylint:disable=unused-argument
"""
Creates a legal agreement
Expand Down Expand Up @@ -251,8 +251,8 @@ def get_serializer_class(self):
return AgreementUpdateSerializer
return super(AgreementUpdateAPIView, self).get_serializer_class()

@swagger_auto_schema(responses={
200: OpenAPIResponse("", AgreementDetailSerializer)})
@extend_schema(responses={
200: OpenApiResponse(AgreementDetailSerializer)})
def put(self, request, *args, **kwargs): #pylint:disable=unused-argument
"""
Updates a legal agreement
Expand Down Expand Up @@ -293,8 +293,8 @@ def put(self, request, *args, **kwargs): #pylint:disable=unused-argument
"""
return self.update(request, *args, **kwargs)

@swagger_auto_schema(responses={
200: OpenAPIResponse("", AgreementDetailSerializer)})
@extend_schema(responses={
200: OpenApiResponse(AgreementDetailSerializer)})
def patch(self, request, *args, **kwargs):
return self.partial_update(request, *args, **kwargs)

Expand Down
16 changes: 7 additions & 9 deletions saas/api/backend.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2022, DjaoDjin inc.
# Copyright (c) 2023, DjaoDjin inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -32,11 +32,11 @@

from ..backends import ProcessorError
from ..compat import gettext_lazy as _
from ..docs import OpenAPIResponse, swagger_auto_schema, Parameter, IN_PATH
from ..docs import extend_schema, OpenApiResponse
from ..mixins import OrganizationMixin
from ..models import get_broker
from .serializers import (BankSerializer, CardSerializer,
CardTokenSerializer)
CardTokenSerializer, QueryParamUpdateSerializer)


class RetrieveBankAPIView(OrganizationMixin, RetrieveAPIView):
Expand Down Expand Up @@ -143,16 +143,14 @@ def delete(self, request, *args, **kwargs):
return super(PaymentMethodDetailAPIView, self).delete(
request, *args, **kwargs)

@swagger_auto_schema(
manual_parameters=[
Parameter('update', IN_PATH, type='bool')
])
@extend_schema(parameters=[QueryParamUpdateSerializer])
def get(self, request, *args, **kwargs):
return super(PaymentMethodDetailAPIView, self).get(
request, *args, **kwargs)

@swagger_auto_schema(responses={
200: OpenAPIResponse("Update successful", CardSerializer),

@extend_schema(responses={
200: OpenApiResponse(CardSerializer),
})
def put(self, request, *args, **kwargs):
"""
Expand Down
20 changes: 13 additions & 7 deletions saas/api/balances.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@
from django.db import transaction
from django.db.models import F, Q, Max
from rest_framework.generics import (get_object_or_404,
ListCreateAPIView, RetrieveUpdateDestroyAPIView)
GenericAPIView, ListCreateAPIView, RetrieveUpdateDestroyAPIView)
from rest_framework.response import Response
from rest_framework.views import APIView

from .. import settings
from ..docs import swagger_auto_schema, OpenAPIResponse
from ..docs import extend_schema, OpenApiResponse
from ..metrics.base import abs_balances_by_period, balances_by_period
from ..models import BalanceLine
from .serializers import (BalanceLineSerializer, QueryParamPeriodSerializer,
Expand All @@ -56,7 +55,7 @@ def get_values(self, balance_line, date_periods):
return values, unit


class BrokerBalancesAPIView(BrokerBalancesMixin, APIView):
class BrokerBalancesAPIView(BrokerBalancesMixin, GenericAPIView):
"""
Retrieves a balance sheet
Expand Down Expand Up @@ -98,7 +97,8 @@ class BrokerBalancesAPIView(BrokerBalancesMixin, APIView):
}
"""

@swagger_auto_schema(query_serializer=QueryParamPeriodSerializer)
@extend_schema(operation_id='metrics_balances_report',
parameters=[QueryParamPeriodSerializer])
def get(self, request, *args, **kwargs):
return super(BrokerBalancesAPIView, self).get(request, *args, **kwargs)

Expand Down Expand Up @@ -204,8 +204,8 @@ def post(self, request, *args, **kwargs):
return super(BalanceLineListAPIView, self).post(
request, *args, **kwargs)

@swagger_auto_schema(responses={
200: OpenAPIResponse("success", BalanceLineSerializer(many=True))})
@extend_schema(responses={
200: OpenApiResponse(BalanceLineSerializer(many=True))})
def patch(self, request, *args, **kwargs):
"""
Updates the order in which lines are displayed
Expand Down Expand Up @@ -297,6 +297,12 @@ class BalanceLineDetailAPIView(RetrieveUpdateDestroyAPIView):
def get_queryset(self):
return self.queryset.filter(report=self.kwargs.get('report'))

@extend_schema(operation_id='metrics_balances_lines_single_partial_update')
def patch(self, request, *args, **kwargs):
return super(BalanceLineDetailAPIView, self).patch(
request, *args, **kwargs)

@extend_schema(operation_id='metrics_balances_lines_single_update')
def put(self, request, *args, **kwargs):
"""
Updates a row in a balance sheet
Expand Down
Loading

0 comments on commit 0da54e4

Please sign in to comment.