diff --git a/src/api/views.py b/src/api/views.py index e4fad749..07e305eb 100644 --- a/src/api/views.py +++ b/src/api/views.py @@ -78,17 +78,12 @@ class CompareViewSet(ModelViewSet): parser_classes = (MultiPartParser, FormParser,) -@api_view(['GET', 'POST']) +@api_view(['POST']) @renderer_classes((JSONRenderer,)) def validate(request): """ Handle Validate api request """ - if request.method == 'GET': - """ Return all validate api request """ - query = ValidateFileUpload.objects.all() - serializer = ValidateSerializer(query, many=True) - return Response(serializer.data) - elif request.method == 'POST': + if request.method == 'POST': """ Return validate tool result on the post file""" serializer = ValidateSerializer(data=request.data) @@ -114,16 +109,12 @@ def validate(request): ) -@api_view(['GET', 'POST']) +@api_view(['POST']) @renderer_classes((JSONRenderer,)) def convert(request): """ Handle Convert api request """ - if request.method == 'GET': - """ Return all convert api request """ - query = ConvertFileUpload.objects.all() - serializer = ConvertSerializer(query, many=True) - return Response(serializer.data) - elif request.method == 'POST': + + if request.method == 'POST': """ Return convert tool result on the post file""" serializer = ConvertSerializer(data=request.data) if serializer.is_valid(): @@ -159,17 +150,12 @@ def convert(request): ) -@api_view(['GET', 'POST']) +@api_view(['POST']) @renderer_classes((JSONRenderer,)) def compare(request): """ Handle Compare api request """ - if request.method == 'GET': - """ Return all compare api request """ - query = CompareFileUpload.objects.all() - serializer = CompareSerializerReturn(query, many=True) - return Response(serializer.data) - elif request.method == 'POST': + if request.method == 'POST': """ Return compare tool result on the post file""" serializer = CompareSerializer(data=request.data) if serializer.is_valid(): @@ -209,17 +195,12 @@ def compare(request): serializer.errors,status=status.HTTP_400_BAD_REQUEST ) -@api_view(['GET', 'POST']) +@api_view(['POST']) @renderer_classes((JSONRenderer,)) def check_license(request): """ Handle Check License api request """ - if request.method == 'GET': - """ Return all check license api request """ - query = CheckLicenseFileUpload.objects.all() - serializer = CheckLicenseSerializer(query, many=True) - return Response(serializer.data) - elif request.method == 'POST': + if request.method == 'POST': """ Return check license tool result on the post file""" serializer = CheckLicenseSerializer(data=request.data) if serializer.is_valid(): @@ -249,18 +230,13 @@ def check_license(request): ) -@api_view(['GET', 'POST']) +@api_view(['POST']) @renderer_classes((JSONRenderer,)) @permission_classes((AllowAny, )) def submit_license(request): """ Handle submit license api request """ - if request.method == 'GET': - """ Return all check license api request """ - query = SubmitLicenseModel.objects.all() - serializer = SubmitLicenseSerializer(query, many=True) - return Response(serializer.data) - elif request.method == 'POST': + if request.method == 'POST': """ Return the result of license submittal on the post license details """ serializer = SubmitLicenseSerializer(data=request.data) if serializer.is_valid(): diff --git a/src/openapi-schema.yml b/src/openapi-schema.yml new file mode 100644 index 00000000..0aba2254 --- /dev/null +++ b/src/openapi-schema.yml @@ -0,0 +1,754 @@ +openapi: 3.0.2 +info: + title: '' + version: '' +paths: + /api2/validate/: + get: + operationId: listValidateFileUploads + description: Returns all validate api request + parameters: + - name: page + required: false + in: query + description: A page number within the paginated result set. + schema: + type: integer + responses: + '200': + content: + application/json: + schema: + type: object + properties: + count: + type: integer + example: 123 + next: + type: string + nullable: true + format: uri + example: http://api.example.org/accounts/?page=4 + previous: + type: string + nullable: true + format: uri + example: http://api.example.org/accounts/?page=2 + results: + type: array + items: + $ref: '#/components/schemas/ValidateReturn' + description: '' + tags: + - api2 + post: + operationId: createValidateFileUpload + description: Returns all validate api request + parameters: [] + requestBody: + content: + multipart/form-data: + schema: + $ref: '#/components/schemas/ValidateReturn' + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/ValidateReturn' + responses: + '201': + content: + application/json: + schema: + $ref: '#/components/schemas/ValidateReturn' + description: '' + tags: + - api2 + /api2/validate/{id}/: + get: + operationId: retrieveValidateFileUpload + description: Returns all validate api request + parameters: + - name: id + in: path + required: true + description: A unique integer value identifying this validate file upload. + schema: + type: string + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/ValidateReturn' + description: '' + tags: + - api2 + put: + operationId: updateValidateFileUpload + description: Returns all validate api request + parameters: + - name: id + in: path + required: true + description: A unique integer value identifying this validate file upload. + schema: + type: string + requestBody: + content: + multipart/form-data: + schema: + $ref: '#/components/schemas/ValidateReturn' + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/ValidateReturn' + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/ValidateReturn' + description: '' + tags: + - api2 + patch: + operationId: partialUpdateValidateFileUpload + description: Returns all validate api request + parameters: + - name: id + in: path + required: true + description: A unique integer value identifying this validate file upload. + schema: + type: string + requestBody: + content: + multipart/form-data: + schema: + $ref: '#/components/schemas/ValidateReturn' + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/ValidateReturn' + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/ValidateReturn' + description: '' + tags: + - api2 + delete: + operationId: destroyValidateFileUpload + description: Returns all validate api request + parameters: + - name: id + in: path + required: true + description: A unique integer value identifying this validate file upload. + schema: + type: string + responses: + '204': + description: '' + tags: + - api2 + /api2/convert/: + get: + operationId: listConvertFileUploads + description: Returns all convert api request + parameters: + - name: page + required: false + in: query + description: A page number within the paginated result set. + schema: + type: integer + responses: + '200': + content: + application/json: + schema: + type: object + properties: + count: + type: integer + example: 123 + next: + type: string + nullable: true + format: uri + example: http://api.example.org/accounts/?page=4 + previous: + type: string + nullable: true + format: uri + example: http://api.example.org/accounts/?page=2 + results: + type: array + items: + $ref: '#/components/schemas/ConvertReturn' + description: '' + tags: + - api2 + post: + operationId: createConvertFileUpload + description: Returns all convert api request + parameters: [] + requestBody: + content: + multipart/form-data: + schema: + $ref: '#/components/schemas/ConvertReturn' + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/ConvertReturn' + responses: + '201': + content: + application/json: + schema: + $ref: '#/components/schemas/ConvertReturn' + description: '' + tags: + - api2 + /api2/convert/{id}/: + get: + operationId: retrieveConvertFileUpload + description: Returns all convert api request + parameters: + - name: id + in: path + required: true + description: A unique integer value identifying this convert file upload. + schema: + type: string + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/ConvertReturn' + description: '' + tags: + - api2 + put: + operationId: updateConvertFileUpload + description: Returns all convert api request + parameters: + - name: id + in: path + required: true + description: A unique integer value identifying this convert file upload. + schema: + type: string + requestBody: + content: + multipart/form-data: + schema: + $ref: '#/components/schemas/ConvertReturn' + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/ConvertReturn' + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/ConvertReturn' + description: '' + tags: + - api2 + patch: + operationId: partialUpdateConvertFileUpload + description: Returns all convert api request + parameters: + - name: id + in: path + required: true + description: A unique integer value identifying this convert file upload. + schema: + type: string + requestBody: + content: + multipart/form-data: + schema: + $ref: '#/components/schemas/ConvertReturn' + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/ConvertReturn' + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/ConvertReturn' + description: '' + tags: + - api2 + delete: + operationId: destroyConvertFileUpload + description: Returns all convert api request + parameters: + - name: id + in: path + required: true + description: A unique integer value identifying this convert file upload. + schema: + type: string + responses: + '204': + description: '' + tags: + - api2 + /api2/compare/: + get: + operationId: listCompareFileUploads + description: Returns all compare api request + parameters: + - name: page + required: false + in: query + description: A page number within the paginated result set. + schema: + type: integer + responses: + '200': + content: + application/json: + schema: + type: object + properties: + count: + type: integer + example: 123 + next: + type: string + nullable: true + format: uri + example: http://api.example.org/accounts/?page=4 + previous: + type: string + nullable: true + format: uri + example: http://api.example.org/accounts/?page=2 + results: + type: array + items: + $ref: '#/components/schemas/CompareReturn' + description: '' + tags: + - api2 + post: + operationId: createCompareFileUpload + description: Returns all compare api request + parameters: [] + requestBody: + content: + multipart/form-data: + schema: + $ref: '#/components/schemas/CompareReturn' + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/CompareReturn' + responses: + '201': + content: + application/json: + schema: + $ref: '#/components/schemas/CompareReturn' + description: '' + tags: + - api2 + /api2/compare/{id}/: + get: + operationId: retrieveCompareFileUpload + description: Returns all compare api request + parameters: + - name: id + in: path + required: true + description: A unique integer value identifying this compare file upload. + schema: + type: string + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/CompareReturn' + description: '' + tags: + - api2 + put: + operationId: updateCompareFileUpload + description: Returns all compare api request + parameters: + - name: id + in: path + required: true + description: A unique integer value identifying this compare file upload. + schema: + type: string + requestBody: + content: + multipart/form-data: + schema: + $ref: '#/components/schemas/CompareReturn' + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/CompareReturn' + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/CompareReturn' + description: '' + tags: + - api2 + patch: + operationId: partialUpdateCompareFileUpload + description: Returns all compare api request + parameters: + - name: id + in: path + required: true + description: A unique integer value identifying this compare file upload. + schema: + type: string + requestBody: + content: + multipart/form-data: + schema: + $ref: '#/components/schemas/CompareReturn' + application/x-www-form-urlencoded: + schema: + $ref: '#/components/schemas/CompareReturn' + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/CompareReturn' + description: '' + tags: + - api2 + delete: + operationId: destroyCompareFileUpload + description: Returns all compare api request + parameters: + - name: id + in: path + required: true + description: A unique integer value identifying this compare file upload. + schema: + type: string + responses: + '204': + description: '' + tags: + - api2 + /api/validate/: + post: + operationId: createvalidate + description: Handle Validate api request + parameters: [] + requestBody: + content: + application/json: + schema: {} + application/x-www-form-urlencoded: + schema: {} + multipart/form-data: + schema: {} + responses: + '201': + content: + application/json: + schema: {} + description: '' + tags: + - api + /api/convert/: + post: + operationId: createconvert + description: Handle Convert api request + parameters: [] + requestBody: + content: + application/json: + schema: {} + application/x-www-form-urlencoded: + schema: {} + multipart/form-data: + schema: {} + responses: + '201': + content: + application/json: + schema: {} + description: '' + tags: + - api + /api/compare/: + post: + operationId: createcompare + description: Handle Compare api request + parameters: [] + requestBody: + content: + application/json: + schema: {} + application/x-www-form-urlencoded: + schema: {} + multipart/form-data: + schema: {} + responses: + '201': + content: + application/json: + schema: {} + description: '' + tags: + - api + /api/check_license/: + post: + operationId: createcheck_license + description: Handle Check License api request + parameters: [] + requestBody: + content: + application/json: + schema: {} + application/x-www-form-urlencoded: + schema: {} + multipart/form-data: + schema: {} + responses: + '201': + content: + application/json: + schema: {} + description: '' + tags: + - api + /api/submit_license/: + post: + operationId: createsubmit_license + description: Handle submit license api request + parameters: [] + requestBody: + content: + application/json: + schema: {} + application/x-www-form-urlencoded: + schema: {} + multipart/form-data: + schema: {} + responses: + '201': + content: + application/json: + schema: {} + description: '' + tags: + - api + /auth/token/: + post: + operationId: createToken + description: 'Implements an endpoint to provide access tokens + + + The endpoint is used in the following flows: + + + * Authorization code + + * Password + + * Client credentials' + parameters: [] + requestBody: + content: + application/json: + schema: {} + application/x-www-form-urlencoded: + schema: {} + multipart/form-data: + schema: {} + responses: + '201': + content: + application/json: + schema: {} + description: '' + tags: + - auth + /auth/convert-token/: + post: + operationId: createConvertToken + description: 'Implements an endpoint to convert a provider token to an access + token + + + The endpoint is used in the following flows: + + + * Authorization code + + * Client credentials' + parameters: [] + requestBody: + content: + application/json: + schema: {} + application/x-www-form-urlencoded: + schema: {} + multipart/form-data: + schema: {} + responses: + '201': + content: + application/json: + schema: {} + description: '' + tags: + - auth + /auth/revoke-token/: + post: + operationId: createRevokeToken + description: Implements an endpoint to revoke access or refresh tokens + parameters: [] + requestBody: + content: + application/json: + schema: {} + application/x-www-form-urlencoded: + schema: {} + multipart/form-data: + schema: {} + responses: + '201': + content: + application/json: + schema: {} + description: '' + tags: + - auth + /auth/invalidate-sessions/: + post: + operationId: createinvalidate_sessions + description: '' + parameters: [] + requestBody: + content: + application/json: + schema: {} + application/x-www-form-urlencoded: + schema: {} + multipart/form-data: + schema: {} + responses: + '201': + content: + application/json: + schema: {} + description: '' + tags: + - auth +components: + schemas: + ValidateReturn: + type: object + properties: + created: + type: string + format: date-time + readOnly: true + file: + type: string + format: binary + owner: + type: integer + result: + type: string + maxLength: 128 + status: + type: integer + required: + - file + - owner + - result + ConvertReturn: + type: object + properties: + created: + type: string + format: date-time + readOnly: true + file: + type: string + format: binary + owner: + type: integer + result: + type: string + maxLength: 32 + from_format: + type: string + maxLength: 16 + to_format: + type: string + maxLength: 16 + tagToRdfFormat: + type: string + nullable: true + maxLength: 16 + cfilename: + type: string + maxLength: 32 + message: + type: string + maxLength: 64 + status: + type: integer + required: + - file + - owner + - result + - from_format + - to_format + - cfilename + - message + CompareReturn: + type: object + properties: + created: + type: string + format: date-time + readOnly: true + file1: + type: string + format: binary + file2: + type: string + format: binary + owner: + type: integer + result: + type: string + maxLength: 32 + rfilename: + type: string + maxLength: 32 + message: + type: string + maxLength: 64 + status: + type: integer + required: + - file1 + - file2 + - owner + - result + - rfilename + - message diff --git a/src/src/settings.py b/src/src/settings.py index f598ab57..d927b4d6 100644 --- a/src/src/settings.py +++ b/src/src/settings.py @@ -74,6 +74,8 @@ 'social_django', 'oauth2_provider', 'rest_framework_social_oauth2', + 'corsheaders', + 'drf_yasg', ] MIDDLEWARE = [ diff --git a/src/src/urls.py b/src/src/urls.py index 0a78a622..a4a95f30 100644 --- a/src/src/urls.py +++ b/src/src/urls.py @@ -32,7 +32,9 @@ from django.contrib.staticfiles.urls import staticfiles_urlpatterns from django.conf import settings from django.conf.urls.static import static -from rest_framework import routers +from drf_yasg.views import get_schema_view +from drf_yasg import openapi +from rest_framework import routers, permissions from api import views @@ -43,6 +45,20 @@ router.register(r'convert', views.ConvertViewSet) router.register(r'compare', views.CompareViewSet) + +schema_view = get_schema_view( + openapi.Info( + title="Blog API", + default_version="v1", + description="A sample API for learning DRF", + terms_of_service="https://www.google.com/policies/terms/", + contact=openapi.Contact(email="hello@example.com"), + license=openapi.License(name="BSD License"), + ), + public=True, + permission_classes=(permissions.AllowAny,), +) + urlpatterns = [ re_path(r'^(/)?$', RedirectView.as_view(url=settings.HOME_URL),name="root"), path('admin/', admin.site.urls), @@ -52,6 +68,8 @@ path('api-auth/', include(("rest_framework.urls", 'api_auth'), namespace='rest_framework')), path('oauth/', include('social_django.urls', namespace='social')), path('auth/', include(("rest_framework_social_oauth2.urls", 'github_auth'), namespace='github_social')), + path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'), + path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'), ] urlpatterns += staticfiles_urlpatterns()