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

Adding Swagger Endpoint #451

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Django==3.2.18
jpype1==1.3.0
numpy==1.22.0
djangorestframework==3.12.2
drf-yasg==1.21.5
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we were not able to generate the required swagger specs using this last time in #104. Can you please have a look at what all is generated right now and is in the correct shape. Post a screenshot of the swagger specs generated as well.

Or I would suggest to dig into other libraries which can do the same.
Just an idea - If we have swagger specs generated in some yaml format, we can host it in github pages/wiki/io website.

Copy link
Contributor Author

@BanulaKumarage BanulaKumarage Mar 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, the swagger endpoint can be accessed with all the API endpoints in the api/swagger endpoint. I'm working on generating the yaml. So far it's working with the endpoint. Will generate the yaml and update the PR. If the issue raises, I will try another library.

@rtgdk needs clarification. Why does the API documentation need to be hosted on GitHub pages? With this implementation, we can access the documentation with the endpoint.

I have attached the screenshots of the api/swagger endpoint
image
image
image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BanulaKumarage Yeah hosting swagger specs directly where the site is hosted is fine.
I remember seeing this when we did the last implementation of drf-yasg, we saw some issues with the generation of documentation for fields in the api.
Can you check if every api has defined doc for every field? The actual documentation is currently hosted here - https://github.com/spdx/spdx-online-tools/wiki/REST-API-Fields-Request-and-Response - but is hard to find and also hard to track and update. Integrating directly into the website as a separate page looks perfect.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BanulaKumarage Also, looks like some extra apis are generated as well. We should limit ourselves to api related only

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BanulaKumarage Yeah hosting swagger specs directly where the site is hosted is fine. I remember seeing this when we did the last implementation of drf-yasg, we saw some issues with the generation of documentation for fields in the api. Can you check if every api has defined doc for every field? The actual documentation is currently hosted here - https://github.com/spdx/spdx-online-tools/wiki/REST-API-Fields-Request-and-Response - but is hard to find and also hard to track and update. Integrating directly into the website as a separate page looks perfect.

Hi @rtgdk I made this as an initial step I will check every field. And update you regarding this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BanulaKumarage Also, looks like some extra apis are generated as well. We should limit ourselves to api related only

@rtgdk is it the auth apis? which are the extra ones? There should be a way to avoid those. I will try to make it clean.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BanulaKumarage Yes, auth apis and api2 seems weird. Can you confirm if these are even needed for swagger specs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rtgdk parameters are available in api2 but not in API endpoints. I have tried multiple libraries but I got the same output. I am trying to figure out a way of resolving this.

bs4==0.0.1
requests==2.25
lxml==4.9.1
Expand Down
19 changes: 18 additions & 1 deletion src/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,30 @@
# limitations under the License.

from django.urls import path

from rest_framework import permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
from api import views

schema_view = get_schema_view(
openapi.Info(
title="API docs",
default_version='v1',
description="SPDX API API",
terms_of_service="https://www.google.com/policies/terms/",
contact=openapi.Contact(email="[email protected]"),
license=openapi.License(name="BSD License"),
),
public=True,
permission_classes=[permissions.AllowAny],
)


urlpatterns = [
path('validate/', views.validate, name='validate-api'),
path('convert/', views.convert, name='convert-api'),
path('compare/', views.compare, name='compare-api'),
path('check_license/', views.check_license, name='check_license-api'),
path('submit_license/', views.submit_license, name='submit_license-api'),
path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui')
]
1 change: 1 addition & 0 deletions src/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from django.http import JsonResponse
from rest_framework.parsers import FileUploadParser,FormParser, MultiPartParser
from rest_framework.response import Response
from rest_framework.generics import GenericAPIView
from rest_framework.viewsets import ModelViewSet
from api.models import ValidateFileUpload, ConvertFileUpload, CompareFileUpload, SubmitLicenseModel
from api.serializers import ValidateSerializer,ConvertSerializer,CompareSerializer,CheckLicenseSerializer,SubmitLicenseSerializer,ValidateSerializerReturn,ConvertSerializerReturn,CompareSerializerReturn,SubmitLicenseSerializerReturn
Expand Down
1 change: 1 addition & 0 deletions src/src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
'social_django',
'oauth2_provider',
'rest_framework_social_oauth2',
'drf_yasg',
]

MIDDLEWARE = [
Expand Down