Skip to content

Commit

Permalink
feat: switching to builtin OpenAPI generation from drf (#1734)
Browse files Browse the repository at this point in the history
  • Loading branch information
holtgrewe authored Jun 24, 2024
1 parent c64af28 commit 9561fb4
Show file tree
Hide file tree
Showing 43 changed files with 28,252 additions and 17,146 deletions.
37 changes: 26 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,19 @@ jobs:
make lint
working-directory: backend

- name: Check for OpenAPI schema changes.
run: |
pipenv run python manage.py spectacular \
| sed -e 's/^ version:.*/ version: VERSION/g' \
> /tmp/varfish_api_schema.yaml
diff \
varfish/tests/drf_spectacular/varfish_api_schema.yaml \
/tmp/varfish_api_schema.yaml
shell: bash -euo pipefail {0}
working-directory: backend
# # TODO: re-enable once we use sodar-core 1.0 and the error is fixed
# - name: Check for OpenAPI schema changes.
# run: |
# pipenv run python manage.py generateschema \
# | grep -v ^Loading \
# | grep -v '^The ' \
# > /tmp/varfish_api_schema.yaml
#
# diff \
# varfish/tests/drf_openapi_schema/varfish_api_schema.yaml \
# /tmp/varfish_api_schema.yaml
# shell: bash -euo pipefail {0}
# working-directory: backend

Node-Lint:
runs-on: ubuntu-latest
Expand All @@ -229,6 +231,19 @@ jobs:
make lint
working-directory: frontend

# # TODO: it appears that this is not stable
# - name: Check for OpenAPI schema changes.
# run: |
# npx openapi-typescript \
# ../backend/varfish/tests/drf_openapi_schema/varfish_api_schema.yaml \
# -o /tmp/varfish.d.ts
#
# diff \
# src/varfish/api/varfish.d.ts \
# /tmp/varfish.d.ts
# shell: bash -euo pipefail {0}
# working-directory: frontend


Node-Test:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,4 @@ celery:

.PHONY: gen-api-schema
gen-api-schema:
pipenv run $(MANAGE) spectacular > ./varfish/tests/drf_spectacular/varfish_api_schema.yaml
pipenv run $(MANAGE) generateschema | grep -v ^Loading | grep -v '^The ' > ./varfish/tests/drf_openapi_schema/varfish_api_schema.yaml
2 changes: 1 addition & 1 deletion backend/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ universal-pathlib = "*"
s3fs = "*"
toml = "*"
black = "*"
drf-spectacular = {extras = ["sidecar"], version = "*"}
rich = "*"

[dev-packages]
Expand Down Expand Up @@ -83,6 +82,7 @@ ipdb = "*"
jedi = "==0.19.1"
watchdog = "*"
werkzeug = "~=3.0.3"
uritemplate = "*"

[ldap-packages]
# Dependencies for enabling LDAP support. You will need the system library
Expand Down
844 changes: 435 additions & 409 deletions backend/Pipfile.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions backend/beaconsite/views_ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def strip_trailing_slashes(s: str) -> str:
class BeaconInfoAjaxView(LoginRequiredMixin, LoggedInPermissionMixin, View):
"""AJAX endpoint to remote site info endpoint via GA4GH Beacon API."""

schema = None
permission_required = "beaconsite.view_data"

def get(self, request, *args, **kwargs):
Expand All @@ -41,6 +42,7 @@ def get(self, request, *args, **kwargs):
class BeaconQueryAjaxView(LoginRequiredMixin, LoggedInPermissionMixin, View):
"""AJAX endpoint to remote site query endpoint via GA4GH Beacon API."""

schema = None
permission_required = "beaconsite.view_data"

def get(self, request, *args, **kwargs):
Expand Down
12 changes: 12 additions & 0 deletions backend/cases/views_ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class CaseListAjaxView(CaseListApiView):
**Returns:** See base API class.
"""

schema = None
authentication_classes = [SessionAuthentication]


Expand All @@ -43,6 +44,7 @@ class CaseRetrieveUpdateDestroyAjaxView(CaseRetrieveUpdateDestroyApiView):
**Returns:** See base API class.
"""

schema = None
authentication_classes = [SessionAuthentication]


Expand All @@ -54,6 +56,7 @@ class AnnotationReleaseInfoAjaxView(AnnotationReleaseInfoApiView):
**Methods:** ``GET``
"""

schema = None
authentication_classes = [SessionAuthentication]


Expand All @@ -65,6 +68,7 @@ class SvAnnotationReleaseInfoAjaxView(SvAnnotationReleaseInfoApiView):
**Methods:** ``GET``
"""

schema = None
authentication_classes = [SessionAuthentication]


Expand All @@ -78,6 +82,7 @@ class CasePhenotypeTermsListCreateAjaxView(CasePhenotypeTermsListCreateApiView):
**Returns:** See base API class.
"""

schema = None
authentication_classes = [SessionAuthentication]


Expand All @@ -93,6 +98,7 @@ class CasePhenotypeTermsRetrieveUpdateDestroyAjaxView(
**Returns:** See base API class.
"""

schema = None
authentication_classes = [SessionAuthentication]


Expand All @@ -106,6 +112,7 @@ class CaseCommentListCreateAjaxView(CaseCommentListCreateApiView):
**Returns:** See base API class.
"""

schema = None
authentication_classes = [SessionAuthentication]


Expand All @@ -119,6 +126,7 @@ class CaseCommentRetrieveUpdateDestroyAjaxView(CaseCommentRetrieveUpdateDestroyA
**Returns:** See base API class.
"""

schema = None
authentication_classes = [SessionAuthentication]


Expand All @@ -132,6 +140,7 @@ class CaseGeneAnnotationListAjaxView(CaseGeneAnnotationListApiView):
**Returns:** See base API class.
"""

schema = None
authentication_classes = [SessionAuthentication]


Expand Down Expand Up @@ -171,6 +180,7 @@ class CaseAlignmentStatsListAjaxView(CaseAlignmentStatsListApiView):
**Returns:** See base API class.
"""

schema = None
authentication_classes = [SessionAuthentication]


Expand All @@ -184,6 +194,7 @@ class SampleVariantStatisticsListAjaxView(SampleVariantStatisticsListApiView):
**Returns:** See base API class.
"""

schema = None
authentication_classes = [SessionAuthentication]


Expand All @@ -197,4 +208,5 @@ class PedigreeRelatednessListAjaxView(PedigreeRelatednessListApiView):
**Returns:** See base API class.
"""

schema = None
authentication_classes = [SessionAuthentication]
3 changes: 3 additions & 0 deletions backend/cases_import/views_api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
import typing

from django.db import transaction
Expand Down Expand Up @@ -29,6 +30,8 @@ class CaseImportActionListCreateApiView(SODARAPIGenericProjectMixin, ListCreateA

def get_serializer_context(self):
result = super().get_serializer_context()
if sys.argv[1:2] == ["generateschema"]:
return result
result["project"] = self.get_project(request=self.request)
return result

Expand Down
18 changes: 18 additions & 0 deletions backend/clinvar_export/views_ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class OrganisationReadView(
NB: these are defined by ClinVar anyway, so they have to be first created through the ClinVar web UI.
"""

schema = None
serializer_class = OrganisationSerializer
queryset = Organisation.objects.all()

Expand All @@ -147,6 +148,7 @@ class SubmitterReadView(
NB: these are defined by ClinVar anyway, so they have to be first created through the ClinVar web UI.
"""

schema = None
serializer_class = SubmitterSerializer

def get_queryset(self):
Expand All @@ -159,6 +161,7 @@ class AssertionMethodReadView(
):
"""List all assertion methods, must be entered via Admin GUI, no API access."""

schema = None
serializer_class = AssertionMethodSerializer
queryset = AssertionMethod.objects.all()

Expand All @@ -175,6 +178,7 @@ class IndividualReadView(
These will be created as necessary automatically from the Case information in the variants app.
"""

schema = None
serializer_class = IndividualSerializer

def get(self, request, *args, **kwargs):
Expand All @@ -195,6 +199,7 @@ class FamilyReadView(
These will be created as necessary automatically from the Case information of the variants app.
"""

schema = None
serializer_class = FamilySerializer

def get(self, request, *args, **kwargs):
Expand All @@ -212,6 +217,7 @@ class SubmissionSetListCreateView(
):
"""Base AJAX view for list/create of SubmissionSet objects."""

schema = None
serializer_class = SubmissionSetSerializer

def get_queryset(self):
Expand All @@ -227,6 +233,8 @@ class SubmissionSetRetrieveUpdateDestroyView(
"""Base AJAX view for retrieve/update/destroy of SubmissionSet objects."""

lookup_field = "sodar_uuid"

schema = None
lookup_url_kwarg = "submissionset"
serializer_class = SubmissionSetSerializer

Expand Down Expand Up @@ -309,6 +317,7 @@ class SubmissionListCreateView(
):
"""Base AJAX view for list/create of Submission objects."""

schema = None
serializer_class = SubmissionSerializer

def get_queryset(self):
Expand All @@ -324,6 +333,8 @@ class SubmissionRetrieveUpdateDestroyView(
"""Base AJAX view for retrieve/update/destroy of Submission objects."""

lookup_field = "sodar_uuid"

schema = None
lookup_url_kwarg = "submission"
serializer_class = SubmissionSerializer

Expand All @@ -336,6 +347,7 @@ class SubmissionIndividualListCreateView(
):
"""Base AJAX view for retrieve/update/destroy of Submission objects."""

schema = None
serializer_class = SubmissionIndividualSerializer

def get_queryset(self):
Expand All @@ -353,6 +365,8 @@ class SubmissionIndividualRetrieveUpdateDestroyView(
"""Base AJAX view for retrieve/update/destroy of Submission objects."""

lookup_field = "sodar_uuid"

schema = None
lookup_url_kwarg = "submissionindividual"
serializer_class = SubmissionIndividualSerializer

Expand All @@ -370,6 +384,7 @@ class SubmittingOrgListCreateView(
):
"""Base AJAX view for retrieve/update/destroy of Submission objects."""

schema = None
serializer_class = SubmittingOrgSerializer

def get_queryset(self):
Expand All @@ -385,6 +400,8 @@ class SubmittingOrgRetrieveUpdateDestroyView(
"""Base AJAX view for retrieve/update/destroy of Submission objects."""

lookup_field = "sodar_uuid"

schema = None
lookup_url_kwarg = "submittingorg"
serializer_class = SubmittingOrgSerializer

Expand Down Expand Up @@ -540,6 +557,7 @@ class ClinVarReportListView(

permission_classes = [ClinVarReportApiPermission]

schema = None
serializer_class = ClinVarReportSerializer

def get_permission_required(self):
Expand Down
6 changes: 6 additions & 0 deletions backend/cohorts/views_ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class CohortListCreateAjaxView(CohortListCreateApiView):
**Returns:** See base API class.
"""

schema = None
authentication_classes = [SessionAuthentication]


Expand All @@ -37,6 +38,7 @@ class CohortRetrieveUpdateDestroyAjaxView(CohortRetrieveUpdateDestroyApiView):
**Returns:** See base API class.
"""

schema = None
authentication_classes = [SessionAuthentication]


Expand All @@ -50,6 +52,7 @@ class CohortCaseCreateAjaxView(CohortCaseCreateApiView):
**Returns:** See base API class.
"""

schema = None
authentication_classes = [SessionAuthentication]


Expand All @@ -63,6 +66,7 @@ class CohortCaseListAjaxView(CohortCaseListApiView):
**Returns:** See base API class.
"""

schema = None
authentication_classes = [SessionAuthentication]


Expand All @@ -76,6 +80,7 @@ class CohortCaseDestroyAjaxView(CohortCaseDestroyApiView):
**Returns:** See base API class.
"""

schema = None
authentication_classes = [SessionAuthentication]


Expand All @@ -89,6 +94,7 @@ class AccessibleProjectsCasesAjaxView(AccessibleProjectsCasesApiView):
**Returns:** See base API class.
"""

schema = None
authentication_classes = [SessionAuthentication]


Expand Down
4 changes: 0 additions & 4 deletions backend/config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@
"rest_framework_httpsignature",
"django_saml2_auth",
"dj_iconify.apps.DjIconifyConfig",
# DRF spectacular with sidecar so it does not depend on internet access
"drf_spectacular",
"drf_spectacular_sidecar",
]

# Apps specific for this project go here.
Expand Down Expand Up @@ -662,7 +659,6 @@
"rest_framework.authentication.SessionAuthentication",
"knox.auth.TokenAuthentication",
),
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
}

SPECTACULAR_SETTINGS = {
Expand Down
Loading

0 comments on commit 9561fb4

Please sign in to comment.