From a6c38f7c7ebd67f0b2faca6c5c01d54fc2319f07 Mon Sep 17 00:00:00 2001 From: zamuzakki Date: Thu, 23 Jan 2025 10:23:25 +0700 Subject: [PATCH] remove invalid swagger schema --- .../geosight/data/api/v1/basemap.py | 6 +- .../data/api/v1/data_browser/data_browser.py | 4 +- .../geosight/data/api/v1/related_table.py | 4 +- .../data/api/v1/related_table_data.py | 4 +- .../geosight/data/serializer/basemap_layer.py | 60 +++++----- .../data/serializer/indicator_value.py | 111 ++++++++---------- .../geosight/data/serializer/related_table.py | 26 ++-- .../serializer/reference_dataset.py | 14 +-- 8 files changed, 104 insertions(+), 125 deletions(-) diff --git a/django_project/geosight/data/api/v1/basemap.py b/django_project/geosight/data/api/v1/basemap.py index 49c5fb1a2..2e2f33e80 100644 --- a/django_project/geosight/data/api/v1/basemap.py +++ b/django_project/geosight/data/api/v1/basemap.py @@ -66,7 +66,7 @@ def retrieve(self, request, id=None): tags=[ApiTag.BASEMAP], manual_parameters=[], request_body=BasemapLayerSerializer. - Meta.swagger_schema_fields['post_body'], + Meta.post_body, operation_description='Create a basemap.' ) def create(self, request, *args, **kwargs): @@ -78,7 +78,7 @@ def create(self, request, *args, **kwargs): tags=[ApiTag.BASEMAP], manual_parameters=[], request_body=BasemapLayerSerializer. - Meta.swagger_schema_fields['post_body'], + Meta.post_body, operation_description='Replace a detailed of basemap.' ) def update(self, request, *args, **kwargs): @@ -90,7 +90,7 @@ def update(self, request, *args, **kwargs): tags=[ApiTag.BASEMAP], manual_parameters=[], request_body=BasemapLayerSerializer. - Meta.swagger_schema_fields['post_body'], + Meta.post_body, operation_description=( 'Update just partial data based on payload ' 'a detailed of basemap.' diff --git a/django_project/geosight/data/api/v1/data_browser/data_browser.py b/django_project/geosight/data/api/v1/data_browser/data_browser.py index 7916aacce..1f8d6ef84 100644 --- a/django_project/geosight/data/api/v1/data_browser/data_browser.py +++ b/django_project/geosight/data/api/v1/data_browser/data_browser.py @@ -100,7 +100,7 @@ def get(self, request, *args, **kwargs): tags=[ApiTag.DATA_BROWSER], manual_parameters=[], request_body=IndicatorValueWithPermissionSerializer. - Meta.swagger_schema_fields['post_body'], + Meta.post_body, responses={ 201: '' } @@ -173,7 +173,7 @@ def put(self, request): tags=[ApiTag.DATA_BROWSER], manual_parameters=[], request_body=IndicatorValueWithPermissionSerializer. - Meta.swagger_schema_fields['delete_body'], + Meta.delete_body, ) def delete(self, request): """Batch delete data.""" diff --git a/django_project/geosight/data/api/v1/related_table.py b/django_project/geosight/data/api/v1/related_table.py index c7e76fdf5..bb8c01ea7 100644 --- a/django_project/geosight/data/api/v1/related_table.py +++ b/django_project/geosight/data/api/v1/related_table.py @@ -72,7 +72,7 @@ def retrieve(self, request, *args, **kwargs): tags=[ApiTag.RELATED_TABLE], manual_parameters=[], request_body=RelatedTableApiSerializer. - Meta.swagger_schema_fields['post_body'], + Meta.post_body, operation_description='Create a related table.' ) def create(self, request, *args, **kwargs): @@ -89,7 +89,7 @@ def create(self, request, *args, **kwargs): tags=[ApiTag.RELATED_TABLE], manual_parameters=[], request_body=RelatedTableApiSerializer. - Meta.swagger_schema_fields['post_body'], + Meta.post_body, operation_description='Update a related table.' ) def update(self, request, *args, **kwargs): diff --git a/django_project/geosight/data/api/v1/related_table_data.py b/django_project/geosight/data/api/v1/related_table_data.py index 755aa2585..bc7e5f658 100644 --- a/django_project/geosight/data/api/v1/related_table_data.py +++ b/django_project/geosight/data/api/v1/related_table_data.py @@ -108,7 +108,7 @@ def retrieve(self, request, *args, **kwargs): tags=[ApiTag.RELATED_TABLE_DATA], manual_parameters=[], request_body=RelatedTableRowApiSerializer. - Meta.swagger_schema_fields['post_body'], + Meta.post_body, operation_description='Create related table rows.' ) def create(self, request, *args, **kwargs): @@ -126,7 +126,7 @@ def create(self, request, *args, **kwargs): tags=[ApiTag.RELATED_TABLE_DATA], manual_parameters=[], request_body=RelatedTableRowApiSerializer. - Meta.swagger_schema_fields['post_body'], + Meta.post_body, operation_description='Update a related table row.' ) def update(self, request, *args, **kwargs): diff --git a/django_project/geosight/data/serializer/basemap_layer.py b/django_project/geosight/data/serializer/basemap_layer.py index aa13c6916..9397bfb3e 100644 --- a/django_project/geosight/data/serializer/basemap_layer.py +++ b/django_project/geosight/data/serializer/basemap_layer.py @@ -147,37 +147,37 @@ class Meta: # noqa: D106 "https://a.tile.openstreetmap.org/{z}/{x}/{y}.png" ), "type": "XYZ", - }, - 'post_body': openapi.Schema( - description='Data that is needed to create/edit basemap.', - type=openapi.TYPE_OBJECT, - properties={ - 'name': openapi.Schema( - title='Name', - type=openapi.TYPE_STRING - ), - 'description': openapi.Schema( - title='Description', - type=openapi.TYPE_STRING - ), - 'category': openapi.Schema( - title='Category', - type=openapi.TYPE_STRING - ), - 'url': openapi.Schema( - title='Url', - type=openapi.TYPE_STRING - ), - 'type': openapi.Schema( - title='Type', - type=openapi.TYPE_STRING, - description=( - f'The choices are {[TYPES]}' - ) - ), - } - ) + } } + post_body = openapi.Schema( + description='Data that is needed to create/edit basemap.', + type=openapi.TYPE_OBJECT, + properties={ + 'name': openapi.Schema( + title='Name', + type=openapi.TYPE_STRING + ), + 'description': openapi.Schema( + title='Description', + type=openapi.TYPE_STRING + ), + 'category': openapi.Schema( + title='Category', + type=openapi.TYPE_STRING + ), + 'url': openapi.Schema( + title='Url', + type=openapi.TYPE_STRING + ), + 'type': openapi.Schema( + title='Type', + type=openapi.TYPE_STRING, + description=( + f'The choices are {[TYPES]}' + ) + ), + } + ) class BasemapLayerParameterSerializer(serializers.ModelSerializer): diff --git a/django_project/geosight/data/serializer/indicator_value.py b/django_project/geosight/data/serializer/indicator_value.py index f57d48f97..67e307adb 100644 --- a/django_project/geosight/data/serializer/indicator_value.py +++ b/django_project/geosight/data/serializer/indicator_value.py @@ -209,74 +209,57 @@ class Meta: # noqa: D106 "admin_level": 0 } ] - }, - 'post_body': openapi.Schema( - description='Data that is needed for post new value.', - type=openapi.TYPE_OBJECT, - properties={ - 'indicator_id': openapi.Schema( - title='Indicator id', - type=openapi.TYPE_NUMBER - ), - 'indicator_shortcode': openapi.Schema( - title='Indicator shortcode', - type=openapi.TYPE_STRING - ), - 'value': openapi.Schema( - title='New value', - type=openapi.TYPE_STRING - ), - 'date': openapi.Schema( - title='Date', - description='Date is in YYYY-MM-DD in UTC.', - type=openapi.TYPE_STRING - ), - 'geom_id': openapi.Schema( - title='Geom id', - type=openapi.TYPE_STRING, - ), - 'dataset_uuid': openapi.Schema( - title='Dataset uuid', - type=openapi.TYPE_STRING - ), - 'admin_level': openapi.Schema( - title='Admin level', - type=openapi.TYPE_NUMBER - ), - 'attributes': openapi.Schema( - title='Attributes', - description=( - 'Optional to save attributes. It is in json' - ), - type=openapi.TYPE_OBJECT, + } + } + post_body = openapi.Schema( + description='Data that is needed for post new value.', + type=openapi.TYPE_OBJECT, + properties={ + 'indicator_id': openapi.Schema( + title='Indicator id', + type=openapi.TYPE_NUMBER + ), + 'indicator_shortcode': openapi.Schema( + title='Indicator shortcode', + type=openapi.TYPE_STRING + ), + 'value': openapi.Schema( + title='New value', + type=openapi.TYPE_STRING + ), + 'date': openapi.Schema( + title='Date', + description='Date is in YYYY-MM-DD in UTC.', + type=openapi.TYPE_STRING + ), + 'geom_id': openapi.Schema( + title='Geom id', + type=openapi.TYPE_STRING, + ), + 'dataset_uuid': openapi.Schema( + title='Dataset uuid', + type=openapi.TYPE_STRING + ), + 'admin_level': openapi.Schema( + title='Admin level', + type=openapi.TYPE_NUMBER + ), + 'attributes': openapi.Schema( + title='Attributes', + description=( + 'Optional to save attributes. It is in json' ), - } - ), - 'put_body': openapi.Schema( - description='List of id with new value.', - type=openapi.TYPE_ARRAY, - items=openapi.Items( type=openapi.TYPE_OBJECT, - properties={ - 'id': openapi.Schema( - title='Id of value', - type=openapi.TYPE_NUMBER - ), - 'value': openapi.Schema( - title='New value', - type=openapi.TYPE_STRING - ) - } - ) - ), - 'delete_body': openapi.Schema( - description='List of id of values.', - type=openapi.TYPE_ARRAY, - items=openapi.Items( - type=openapi.TYPE_NUMBER ) + } + ) + delete_body = openapi.Schema( + description='List of id of values.', + type=openapi.TYPE_ARRAY, + items=openapi.Items( + type=openapi.TYPE_NUMBER ) - } + ) class IndicatorValueWithPermissionSerializer(IndicatorValueSerializer): diff --git a/django_project/geosight/data/serializer/related_table.py b/django_project/geosight/data/serializer/related_table.py index 15366b6e4..02463ab2d 100644 --- a/django_project/geosight/data/serializer/related_table.py +++ b/django_project/geosight/data/serializer/related_table.py @@ -124,7 +124,6 @@ def get_permission(self, obj: RelatedTable): class Meta: # noqa: D106 model = RelatedTable exclude = ('unique_id',) - swagger_schema_fields = { 'type': openapi.TYPE_OBJECT, 'title': 'RelatedTable', @@ -151,13 +150,13 @@ class Meta: # noqa: D106 "creator": 'Admin', "created_at": "2023-01-01T00:00:00.00000Z", "modified_at": "2023-01-01T00:00:00.00000Z", - }, - 'post_body': openapi.Schema( - description='Data needed to create/edit related tables.', - type=openapi.TYPE_OBJECT, - properties=_related_table_swagger_properties - ) + } } + post_body = openapi.Schema( + description='Data needed to create/edit related tables.', + type=openapi.TYPE_OBJECT, + properties=_related_table_swagger_properties + ) class RelatedTableRowApiSerializer(DynamicModelSerializer): @@ -168,7 +167,6 @@ class RelatedTableRowApiSerializer(DynamicModelSerializer): class Meta: # noqa: D106 model = RelatedTableRow exclude = ('table', 'order', 'data') - swagger_schema_fields = { 'type': openapi.TYPE_OBJECT, 'title': 'RelatedTableRow', @@ -181,13 +179,13 @@ class Meta: # noqa: D106 "field_2": "2024-02-14T00:00:00Z", "field_3": 42.7 } - }, - 'post_body': openapi.Schema( - description='Data needed to create/edit related table rows.', - type=openapi.TYPE_OBJECT, - properties=_related_table_row_swagger_properties - ) + } } + post_body = openapi.Schema( + description='Data needed to create/edit related table rows.', + type=openapi.TYPE_OBJECT, + properties=_related_table_row_swagger_properties + ) class RelatedTableRowApiFlatSerializer(DynamicModelSerializer): diff --git a/django_project/geosight/reference_dataset/serializer/reference_dataset.py b/django_project/geosight/reference_dataset/serializer/reference_dataset.py index b44ec0359..2cc862202 100644 --- a/django_project/geosight/reference_dataset/serializer/reference_dataset.py +++ b/django_project/geosight/reference_dataset/serializer/reference_dataset.py @@ -130,15 +130,13 @@ class Meta: # noqa: D106 model = ReferenceDataset fields = '__all__' lookup_field = "identifier" - swagger_schema_fields = { - 'delete_body': openapi.Schema( - description='List of identifier of values.', - type=openapi.TYPE_ARRAY, - items=openapi.Items( - type=openapi.TYPE_STRING - ) + delete_body = openapi.Schema( + description='List of identifier of values.', + type=openapi.TYPE_ARRAY, + items=openapi.Items( + type=openapi.TYPE_STRING ) - } + ) class ReferenceDatasetCentroidUrlSerializer(serializers.ModelSerializer):