diff --git a/SAS/TMSS/src/tmss/tmssapp/viewsets/lofar_viewset.py b/SAS/TMSS/src/tmss/tmssapp/viewsets/lofar_viewset.py index 3960f1e69da567d4637620d96a24ec45e706dfbf..9ef8fa97a048dea3fd09dc237c0baacb27899310 100644 --- a/SAS/TMSS/src/tmss/tmssapp/viewsets/lofar_viewset.py +++ b/SAS/TMSS/src/tmss/tmssapp/viewsets/lofar_viewset.py @@ -87,7 +87,7 @@ class AbstractTemplateViewSet(LOFARViewSet): path = revese_url('get_template_json_schema', kwargs={'template': self.queryset.model._meta.model_name, 'name': request.data['name'], 'version': request.data.get('version', 1)}).rstrip('/') - schema['$id'] = '%s://%s%s#' % (request.scheme, request.get_host(), path) + schema['$id'] = '%s://%s%s' % (request.scheme, request.get_host(), path) try: # we explicitely want to override the uploaded schema with the $id-annotated one. @@ -109,6 +109,17 @@ class AbstractTemplateViewSet(LOFARViewSet): self._inject_id_in_schema(request) return super().update(request, pk, **kwargs) + def retrieve(self, request, pk=None, **kwargs): + response = super().retrieve(request, pk, **kwargs) + + if 'application/json' in request.accepted_media_type: + # config Access-Control. Our schemas use $ref url's to other schemas, mainly pointing to our own common schemas with base definitions. + # We instruct the client to allow fetching those. + response["Access-Control-Allow-Origin"] = "*" + response["Access-Control-Allow-Methods"] = "GET, OPTIONS" + + return response + @swagger_auto_schema(responses={200: 'The schema as a JSON object', 403: 'forbidden'}, operation_description="Get the schema as a JSON object.")