Skip to content

Commit e1c217f

Browse files
committed
Update to drf-spectacular==0.26.5
Latest version without too much breaking changes Fix `AutoSchema` subclass Regenerate schemas Add regression test
1 parent 1177dfe commit e1c217f

File tree

9 files changed

+81
-28
lines changed

9 files changed

+81
-28
lines changed

requirements/base.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ djangorestframework-gis==1.0
150150
# via -r requirements/base.in
151151
drf-nested-routers==0.93.3
152152
# via commonground-api-common
153-
drf-spectacular==0.16.0
153+
drf-spectacular==0.26.5
154154
# via -r requirements/base.in
155155
drf-yasg==1.21.7
156156
# via commonground-api-common

requirements/ci.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ drf-nested-routers==0.93.3
218218
# via
219219
# -r requirements/base.txt
220220
# commonground-api-common
221-
drf-spectacular==0.16.0
221+
drf-spectacular==0.26.5
222222
# via -r requirements/base.txt
223223
drf-yasg==1.21.7
224224
# via

requirements/dev.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ drf-nested-routers==0.93.3
248248
# via
249249
# -r requirements/ci.txt
250250
# commonground-api-common
251-
drf-spectacular==0.16.0
251+
drf-spectacular==0.26.5
252252
# via -r requirements/ci.txt
253253
drf-yasg==1.21.7
254254
# via

src/objects/api/v1/filters.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from datetime import date as date_
2+
13
from django import forms
24
from django.utils.translation import gettext_lazy as _
35

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

109111
return queryset
110112

111-
def filter_date(self, queryset, name, value: date):
113+
def filter_date(self, queryset, name, value: date_):
112114
return queryset.filter_for_date(value)
113115

114-
def filter_registration_date(self, queryset, name, value: date):
116+
def filter_registration_date(self, queryset, name, value: date_):
115117
return queryset.filter_for_registration_date(value)

src/objects/api/v1/openapi.yaml

+19-9
Original file line numberDiff line numberDiff line change
@@ -639,8 +639,8 @@ components:
639639
typeVersion:
640640
type: integer
641641
maximum: 32767
642-
description: Version of the OBJECTTYPE for data in the object record
643642
minimum: 0
643+
description: Version of the OBJECTTYPE for data in the object record
644644
data:
645645
type: object
646646
additionalProperties: {}
@@ -661,20 +661,25 @@ components:
661661
type: string
662662
format: date
663663
readOnly: true
664+
nullable: true
664665
description: Legal end date of the object record
665666
registrationAt:
666667
type: string
667668
format: date
668669
readOnly: true
669670
description: The date when the record was registered in the system
670671
correctionFor:
671-
type: string
672-
readOnly: true
672+
type: integer
673+
maximum: 2147483647
674+
minimum: 0
673675
description: Index of the record corrected by the current record
674-
correctedBy:
675-
type: string
676676
readOnly: true
677+
correctedBy:
678+
type: integer
679+
maximum: 2147483647
680+
minimum: 0
677681
description: Index of the record, which corrects the current record
682+
readOnly: true
678683
required:
679684
- startAt
680685
- typeVersion
@@ -786,8 +791,8 @@ components:
786791
typeVersion:
787792
type: integer
788793
maximum: 32767
789-
description: Version of the OBJECTTYPE for data in the object record
790794
minimum: 0
795+
description: Version of the OBJECTTYPE for data in the object record
791796
data:
792797
type: object
793798
additionalProperties: {}
@@ -808,19 +813,24 @@ components:
808813
type: string
809814
format: date
810815
readOnly: true
816+
nullable: true
811817
description: Legal end date of the object record
812818
registrationAt:
813819
type: string
814820
format: date
815821
readOnly: true
816822
description: The date when the record was registered in the system
817823
correctionFor:
818-
type: string
824+
type: integer
825+
maximum: 2147483647
826+
minimum: 0
819827
description: Index of the record corrected by the current record
820828
correctedBy:
821-
type: string
822-
readOnly: true
829+
type: integer
830+
maximum: 2147483647
831+
minimum: 0
823832
description: Index of the record, which corrects the current record
833+
readOnly: true
824834
required:
825835
- startAt
826836
- typeVersion

src/objects/api/v2/openapi.yaml

