Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT: add openapi documentation page if debug=true #90

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions mongoose_app/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from rest_framework import serializers
from .models import Product, User

class ProductSerializer(serializers.ModelSerializer):
class Meta:
model = Product
fields = '__all__'

class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = '__all__'
51 changes: 39 additions & 12 deletions mongoose_app/urls.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,44 @@
from django.urls import path

from django.conf import settings
from . import views
from rest_framework import permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi

# Define schema view for drf-yasg (only if DEBUG is True)
schema_view = None
if settings.DEBUG:
schema_view = get_schema_view(
openapi.Info(
title="Mongoose API",
default_version='v1',
description="API Documentation for the Mongoose POS",
contact=openapi.Contact(email="[email protected]"),
license=openapi.License(name="MIT License"),
),
public=True,
permission_classes=(permissions.AllowAny,),
)

urlpatterns = [
# GET endpoints
path("card", views.get_card, name="get_card"),
path("products", views.get_products, name="get_products"),
path("confirm", views.confirm_card, name="confirm_card"),
# POST endpoints
path("transaction", views.create_transaction, name="create_transaction"),
path("balance", views.update_balance, name="update_balance"),
path("register", views.register_card, name="register_card"),
path("catchwebhook", views.on_webhook, name="receive_update"),
path("topup", views.topup, name="topup"),
path("payment/webhook", views.payment_webhook, name="payment_webhook"),
# Your API endpoints here
path("card", views.GetCard.as_view(), name="get_card"),
path("products", views.GetProducts.as_view(), name="get_products"),
path("confirm", views.ConfirmCard.as_view(), name="confirm_card"),
path("transaction", views.CreateTransaction.as_view(), name="create_transaction"),
path("balance", views.UpdateBalance.as_view(), name="update_balance"),
path("register", views.RegisterCard.as_view(), name="register_card"),
path("catchwebhook", views.WebhookReceiver.as_view(), name="receive_update"),
path("topup", views.TopUp.as_view(), name="topup"),
path("payment/webhook", views.PaymentWebhook.as_view(), name="payment_webhook"),

# Only include Swagger and ReDoc paths if schema_view is defined (i.e., DEBUG=True)
*(
[
path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='swagger-ui'),
path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='redoc-ui')
]
if schema_view
else []
)
]
Loading