mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-28 00:49:49 +03:00
add guidance for overriding get_tags method
This commit is contained in:
parent
22da4772c8
commit
95831b5be1
|
@ -221,7 +221,7 @@ project you may adjust `settings.DEFAULT_SCHEMA_CLASS` appropriately.
|
|||
Tags can be used to group logical operations. Each tag name in the list MUST be unique.
|
||||
|
||||
---
|
||||
#### Django REST Framework generates tags automatically with following logic:
|
||||
#### Django REST Framework generates tags automatically with the following logic:
|
||||
|
||||
1. Extract tag from `ViewSet`.
|
||||
1. If `ViewSet` name ends with `ViewSet`, or `View`; remove it.
|
||||
|
@ -277,6 +277,32 @@ class MyView(APIView):
|
|||
...
|
||||
```
|
||||
|
||||
If you need more customization, you can override the `get_tags` method of `AutoSchema` class. Consider the following example:
|
||||
|
||||
```python
|
||||
from rest_framework.schemas.openapi import AutoSchema
|
||||
from rest_framework.views import APIView
|
||||
|
||||
class MySchema(AutoSchema):
|
||||
...
|
||||
def get_tags(self, path, method):
|
||||
if method == 'POST':
|
||||
tags = ['tag1', 'tag2']
|
||||
elif method == 'GET':
|
||||
tags = ['tag2', 'tag3']
|
||||
elif path == '/example/path/':
|
||||
tags = ['tag3', 'tag4']
|
||||
else:
|
||||
tags = ['tag5', 'tag6', 'tag7']
|
||||
|
||||
return tags
|
||||
|
||||
class MyView(APIView):
|
||||
schema = MySchema()
|
||||
...
|
||||
```
|
||||
|
||||
|
||||
[openapi]: https://github.com/OAI/OpenAPI-Specification
|
||||
[openapi-specification-extensions]: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#specification-extensions
|
||||
[openapi-operation]: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#operationObject
|
||||
|
|
Loading…
Reference in New Issue
Block a user