Skip to content

Commit

Permalink
feat: initial set of seqvar stores based on code generated from OpenA…
Browse files Browse the repository at this point in the history
…PI (#1765) (#1769)
  • Loading branch information
holtgrewe authored Jul 3, 2024
1 parent f249d93 commit ae9c1f3
Show file tree
Hide file tree
Showing 47 changed files with 24,307 additions and 29,790 deletions.
5 changes: 4 additions & 1 deletion backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,7 @@ celery:

.PHONY: gen-api-schema
gen-api-schema:
pipenv run $(MANAGE) generateschema | grep -v ^Loading | grep -v '^The ' > ./varfish/tests/drf_openapi_schema/varfish_api_schema.yaml
pipenv run $(MANAGE) spectacular \
| grep -v ^Loading \
| grep -v '^The ' \
> ./varfish/tests/drf_openapi_schema/varfish_api_schema.yaml
1 change: 1 addition & 0 deletions backend/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ rich = "*"
drf-writable-nested = "*"
django-modelcluster = "*"
faker = "*"
drf-spectacular = {extras = ["sidecar"], version = "*"}

[dev-packages]
# packages for testing
Expand Down
209 changes: 121 additions & 88 deletions backend/Pipfile.lock

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions backend/cases_analysis/views_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import sys

from django.db import transaction
from django_pydantic_field.rest_framework import AutoSchema
from projectroles.views_api import SODARAPIProjectPermission
from rest_framework import viewsets
from rest_framework.generics import get_object_or_404
Expand Down Expand Up @@ -41,8 +40,6 @@ class CaseAnalysisViewSet(viewsets.ReadOnlyModelViewSet):
lookup_field = "sodar_uuid"
lookup_url_kwarg = "caseanalysis"

schema = AutoSchema() # OpenAPI schema generation for pydantic fields

pagination_class = StandardPagination

permission_classes = [CaseProjectPermission]
Expand All @@ -57,6 +54,8 @@ def get_queryset(self):
Currently, this will be at most one.
"""
result = CaseAnalysis.objects.all()
if sys.argv[:2] == ["manage.py", "spectacular"]:
return result # short circuit in schema generation
result = result.filter(case__sodar_uuid=self.kwargs["case"])
return result

Expand All @@ -79,8 +78,6 @@ class CaseAnalysisSessionViewSet(viewsets.ReadOnlyModelViewSet):
lookup_field = "sodar_uuid"
lookup_url_kwarg = "caseanalysissession"

schema = AutoSchema() # OpenAPI schema generation for pydantic fields

pagination_class = StandardPagination

permission_classes = [CaseProjectPermission]
Expand All @@ -96,6 +93,8 @@ def get_queryset(self):
Currently, this will be at most one.
"""
result = CaseAnalysisSession.objects.all()
if sys.argv[:2] == ["manage.py", "spectacular"]:
return result # short circuit in schema generation
result = result.filter(
caseanalysis__case__sodar_uuid=self.kwargs["case"],
user=self.request.user,
Expand Down
9 changes: 8 additions & 1 deletion backend/config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"rest_framework_httpsignature",
"django_saml2_auth",
"dj_iconify.apps.DjIconifyConfig",
"drf_spectacular",
]

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

SPECTACULAR_SETTINGS = {
Expand All @@ -674,14 +676,16 @@
"SERVE_INCLUDE_SCHEMA": False,
# Skip schema generation for some paths.
"PREPROCESSING_HOOKS": [
"varfish.utils.spectacular_preprocess_hook",
"varfish.spectacular_utils.spectacular_preprocess_hook",
],
# We add some explicit choices naming to work around warning.
"ENUM_NAME_OVERRIDES": {
"VariantRatingEnum": "variants.models.userannos.VARIANT_RATING_CHOICES",
"GenomeBuildVerbatimEnum": "importer.models.GENOME_BUILD_CHOICES_VERBATIM",
"GenomeBuildLowerEnum": "cases_files.models.GENOMEBUILD_CHOICES_LOWER",
"CaseStatusEnum": "variants.models.case.CASE_STATUS_CHOICES",
"SeqvarsQueryExecutionStateEnum": "seqvars.models.SeqvarsQueryExecution.STATE_CHOICES",
"SeqvarsQueryPresetsSetVersionStatusEnum": "seqvars.models.SeqvarsQueryPresetsSetVersion.STATUS_CHOICES",
},
# Sidecar Settings
"SWAGGER_UI_DIST": "SIDECAR",
Expand Down Expand Up @@ -748,6 +752,9 @@ def set_logging(level):
LOGGING_DEBUG = env.bool("LOGGING_DEBUG", False)
LOGGING = set_logging("DEBUG" if (DEBUG or LOGGING_DEBUG) else "INFO")

# Propagate exceptions to log.
DEBUG_PROPAGATE_EXCEPTIONS = DEV

# LDAP configuration
# ------------------------------------------------------------------------------

Expand Down
16 changes: 16 additions & 0 deletions backend/config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from django.views.generic import TemplateView
import django_saml2_auth.views
from djproxy.views import HttpProxy
from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView, SpectacularSwaggerView
from projectroles.views import HomeView as ProjectRolesHomeView
from sentry_sdk import last_event_id

Expand Down Expand Up @@ -96,6 +97,21 @@ def handler500(request, *args, **argv):
url(r"^seqvars/", include("seqvars.urls")),
]

# URL Patterns for DRF Spectacular
# ------------------------------------------------------------------------------

urlpatterns += [
# Schema
path("api/schema/", SpectacularAPIView.as_view(), name="schema"),
# UI
path(
"api/schema/swagger-ui/",
SpectacularSwaggerView.as_view(url_name="schema"),
name="swagger-ui",
),
path("api/schema/redoc/", SpectacularRedocView.as_view(url_name="schema"), name="redoc"),
]


# URL Patterns for Proxies
# ------------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions backend/genepanels/serializers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from drf_spectacular.utils import extend_schema_field
from rest_framework import serializers

from genepanels.models import GenePanel, GenePanelCategory
Expand Down Expand Up @@ -44,6 +45,7 @@ class Meta:
"genepanel_set",
)

@extend_schema_field(GenePanelSerializer)
def get_genepanel_set(self, obj):
"""Corresponds to the ``genepanel_set`` field defined above."""
return GenePanelSerializer(obj.genepanel_set.filter(state="active"), many=True).data
24 changes: 12 additions & 12 deletions backend/seqvars/admin.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from django.contrib import admin

from seqvars.models import (
Query,
QueryExecution,
QueryPresetsFrequency,
QueryPresetsSet,
ResultRow,
ResultSet,
SeqvarsQuery,
SeqvarsQueryExecution,
SeqvarsQueryPresetsFrequency,
SeqvarsQueryPresetsSet,
SeqvarsResultRow,
SeqvarsResultSet,
)

admin.site.register(QueryPresetsSet)
admin.site.register(QueryPresetsFrequency)
admin.site.register(Query)
admin.site.register(QueryExecution)
admin.site.register(ResultSet)
admin.site.register(ResultRow)
admin.site.register(SeqvarsQueryPresetsSet)
admin.site.register(SeqvarsQueryPresetsFrequency)
admin.site.register(SeqvarsQuery)
admin.site.register(SeqvarsQueryExecution)
admin.site.register(SeqvarsResultSet)
admin.site.register(SeqvarsResultRow)
Loading

0 comments on commit ae9c1f3

Please sign in to comment.