+27-10
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,8 @@ components:
727727
typeVersion:
728728
type: integer
729729
maximum: 32767
730-
description: Version of the OBJECTTYPE for data in the object record
731730
minimum: 0
731+
description: Version of the OBJECTTYPE for data in the object record
732732
data:
733733
type: object
734734
additionalProperties: {}
@@ -749,20 +749,25 @@ components:
749749
type: string
750750
format: date
751751
readOnly: true
752+
nullable: true
752753
description: Legal end date of the object record
753754
registrationAt:
754755
type: string
755756
format: date
756757
readOnly: true
757758
description: The date when the record was registered in the system
758759
correctionFor:
759-
type: string
760-
readOnly: true
760+
type: integer
761+
maximum: 2147483647
762+
minimum: 0
761763
description: Index of the record corrected by the current record
762-
correctedBy:
763-
type: string
764764
readOnly: true
765+
correctedBy:
766+
type: integer
767+
maximum: 2147483647
768+
minimum: 0
765769
description: Index of the record, which corrects the current record
770+
readOnly: true
766771
required:
767772
- startAt
768773
- typeVersion
@@ -787,6 +792,9 @@ components:
787792
- read_only
788793
- read_and_write
789794
type: string
795+
description: |-
796+
* `read_only` - Read-only
797+
* `read_and_write` - Read and write
790798
MultiLineString:
791799
type: object
792800
description: GeoJSON multi-line-string geometry
@@ -879,8 +887,8 @@ components:
879887
typeVersion:
880888
type: integer
881889
maximum: 32767
882-
description: Version of the OBJECTTYPE for data in the object record
883890
minimum: 0
891+
description: Version of the OBJECTTYPE for data in the object record
884892
data:
885893
type: object
886894
additionalProperties: {}
@@ -901,19 +909,24 @@ components:
901909
type: string
902910
format: date
903911
readOnly: true
912+
nullable: true
904913
description: Legal end date of the object record
905914
registrationAt:
906915
type: string
907916
format: date
908917
readOnly: true
909918
description: The date when the record was registered in the system
910919
correctionFor:
911-
type: string
920+
type: integer
921+
maximum: 2147483647
922+
minimum: 0
912923
description: Index of the record corrected by the current record
913924
correctedBy:
914-
type: string
915-
readOnly: true
925+
type: integer
926+
maximum: 2147483647
927+
minimum: 0
916928
description: Index of the record, which corrects the current record
929+
readOnly: true
917930
required:
918931
- startAt
919932
- typeVersion
@@ -1022,7 +1035,11 @@ components:
10221035
mode:
10231036
allOf:
10241037
- $ref: '#/components/schemas/ModeEnum'
1025-
description: Permission mode
1038+
description: |-
1039+
Permission mode
1040+
1041+
* `read_only` - Read-only
1042+
* `read_and_write` - Read and write
10261043
use_fields:
10271044
type: boolean
10281045
description: Use field-based authorization

src/objects/tests/v1/test_schema.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from rest_framework import status
2+
from rest_framework.test import APITestCase
3+
4+
from .utils import reverse
5+
6+
7+
class APISchemaTest(APITestCase):
8+
def test_schema_endoint(self):
9+
response = self.client.get(reverse("schema-redoc"))
10+
self.assertEqual(response.status_code, status.HTTP_200_OK)

src/objects/tests/v2/test_schema.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from rest_framework import status
2+
from rest_framework.test import APITestCase
3+
4+
from .utils import reverse
5+
6+
7+
class APISchemaTest(APITestCase):
8+
def test_schema_endoint(self):
9+
response = self.client.get(reverse("schema-redoc"))
10+
self.assertEqual(response.status_code, status.HTTP_200_OK)

src/objects/utils/autoschema.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,13 @@ def _get_filter_parameters(self):
4040
return []
4141
return super()._get_filter_parameters()
4242

43-
def _get_response_for_code(self, serializer, status_code, media_types=None):
43+
def _get_response_for_code(
44+
self, serializer, status_code, media_types=None, direction="response"
45+
):
4446
"""add default description to the response"""
45-
response = super()._get_response_for_code(serializer, status_code, media_types)
47+
response = super()._get_response_for_code(
48+
serializer, status_code, media_types, direction
49+
)
4650

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

150154
return []
151155

152-
def _get_request_body(self):
156+
def _get_request_body(self, direction="request"):
153157
"""update search request body with filter parameters"""
154-
request_body = super()._get_request_body()
158+
request_body = super()._get_request_body(direction)
155159

156160
if self.view.action == "search":
157161
filter_params = self.get_filter_params_for_search()

0 commit comments

Comments
 (0)