Skip to content

Commit

Permalink
Change JSONFields to more specific Fields
Browse files Browse the repository at this point in the history
Closes: #3639
  • Loading branch information
pedro-psb committed Jul 1, 2024
1 parent bb025a6 commit cf285d7
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 44 deletions.
2 changes: 1 addition & 1 deletion pulp_rpm/app/serializers/advisory.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class UpdateCollectionSerializer(ModelSerializer):
help_text=_("Collection short name."), allow_blank=True, allow_null=True
)

module = serializers.JSONField(help_text=_("Collection modular NSVCA."), allow_null=True)
module = serializers.CharField(help_text=_("Collection modular NSVCA."), allow_null=True)

packages = UpdateCollectionPackagesField(
source="*", read_only=True, help_text=_("List of packages")
Expand Down
52 changes: 36 additions & 16 deletions pulp_rpm/app/serializers/comps.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,19 @@ class PackageGroupSerializer(NoArtifactContentSerializer):
)
name = serializers.CharField(help_text=_("PackageGroup name."), allow_blank=True)
description = serializers.CharField(help_text=_("PackageGroup description."), allow_blank=True)
packages = serializers.JSONField(help_text=_("PackageGroup package list."), allow_null=True)
packages = serializers.ListField(
help_text=_("PackageGroup package list."), child=serializers.CharField(), allow_null=True
)
biarch_only = serializers.BooleanField(help_text=_("PackageGroup biarch only."), required=False)
desc_by_lang = serializers.JSONField(
help_text=_("PackageGroup description by language."), allow_null=True
desc_by_lang = serializers.DictField(
help_text=_("PackageGroup description by language."),
child=serializers.CharField(),
allow_null=True,
)
name_by_lang = serializers.JSONField(
help_text=_("PackageGroup name by language."), allow_null=True
name_by_lang = serializers.DictField(
help_text=_("PackageGroup name by language."),
child=serializers.CharField(),
allow_null=True,
)
digest = serializers.CharField(
help_text=_("PackageGroup digest."),
Expand Down Expand Up @@ -73,11 +79,17 @@ class PackageCategorySerializer(NoArtifactContentSerializer):
display_order = serializers.IntegerField(
help_text=_("Category display order."), allow_null=True
)
group_ids = serializers.JSONField(help_text=_("Category group list."), allow_null=True)
desc_by_lang = serializers.JSONField(
help_text=_("Category description by language."), allow_null=True
group_ids = serializers.ListField(
help_text=_("Category group list."), child=serializers.CharField(), allow_null=True
)
desc_by_lang = serializers.DictField(
help_text=_("Category description by language."),
child=serializers.CharField(),
allow_null=True,
)
name_by_lang = serializers.DictField(
help_text=_("Category name by language."), child=serializers.CharField(), allow_null=True
)
name_by_lang = serializers.JSONField(help_text=_("Category name by language."), allow_null=True)
digest = serializers.CharField(
help_text=_("Category digest."),
)
Expand Down Expand Up @@ -109,13 +121,19 @@ class PackageEnvironmentSerializer(NoArtifactContentSerializer):
display_order = serializers.IntegerField(
help_text=_("Environment display order."), allow_null=True
)
group_ids = serializers.JSONField(help_text=_("Environment group list."), allow_null=True)
option_ids = serializers.JSONField(help_text=_("Environment option ids"), allow_null=True)
desc_by_lang = serializers.JSONField(
help_text=_("Environment description by language."), allow_null=True
group_ids = serializers.ListField(
help_text=_("Environment group list."), child=serializers.CharField(), allow_null=True
)
name_by_lang = serializers.JSONField(
help_text=_("Environment name by language."), allow_null=True
option_ids = serializers.ListField(
help_text=_("Environment option ids"), child=serializers.CharField(), allow_null=True
)
desc_by_lang = serializers.DictField(
help_text=_("Environment description by language."),
child=serializers.CharField(),
allow_null=True,
)
name_by_lang = serializers.DictField(
help_text=_("Environment name by language."), child=serializers.CharField(), allow_null=True
)
digest = serializers.CharField(help_text=_("Environment digest."))

Expand All @@ -139,7 +157,9 @@ class PackageLangpacksSerializer(NoArtifactContentSerializer):
PackageLangpacks serializer.
"""

matches = serializers.JSONField(help_text=_("Langpacks matches."), allow_null=True)
matches = serializers.ListField(
help_text=_("Langpacks matches."), child=serializers.CharField(), allow_null=True
)
digest = serializers.CharField(help_text=_("Langpacks digest."), allow_null=True)

class Meta:
Expand Down
16 changes: 12 additions & 4 deletions pulp_rpm/app/serializers/modulemd.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ class ModulemdSerializer(NoArtifactContentSerializer):
arch = serializers.CharField(
help_text=_("Modulemd architecture."),
)
artifacts = serializers.JSONField(help_text=_("Modulemd artifacts."), allow_null=True)
dependencies = serializers.JSONField(help_text=_("Modulemd dependencies."), allow_null=True)
artifacts = serializers.ListField(
help_text=_("Modulemd artifacts."), child=serializers.CharField(), allow_null=True
)
dependencies = serializers.ListField(
help_text=_("Modulemd dependencies."), child=serializers.CharField(), allow_null=True
)
# TODO: The performance of this is not great, there's a noticable difference in response
# time before/after. Since this will only return Package content hrefs, we might benefit
# from creating a specialized version of this Field that can skip some of the work.
Expand All @@ -45,7 +49,9 @@ class ModulemdSerializer(NoArtifactContentSerializer):
view_name="content-rpm/packages-detail",
many=True,
)
profiles = serializers.JSONField(help_text=_("Modulemd profiles."), allow_null=True)
profiles = serializers.ListField(
help_text=_("Modulemd profiles."), child=serializers.CharField(), allow_null=True
)
snippet = serializers.CharField(help_text=_("Modulemd snippet"), write_only=True)

def create(self, validated_data):
Expand Down Expand Up @@ -87,7 +93,9 @@ class ModulemdDefaultsSerializer(NoArtifactContentSerializer):

module = serializers.CharField(help_text=_("Modulemd name."))
stream = serializers.CharField(help_text=_("Modulemd default stream."))
profiles = serializers.JSONField(help_text=_("Default profiles for modulemd streams."))
profiles = serializers.ListField(
help_text=_("Default profiles for modulemd streams."), child=serializers.CharField()
)
snippet = serializers.CharField(help_text=_("Modulemd default snippet"), write_only=True)

def create(self, validated_data):
Expand Down
40 changes: 20 additions & 20 deletions pulp_rpm/app/serializers/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,64 +77,64 @@ class PackageSerializer(SingleArtifactContentUploadSerializer, ContentChecksumSe
read_only=True,
)

changelogs = serializers.JSONField(
changelogs = serializers.ListField(
help_text=_("Changelogs that package contains"),
default="[]",
child=serializers.CharField(),
required=False,
read_only=True,
)
files = serializers.JSONField(
files = serializers.ListField(
help_text=_("Files that package contains"),
default="[]",
child=serializers.CharField(),
required=False,
read_only=True,
)

requires = serializers.JSONField(
requires = serializers.ListField(
help_text=_("Capabilities the package requires"),
default="[]",
child=serializers.CharField(),
required=False,
read_only=True,
)
provides = serializers.JSONField(
provides = serializers.ListField(
help_text=_("Capabilities the package provides"),
default="[]",
child=serializers.CharField(),
required=False,
read_only=True,
)
conflicts = serializers.JSONField(
conflicts = serializers.ListField(
help_text=_("Capabilities the package conflicts"),
default="[]",
child=serializers.CharField(),
required=False,
read_only=True,
)
obsoletes = serializers.JSONField(
obsoletes = serializers.ListField(
help_text=_("Capabilities the package obsoletes"),
default="[]",
child=serializers.CharField(),
required=False,
read_only=True,
)
suggests = serializers.JSONField(
suggests = serializers.ListField(
help_text=_("Capabilities the package suggests"),
default="[]",
child=serializers.CharField(),
required=False,
read_only=True,
)
enhances = serializers.JSONField(
enhances = serializers.ListField(
help_text=_("Capabilities the package enhances"),
default="[]",
child=serializers.CharField(),
required=False,
read_only=True,
)
recommends = serializers.JSONField(
recommends = serializers.ListField(
help_text=_("Capabilities the package recommends"),
default="[]",
child=serializers.CharField(),
required=False,
read_only=True,
)
supplements = serializers.JSONField(
supplements = serializers.ListField(
help_text=_("Capabilities the package supplements"),
default="[]",
child=serializers.CharField(),
required=False,
read_only=True,
)
Expand Down
9 changes: 6 additions & 3 deletions pulp_rpm/app/serializers/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ class RpmRepositorySerializer(RepositorySerializer):
),
read_only=True,
)
repo_config = serializers.JSONField(
repo_config = serializers.DictField(
required=False,
help_text=_("A JSON document describing config.repo file"),
child=serializers.CharField(),
)

def validate(self, data):
Expand Down Expand Up @@ -402,9 +403,10 @@ class RpmPublicationSerializer(PublicationSerializer):
),
read_only=True,
)
repo_config = serializers.JSONField(
repo_config = serializers.DictField(
required=False,
help_text=_("A JSON document describing config.repo file"),
child=serializers.CharField(),
)

def validate(self, data):
Expand Down Expand Up @@ -541,8 +543,9 @@ class CopySerializer(ValidateFieldsMixin, serializers.Serializer):
A serializer for Content Copy API.
"""

config = serializers.JSONField(
config = serializers.DictField(
help_text=_("A JSON document describing sources, destinations, and content to be copied"),
child=serializers.CharField(),
)

dependency_solving = serializers.BooleanField(
Expand Down

0 comments on commit cf285d7

Please sign in to comment.