diff --git a/CHANGES/+fix-any-type.bugfix b/CHANGES/+fix-any-type.bugfix new file mode 100644 index 00000000..89ea25f5 --- /dev/null +++ b/CHANGES/+fix-any-type.bugfix @@ -0,0 +1,2 @@ +Fixed the JSONField specification so it doesn't break ruby bindings. +See context [here](https://github.com/pulp/pulp_rpm/issues/3639). diff --git a/pulp_python/app/fields.py b/pulp_python/app/fields.py new file mode 100644 index 00000000..110d2c55 --- /dev/null +++ b/pulp_python/app/fields.py @@ -0,0 +1,12 @@ +from drf_spectacular.utils import extend_schema_field +from drf_spectacular.types import OpenApiTypes +from rest_framework import serializers + + +@extend_schema_field(OpenApiTypes.OBJECT) +class JSONObjectField(serializers.JSONField): + """A drf JSONField override to force openapi schema to use 'object' type. + + Not strictly correct, but we relied on that for a long time. + See: https://github.com/tfranzel/drf-spectacular/issues/1095 + """ diff --git a/pulp_python/app/pypi/serializers.py b/pulp_python/app/pypi/serializers.py index dc99fc80..301d7a8b 100644 --- a/pulp_python/app/pypi/serializers.py +++ b/pulp_python/app/pypi/serializers.py @@ -3,6 +3,7 @@ from rest_framework import serializers from pulp_python.app.utils import DIST_EXTENSIONS +from pulp_python.app import fields from pulpcore.plugin.models import Artifact from pulpcore.plugin.util import get_domain from django.db.utils import IntegrityError @@ -28,9 +29,9 @@ class PackageMetadataSerializer(serializers.Serializer): """ last_serial = serializers.IntegerField(help_text=_("Cache value from last PyPI sync")) - info = serializers.JSONField(help_text=_("Core metadata of the package")) - releases = serializers.JSONField(help_text=_("List of all the releases of the package")) - urls = serializers.JSONField() + info = fields.JSONObjectField(help_text=_("Core metadata of the package")) + releases = fields.JSONObjectField(help_text=_("List of all the releases of the package")) + urls = fields.JSONObjectField() class PackageUploadSerializer(serializers.Serializer): diff --git a/pulp_python/app/serializers.py b/pulp_python/app/serializers.py index ff789b53..bb588b47 100644 --- a/pulp_python/app/serializers.py +++ b/pulp_python/app/serializers.py @@ -8,6 +8,7 @@ from pulpcore.plugin.util import get_domain from pulp_python.app import models as python_models +from pulp_python.app import fields from pulp_python.app.utils import get_project_metadata_from_artifact, parse_project_metadata @@ -157,7 +158,7 @@ class PythonPackageContentSerializer(core_serializers.SingleArtifactContentUploa required=False, allow_blank=True, help_text=_('A browsable URL for the project and a label for it, separated by a comma.') ) - project_urls = serializers.JSONField( + project_urls = fields.JSONObjectField( required=False, default=dict, help_text=_('A dictionary of labels and URLs for the project.') ) @@ -170,28 +171,28 @@ class PythonPackageContentSerializer(core_serializers.SingleArtifactContentUploa required=False, allow_blank=True, help_text=_('Field to specify the OS and CPU for which the binary package was compiled. ') ) - requires_dist = serializers.JSONField( + requires_dist = fields.JSONObjectField( required=False, default=list, help_text=_('A JSON list containing names of some other distutils project ' 'required by this distribution.') ) - provides_dist = serializers.JSONField( + provides_dist = fields.JSONObjectField( required=False, default=list, help_text=_('A JSON list containing names of a Distutils project which is contained' ' within this distribution.') ) - obsoletes_dist = serializers.JSONField( + obsoletes_dist = fields.JSONObjectField( required=False, default=list, help_text=_('A JSON list containing names of a distutils project\'s distribution which ' 'this distribution renders obsolete, meaning that the two projects should not ' 'be installed at the same time.') ) - requires_external = serializers.JSONField( + requires_external = fields.JSONObjectField( required=False, default=list, help_text=_('A JSON list containing some dependency in the system that the distribution ' 'is to be used.') ) - classifiers = serializers.JSONField( + classifiers = fields.JSONObjectField( required=False, default=list, help_text=_('A JSON list containing classification values for a Python package.') )