Decorator for creating dict based on the drf serializer class for swagger
Project description
Decorator for creating dict based on the drf serializer class for swagger
Provides a decorator for converting the drf serializer class to a dictionary
Install
- Install package
pip install drf-serializer-dumps
About decorator
serializer_dumps
decorator is based on the assignment of fields in the serializer to generate a dict, for SerializerMethodField
, the definition is made by OpenApiTypes
or the usual python type hints.
- Optional parameters:
exclude_fields
Exclude a number of serializer fields when generating a dictionary.renew_type_value
Generate a newuuid
anddatetime, date, time
when calling the function.extend_type_map
Expand the type dictionary to default values, new types and their values, or redefine existing types and their values.
Usage example
Example 1
from rest_framework import serializers
from drf_serializer_dumps.decorators import serializer_dumps
class PersonCars(serializers.Serializer):
car_name = serializers.CharField()
car_price = serializers.IntegerField()
class PersonSerializer(serializers.Serializer):
name = serializers.CharField()
age = serializers.IntegerField()
cars = PersonCars(many=True)
result = serializer_dumps(PersonSerializer)
print(result)
>>> {'name': 'string', 'age': 1, 'cars': [{'car_name': 'string', 'car_price': 1}]}
Example 2
from rest_framework import serializers
from django.contrib.postgres.fields import ArrayField
from drf_serializer_dumps.decorators import serializer_dumps
class Person(models.Model):
name = models.CharField(max_length=256)
phones = ArrayField(models.CharField(max_length=256))
class PersonSerializer(serializers.ModelSerializer):
class Meta:
model = Person
fields = '__all__'
result = serializer_dumps(PersonSerializer)
print(result)
>>> {'id': 1, 'name': 'string', 'phones': ['string']}
Example 3
Integration with drf-spectacular extend_schema decorator
@extend_schema(
examples=[
OpenApiExample('Name1', serializer_dumps(Some1Serializer)),
OpenApiExample('Name2', serializer_dumps(Some2Serializer)),
]
)
def your_api_method(self, request, *args, **kwargs):
...
Contributing
We would love you to contribute to drf-serializer-dumps
, pull requests are very welcome! Please see CONTRIBUTING.md for more information.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file drf_serializer_dumps-1.0.5.tar.gz
.
File metadata
- Download URL: drf_serializer_dumps-1.0.5.tar.gz
- Upload date:
- Size: 17.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4a7b2a4ff60469d375e5314edf7beeb447a53253334e6a2c67a42534d2a0574 |
|
MD5 | f60ba629c8b30bec23ec6e2092847a40 |
|
BLAKE2b-256 | bd2db5c09775ff307747c548b6bd0e5c4ab764a7856baf0f86c54678ddd6211d |
Provenance
The following attestation bundles were made for drf_serializer_dumps-1.0.5.tar.gz
:
Publisher:
publish-to-pypi.yml
on Friskes/drf-serializer-dumps
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
drf_serializer_dumps-1.0.5.tar.gz
- Subject digest:
d4a7b2a4ff60469d375e5314edf7beeb447a53253334e6a2c67a42534d2a0574
- Sigstore transparency entry: 148230200
- Sigstore integration time:
- Predicate type:
File details
Details for the file drf_serializer_dumps-1.0.5-py3-none-any.whl
.
File metadata
- Download URL: drf_serializer_dumps-1.0.5-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | df1105394571d791ae687d083490461be4877c28ee1bb08b8fae5d247c304687 |
|
MD5 | d6840eefb56f391a55fffd4f08d4497f |
|
BLAKE2b-256 | 5f4c905152f1244c9c9fa23fb06a7877a05d4c458bf0becb8e255e8828edcdb9 |
Provenance
The following attestation bundles were made for drf_serializer_dumps-1.0.5-py3-none-any.whl
:
Publisher:
publish-to-pypi.yml
on Friskes/drf-serializer-dumps
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
drf_serializer_dumps-1.0.5-py3-none-any.whl
- Subject digest:
df1105394571d791ae687d083490461be4877c28ee1bb08b8fae5d247c304687
- Sigstore transparency entry: 148230201
- Sigstore integration time:
- Predicate type: