-
Notifications
You must be signed in to change notification settings - Fork 57
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
BanulaKumarage
wants to merge
5
commits into
spdx:main
Choose a base branch
from
BanulaKumarage:Swagger-API-Documentation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a7b3b34
#202 Fixing Unit test failure - test_post_submit
BanulaKumarage 9b1f727
Merge branch 'spdx:main' into main
BanulaKumarage 7571947
Adding Swagger endpoint
BanulaKumarage dcce1ae
Merge branch 'Swagger-API-Documentation' of https://github.com/Banula…
BanulaKumarage 56fc152
Updating requirements.txt with dependencies
BanulaKumarage File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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') | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,7 @@ | |
'social_django', | ||
'oauth2_provider', | ||
'rest_framework_social_oauth2', | ||
'drf_yasg', | ||
] | ||
|
||
MIDDLEWARE = [ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
endpointThere was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @rtgdk I made this as an initial step I will check every field. And update you regarding this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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.