Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid swagger schema #373

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions django_project/geosight/data/api/v1/basemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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.'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: ''
}
Expand Down Expand Up @@ -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."""
Expand Down
4 changes: 2 additions & 2 deletions django_project/geosight/data/api/v1/related_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions django_project/geosight/data/api/v1/related_table_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down
60 changes: 30 additions & 30 deletions django_project/geosight/data/serializer/basemap_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
111 changes: 47 additions & 64 deletions django_project/geosight/data/serializer/indicator_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
26 changes: 12 additions & 14 deletions django_project/geosight/data/serializer/related_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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):
Expand All @@ -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',
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading