{"id":17005948,"url":"https://github.com/friskes/drf-serializer-dumps","last_synced_at":"2025-04-12T06:32:32.004Z","repository":{"id":234960765,"uuid":"789852792","full_name":"Friskes/drf-serializer-dumps","owner":"Friskes","description":"Decorator for creating dict based on the drf serializer class for swagger","archived":false,"fork":false,"pushed_at":"2024-05-21T19:23:12.000Z","size":37,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-31T10:51:31.789Z","etag":null,"topics":["decorator","django","django-rest-framework","documentation-generator","drf-spectacular","schema","serializers","swagger"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Friskes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-21T18:19:32.000Z","updated_at":"2024-06-25T22:32:17.000Z","dependencies_parsed_at":"2024-04-21T21:27:41.021Z","dependency_job_id":"67a82d73-ec16-4d9e-b81b-b4839a72ca30","html_url":"https://github.com/Friskes/drf-serializer-dumps","commit_stats":null,"previous_names":["friskes/drf-serializer-dumps"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Friskes%2Fdrf-serializer-dumps","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Friskes%2Fdrf-serializer-dumps/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Friskes%2Fdrf-serializer-dumps/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Friskes%2Fdrf-serializer-dumps/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Friskes","download_url":"https://codeload.github.com/Friskes/drf-serializer-dumps/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223502361,"owners_count":17155938,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["decorator","django","django-rest-framework","documentation-generator","drf-spectacular","schema","serializers","swagger"],"created_at":"2024-10-14T05:04:36.331Z","updated_at":"2024-11-07T11:05:04.239Z","avatar_url":"https://github.com/Friskes.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Decorator for creating dict based on the drf serializer class for swagger\n\n\u003cdiv align=\"center\"\u003e\n\n| Project   |     | Status                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |\n|-----------|:----|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| CI/CD     |     | [![Latest Release](https://github.com/Friskes/drf-serializer-dumps/actions/workflows/publish-to-pypi.yml/badge.svg)](https://github.com/Friskes/drf-serializer-dumps/actions/workflows/publish-to-pypi.yml)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |\n| Quality   |     | [![Coverage](https://codecov.io/github/Friskes/drf-serializer-dumps/graph/badge.svg?token=vKez4Pycrc)](https://codecov.io/github/Friskes/drf-serializer-dumps)                                                                                                                                                                                                                                                                                                                               |\n| Package   |     | [![PyPI - Version](https://img.shields.io/pypi/v/drf-serializer-dumps?labelColor=202235\u0026color=edb641\u0026logo=python\u0026logoColor=edb641)](https://badge.fury.io/py/drf-serializer-dumps) ![PyPI - Support Python Versions](https://img.shields.io/pypi/pyversions/drf-serializer-dumps?labelColor=202235\u0026color=edb641\u0026logo=python\u0026logoColor=edb641) ![Project PyPI - Downloads](https://img.shields.io/pypi/dm/drf-serializer-dumps?logo=python\u0026label=downloads\u0026labelColor=202235\u0026color=edb641\u0026logoColor=edb641)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |\n| Meta      |     | [![types - Mypy](https://img.shields.io/badge/types-Mypy-202235.svg?logo=python\u0026labelColor=202235\u0026color=edb641\u0026logoColor=edb641)](https://github.com/python/mypy) [![License - MIT](https://img.shields.io/badge/license-MIT-202235.svg?logo=python\u0026labelColor=202235\u0026color=edb641\u0026logoColor=edb641)](https://spdx.org/licenses/) [![code style - Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/format.json\u0026labelColor=202235)](https://github.com/astral-sh/ruff) |\n\n\u003c/div\u003e\n\n\u003e Provides a decorator for converting the drf serializer class to a dictionary\n\n## Install\n1. Install package\n    ```bash\n    pip install drf-serializer-dumps\n    ```\n\n## About decorator\n`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.\n\n- Optional parameters:\n    - `exclude_fields` Exclude a number of serializer fields when generating a dictionary.\n    - `renew_type_value` Generate a new `uuid` and `datetime, date, time` when calling the function.\n    - `extend_type_map` Expand the type dictionary to default values, new types and their values, or redefine existing types and their values.\n\n## Usage example\n\n### Example 1\n```python\nfrom rest_framework import serializers\nfrom drf_serializer_dumps.decorators import serializer_dumps\n\n\nclass PersonCars(serializers.Serializer):\n    car_name = serializers.CharField()\n    car_price = serializers.IntegerField()\n\n\nclass PersonSerializer(serializers.Serializer):\n    name = serializers.CharField()\n    age = serializers.IntegerField()\n    cars = PersonCars(many=True)\n\n\nresult = serializer_dumps(PersonSerializer)\nprint(result)\n\u003e\u003e\u003e {'name': 'string', 'age': 1, 'cars': [{'car_name': 'string', 'car_price': 1}]}\n```\n\n### Example 2\n```python\nfrom rest_framework import serializers\nfrom django.contrib.postgres.fields import ArrayField\nfrom drf_serializer_dumps.decorators import serializer_dumps\n\n\nclass Person(models.Model):\n    name = models.CharField(max_length=256)\n    phones = ArrayField(models.CharField(max_length=256))\n\n\nclass PersonSerializer(serializers.ModelSerializer):\n    class Meta:\n        model = Person\n        fields = '__all__'\n\n\nresult = serializer_dumps(PersonSerializer)\nprint(result)\n\u003e\u003e\u003e {'id': 1, 'name': 'string', 'phones': ['string']}\n```\n\n### Example 3\n\u003e Integration with drf-spectacular extend_schema decorator\n```python\n@extend_schema(\n    examples=[\n        OpenApiExample('Name1', serializer_dumps(Some1Serializer)),\n        OpenApiExample('Name2', serializer_dumps(Some2Serializer)),\n    ]\n)\ndef your_api_method(self, request, *args, **kwargs):\n    ...\n```\n\n## Contributing\nWe would love you to contribute to `drf-serializer-dumps`, pull requests are very welcome! Please see [CONTRIBUTING.md](https://github.com/Friskes/drf-serializer-dumps/blob/main/CONTRIBUTING.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffriskes%2Fdrf-serializer-dumps","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffriskes%2Fdrf-serializer-dumps","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffriskes%2Fdrf-serializer-dumps/lists"}