diff --git a/src/objects/api/v2/openapi.yaml b/src/objects/api/v2/openapi.yaml index a7f3efce..3fc1b553 100644 --- a/src/objects/api/v2/openapi.yaml +++ b/src/objects/api/v2/openapi.yaml @@ -858,6 +858,8 @@ components: minimum: 0 description: Version of the OBJECTTYPE for data in the object record data: + type: object + additionalProperties: true description: Object data, based on OBJECTTYPE geometry: allOf: @@ -1016,6 +1018,8 @@ components: minimum: 0 description: Version of the OBJECTTYPE for data in the object record data: + type: object + additionalProperties: true description: Object data, based on OBJECTTYPE geometry: allOf: @@ -1178,6 +1182,8 @@ components: type: boolean description: Use field-based authorization fields: + type: object + additionalProperties: true nullable: true title: Mode description: Fields allowed for this token in relation to objecttype versions. diff --git a/src/objects/utils/apps.py b/src/objects/utils/apps.py index 5245b233..535ca346 100644 --- a/src/objects/utils/apps.py +++ b/src/objects/utils/apps.py @@ -1,6 +1,10 @@ from django.apps import AppConfig +from django.db import models from drf_spectacular.extensions import OpenApiFilterExtension +from rest_framework.serializers import ModelSerializer + +from .fields import JSONObjectField def unregister_camelize_filter_extension(): @@ -23,3 +27,6 @@ def ready(self): from . import oas_extensions # noqa unregister_camelize_filter_extension() + + field_mapping = ModelSerializer.serializer_field_mapping + field_mapping[models.JSONField] = JSONObjectField diff --git a/src/objects/utils/fields.py b/src/objects/utils/fields.py new file mode 100644 index 00000000..c70f62bb --- /dev/null +++ b/src/objects/utils/fields.py @@ -0,0 +1,9 @@ +from drf_spectacular.utils import extend_schema_field +from rest_framework import serializers + + +@extend_schema_field({"type": "object", "additionalProperties": True}) +class JSONObjectField(serializers.JSONField): + """ + serializers.JSONField does not have a type by default and will show `any` in api spec. + """