{"id":15091371,"url":"https://github.com/friskes/drf-spectacular-websocket","last_synced_at":"2025-06-10T18:08:37.964Z","repository":{"id":234962470,"uuid":"789855166","full_name":"Friskes/drf-spectacular-websocket","owner":"Friskes","description":"Extend websocket schema decorator for Django Channels","archived":false,"fork":false,"pushed_at":"2024-11-30T11:52:04.000Z","size":228,"stargazers_count":12,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-12T17:14:57.997Z","etag":null,"topics":["channels","decorator","django","django-rest-framework","documentation-generator","drf-spectacular","openapi-generator","openapi-specification","openapi3","schema","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,"zenodo":null}},"created_at":"2024-04-21T18:27:01.000Z","updated_at":"2025-05-05T17:36:37.000Z","dependencies_parsed_at":"2024-04-25T10:48:47.425Z","dependency_job_id":"17441a99-52e4-4186-b1fa-00730a462927","html_url":"https://github.com/Friskes/drf-spectacular-websocket","commit_stats":{"total_commits":60,"total_committers":3,"mean_commits":20.0,"dds":"0.050000000000000044","last_synced_commit":"8aec9d8f03b7c9721776d69a906fc961f9a89136"},"previous_names":["friskes/drf-spectacular-websocket"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Friskes%2Fdrf-spectacular-websocket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Friskes%2Fdrf-spectacular-websocket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Friskes%2Fdrf-spectacular-websocket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Friskes%2Fdrf-spectacular-websocket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Friskes","download_url":"https://codeload.github.com/Friskes/drf-spectacular-websocket/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Friskes%2Fdrf-spectacular-websocket/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259123865,"owners_count":22808876,"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":["channels","decorator","django","django-rest-framework","documentation-generator","drf-spectacular","openapi-generator","openapi-specification","openapi3","schema","swagger"],"created_at":"2024-09-25T10:40:40.033Z","updated_at":"2025-06-10T18:08:37.938Z","avatar_url":"https://github.com/Friskes.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Extend websocket schema decorator for Django Channels\n\n\u003cdiv align=\"center\"\u003e\n\n| Project   |     | Status                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |\n|-----------|:----|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| CI/CD     |     | [![Latest Release](https://github.com/Friskes/drf-spectacular-websocket/actions/workflows/publish-to-pypi.yml/badge.svg)](https://github.com/Friskes/drf-spectacular-websocket/actions/workflows/publish-to-pypi.yml)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |\n| Quality   |     | [![Coverage](https://codecov.io/github/Friskes/drf-spectacular-websocket/graph/badge.svg?token=vKez4Pycrc)](https://codecov.io/github/Friskes/drf-spectacular-websocket)                                                                                                                                                                                                                                                                                                                               |\n| Package   |     | [![PyPI - Version](https://img.shields.io/pypi/v/drf-spectacular-websocket?labelColor=202235\u0026color=edb641\u0026logo=python\u0026logoColor=edb641)](https://badge.fury.io/py/drf-spectacular-websocket) ![PyPI - Support Python Versions](https://img.shields.io/pypi/pyversions/drf-spectacular-websocket?labelColor=202235\u0026color=edb641\u0026logo=python\u0026logoColor=edb641) ![Project PyPI - Downloads](https://img.shields.io/pypi/dm/drf-spectacular-websocket?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 [extend_ws_schema](#About-decorator) decorator to documentation [Cunsumer](https://channels.readthedocs.io/en/latest/topics/consumers.html) methods from [channels](https://github.com/django/channels) just like it does [drf-spectacular](https://github.com/tfranzel/drf-spectacular)\n\n\n## Install\n1. Install package\n    ```bash\n    pip install drf-spectacular-websocket\n    ```\n\n2. Create sidecar static\n    ```bash\n    python manage.py collectstatic\n    ```\n\n3. Add app name to `INSTALLED_APPS`\n    \u003e `drf_spectacular_websocket` must be higher than `drf_spectacular`\n    ```python\n    INSTALLED_APPS = [\n        'drf_spectacular_websocket',\n        'drf_spectacular',\n        'drf_spectacular_sidecar',\n    ]\n    ```\n\n\n## Configure settings\n```python\nASGI_APPLICATION = 'path.to.your.application'\n\n# (Optional) this is default settings are automatically set by the drf_spectacular_websocket.\n# You can override them in your application if necessary.\nSPECTACULAR_SETTINGS = {\n    'DEFAULT_GENERATOR_CLASS': 'drf_spectacular_websocket.schemas.WsSchemaGenerator',\n    'SWAGGER_UI_DIST': 'SIDECAR',\n    'SWAGGER_UI_FAVICON_HREF': 'SIDECAR',\n    'REDOC_DIST': 'SIDECAR',\n    'SWAGGER_UI_SETTINGS': {\n        'connectSocket': True,  # Automatically establish a WS connection when opening swagger\n        'socketMaxMessages': 8,  # Max number of messages displayed in the log window in swagger\n        'socketMessagesInitialOpened': False,  # Automatically open the log window when opening swagger\n    },\n}\n```\n\n\u003e drf_spectacular_websocket automatically finds websocket urls and related consumer using `ASGI_APPLICATION` setting.\n\n## About decorator\n`extend_ws_schema` decorator accepts one new `type` parameter relative to drf_spectacular `extend_schema`.\n- possible values:\n    - `send` - Type of interaction, [request -\u003e response]\n    - `receive` - Type of interaction, [response without request]\n\n## Usage example\n\n```python\nfrom channels.generic.websocket import AsyncJsonWebsocketConsumer\nfrom rest_framework.serializers import Serializer, CharField\nfrom drf_spectacular_websocket.decorators import extend_ws_schema\n\n\nclass SomeMethodInputSerializer(Serializer):\n    some_field = CharField()\n\n\nclass SomeMethodOutputSerializer(Serializer):\n    some_field = CharField()\n\n\nclass SendMessageOutputSerializer(Serializer):\n    some_field = CharField()\n\n\nclass SomeConsumer(AsyncJsonWebsocketConsumer):\n\n    async def receive_json(self, content, **kwargs):\n        some_value = content.get('some_key')\n        if some_value:\n            await self.some_method(some_value)\n\n    @extend_ws_schema(\n        type='send',\n        summary='some_method_summary',\n        description='some_method_description',\n        request=SomeMethodInputSerializer,\n        responses=SomeMethodOutputSerializer,\n    )\n    async def some_method(self, some_value):\n        input_serializer = SomeMethodInputSerializer(data=some_value)\n        input_serializer.is_valid(raise_exception=True)\n\n        return_value = await some_business_logic(input_serializer.validated_data)\n\n        output_serializer = SomeMethodOutputSerializer(data=return_value)\n        output_serializer.is_valid(raise_exception=True)\n\n        await self.send_json(output_serializer.validated_data)\n\n    @extend_ws_schema(\n        type='receive',\n        summary='send_message_summary',\n        description='send_message_description',\n        request=None,\n        responses=SendMessageOutputSerializer,\n    )\n    async def send_message(self, message):\n        await self.send_json(message)\n```\n\n## Contributing\nWe would love you to contribute to `drf-spectacular-websocket`, pull requests are very welcome! Please see [CONTRIBUTING.md](https://github.com/Friskes/drf-spectacular-websocket/blob/main/CONTRIBUTING.md) for more information.\n\n## Swagger Examples\n\n### Send\n![](https://raw.githubusercontent.com/Friskes/drf-spectacular-websocket/main/images/example_send.png)\n\n### Receive\n![](https://raw.githubusercontent.com/Friskes/drf-spectacular-websocket/main/images/example_receive.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffriskes%2Fdrf-spectacular-websocket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffriskes%2Fdrf-spectacular-websocket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffriskes%2Fdrf-spectacular-websocket/lists"}