Skip to content

Commit

Permalink
Update to drf-spectacular==0.26.5
Browse files Browse the repository at this point in the history
Latest version without too much breaking changes
Fix `AutoSchema` subclass
Regenerate schemas
Add regression test
  • Loading branch information
Viicos committed Mar 14, 2024
1 parent 1177dfe commit e1c217f
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 28 deletions.
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ djangorestframework-gis==1.0
# via -r requirements/base.in
drf-nested-routers==0.93.3
# via commonground-api-common
drf-spectacular==0.16.0
drf-spectacular==0.26.5
# via -r requirements/base.in
drf-yasg==1.21.7
# via commonground-api-common
Expand Down
2 changes: 1 addition & 1 deletion requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ drf-nested-routers==0.93.3
# via
# -r requirements/base.txt
# commonground-api-common
drf-spectacular==0.16.0
drf-spectacular==0.26.5
# via -r requirements/base.txt
drf-yasg==1.21.7
# via
Expand Down
2 changes: 1 addition & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ drf-nested-routers==0.93.3
# via
# -r requirements/ci.txt
# commonground-api-common
drf-spectacular==0.16.0
drf-spectacular==0.26.5
# via -r requirements/ci.txt
drf-yasg==1.21.7
# via
Expand Down
6 changes: 4 additions & 2 deletions src/objects/api/v1/filters.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import date as date_

from django import forms
from django.utils.translation import gettext_lazy as _

Expand Down Expand Up @@ -108,8 +110,8 @@ def filter_data_attrs(self, queryset, name, value: str):

return queryset

def filter_date(self, queryset, name, value: date):
def filter_date(self, queryset, name, value: date_):
return queryset.filter_for_date(value)

def filter_registration_date(self, queryset, name, value: date):
def filter_registration_date(self, queryset, name, value: date_):
return queryset.filter_for_registration_date(value)
28 changes: 19 additions & 9 deletions src/objects/api/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,8 @@ components:
typeVersion:
type: integer
maximum: 32767
description: Version of the OBJECTTYPE for data in the object record
minimum: 0
description: Version of the OBJECTTYPE for data in the object record
data:
type: object
additionalProperties: {}
Expand All @@ -661,20 +661,25 @@ components:
type: string
format: date
readOnly: true
nullable: true
description: Legal end date of the object record
registrationAt:
type: string
format: date
readOnly: true
description: The date when the record was registered in the system
correctionFor:
type: string
readOnly: true
type: integer
maximum: 2147483647
minimum: 0
description: Index of the record corrected by the current record
correctedBy:
type: string
readOnly: true
correctedBy:
type: integer
maximum: 2147483647
minimum: 0
description: Index of the record, which corrects the current record
readOnly: true
required:
- startAt
- typeVersion
Expand Down Expand Up @@ -786,8 +791,8 @@ components:
typeVersion:
type: integer
maximum: 32767
description: Version of the OBJECTTYPE for data in the object record
minimum: 0
description: Version of the OBJECTTYPE for data in the object record
data:
type: object
additionalProperties: {}
Expand All @@ -808,19 +813,24 @@ components:
type: string
format: date
readOnly: true
nullable: true
description: Legal end date of the object record
registrationAt:
type: string
format: date
readOnly: true
description: The date when the record was registered in the system
correctionFor:
type: string
type: integer
maximum: 2147483647
minimum: 0
description: Index of the record corrected by the current record
correctedBy:
type: string
readOnly: true
type: integer
maximum: 2147483647
minimum: 0
description: Index of the record, which corrects the current record
readOnly: true
required:
- startAt
- typeVersion
Expand Down
37 changes: 27 additions & 10 deletions src/objects/api/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,8 @@ components:
typeVersion:
type: integer
maximum: 32767
description: Version of the OBJECTTYPE for data in the object record
minimum: 0
description: Version of the OBJECTTYPE for data in the object record
data:
type: object
additionalProperties: {}
Expand All @@ -749,20 +749,25 @@ components:
type: string
format: date
readOnly: true
nullable: true
description: Legal end date of the object record
registrationAt:
type: string
format: date
readOnly: true
description: The date when the record was registered in the system
correctionFor:
type: string
readOnly: true
type: integer
maximum: 2147483647
minimum: 0
description: Index of the record corrected by the current record
correctedBy:
type: string
readOnly: true
correctedBy:
type: integer
maximum: 2147483647
minimum: 0
description: Index of the record, which corrects the current record
readOnly: true
required:
- startAt
- typeVersion
Expand All @@ -787,6 +792,9 @@ components:
- read_only
- read_and_write
type: string
description: |-
* `read_only` - Read-only
* `read_and_write` - Read and write
MultiLineString:
type: object
description: GeoJSON multi-line-string geometry
Expand Down Expand Up @@ -879,8 +887,8 @@ components:
typeVersion:
type: integer
maximum: 32767
description: Version of the OBJECTTYPE for data in the object record
minimum: 0
description: Version of the OBJECTTYPE for data in the object record
data:
type: object
additionalProperties: {}
Expand All @@ -901,19 +909,24 @@ components:
type: string
format: date
readOnly: true
nullable: true
description: Legal end date of the object record
registrationAt:
type: string
format: date
readOnly: true
description: The date when the record was registered in the system
correctionFor:
type: string
type: integer
maximum: 2147483647
minimum: 0
description: Index of the record corrected by the current record
correctedBy:
type: string
readOnly: true
type: integer
maximum: 2147483647
minimum: 0
description: Index of the record, which corrects the current record
readOnly: true
required:
- startAt
- typeVersion
Expand Down Expand Up @@ -1022,7 +1035,11 @@ components:
mode:
allOf:
- $ref: '#/components/schemas/ModeEnum'
description: Permission mode
description: |-
Permission mode
* `read_only` - Read-only
* `read_and_write` - Read and write
use_fields:
type: boolean
description: Use field-based authorization
Expand Down
10 changes: 10 additions & 0 deletions src/objects/tests/v1/test_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from rest_framework import status
from rest_framework.test import APITestCase

from .utils import reverse


class APISchemaTest(APITestCase):
def test_schema_endoint(self):
response = self.client.get(reverse("schema-redoc"))
self.assertEqual(response.status_code, status.HTTP_200_OK)
10 changes: 10 additions & 0 deletions src/objects/tests/v2/test_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from rest_framework import status
from rest_framework.test import APITestCase

from .utils import reverse


class APISchemaTest(APITestCase):
def test_schema_endoint(self):
response = self.client.get(reverse("schema-redoc"))
self.assertEqual(response.status_code, status.HTTP_200_OK)
12 changes: 8 additions & 4 deletions src/objects/utils/autoschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ def _get_filter_parameters(self):
return []
return super()._get_filter_parameters()

def _get_response_for_code(self, serializer, status_code, media_types=None):
def _get_response_for_code(
self, serializer, status_code, media_types=None, direction="response"
):
"""add default description to the response"""
response = super()._get_response_for_code(serializer, status_code, media_types)
response = super()._get_response_for_code(
serializer, status_code, media_types, direction
)

if not response.get("description"):
response["description"] = HTTP_STATUS_CODE_TITLES.get(int(status_code))
Expand Down Expand Up @@ -149,9 +153,9 @@ def get_fields_params(self) -> list[OpenApiParameter]:

return []

def _get_request_body(self):
def _get_request_body(self, direction="request"):
"""update search request body with filter parameters"""
request_body = super()._get_request_body()
request_body = super()._get_request_body(direction)

if self.view.action == "search":
filter_params = self.get_filter_params_for_search()
Expand Down

0 comments on commit e1c217f

Please sign in to comment.