Skip to content
Snippets Groups Projects
Commit 6c8234e5 authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

TMSS-272: implemented a generic template get schema as json url and method

parent 4af57fdc
No related branches found
No related tags found
1 merge request!213Resolve TMSS-272
......@@ -8,6 +8,7 @@ from lofar.sas.tmss.tmss.tmssapp.adapters.parset import convert_to_parset
from drf_yasg.utils import swagger_auto_schema
from rest_framework.permissions import AllowAny
from rest_framework.decorators import authentication_classes, permission_classes
from django.apps import apps
def subtask_template_default_specification(request, subtask_template_pk:int):
......@@ -39,24 +40,11 @@ def task_specify_observation(request, pk=None):
@authentication_classes([AllowAny])
@swagger_auto_schema(responses={200: 'JSON schema',
404: 'the schema with requested <name> and <version> is not available'},
operation_description="Get the JSON schema with the given <name> and <version> as application/json content response.")
def get_common_json_schema(request, name:str, version:str):
template = get_object_or_404(models.CommonSchemaTemplate, name=name, version=version)
schema = template.schema
schema['$id'] = request.get_raw_uri()
operation_description="Get the JSON schema for the given <template> with the given <name> and <version> as application/json content response.")
def get_template_json_schema(request, template:str, name:str, version:str):
template_model = apps.get_model("tmssapp", template)
template_instance = get_object_or_404(template_model, name=name, version=version)
schema = template_instance.schema
return JsonResponse(schema, json_dumps_params={"indent":2})
@permission_classes([AllowAny])
@authentication_classes([AllowAny])
@swagger_auto_schema(responses={200: 'JSON schema',
404: 'the schema with requested <name> and <version> is not available'},
operation_description="Get the JSON schema with the given <name> and <version> as application/json content response.")
def get_subtask_template_json_schema(request, name:str, version:str):
template = get_object_or_404(models.SubtaskTemplate, name=name, version=version)
schema = template.schema
schema['$id'] = request.get_raw_uri()
return JsonResponse(schema, json_dumps_params={"indent":2})
......@@ -54,7 +54,8 @@ urlpatterns = [
path('docs/', include_docs_urls(title='TMSS API')),
re_path(r'^swagger(?P<format>\.json|\.yaml)$', swagger_schema_view.without_ui(cache_timeout=0), name='schema-json'),
path('swagger/', swagger_schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
path('redoc/', swagger_schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc')
path('redoc/', swagger_schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
path('schemas/<str:template>/<str:name>/<str:version>/', views.get_template_json_schema, name='template_json_schema')
]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment