Enhance API documentation and schema management by implementing explicit tag configurations for Swagger and ReDoc. Introduce postprocessing hooks to filter auto-generated tags, ensuring only defined tags are used. Update viewsets across various modules to utilize the new tagging system, improving clarity and organization in API documentation.

This commit is contained in:
IGNY8 VPS (Salman)
2025-11-16 04:48:14 +00:00
parent dee2a36ff0
commit 3694e40c04
11 changed files with 363 additions and 3 deletions

View File

@@ -331,7 +331,8 @@ SPECTACULAR_SETTINGS = {
# Include request/response examples
'SERVE_PERMISSIONS': ['rest_framework.permissions.AllowAny'],
'SERVE_AUTHENTICATION': None, # Allow unauthenticated access to docs
# Tags for grouping endpoints
# Tag configuration - prevent auto-generation and use explicit tags
'TAGS': [
{'name': 'Authentication', 'description': 'User authentication and registration'},
{'name': 'Planner', 'description': 'Keywords, clusters, and content ideas'},
@@ -339,6 +340,54 @@ SPECTACULAR_SETTINGS = {
{'name': 'System', 'description': 'Settings, prompts, and integrations'},
{'name': 'Billing', 'description': 'Credits, usage, and transactions'},
],
'TAGS_ORDER': ['Authentication', 'Planner', 'Writer', 'System', 'Billing'],
# Postprocessing hook to filter out auto-generated tags
'POSTPROCESSING_HOOKS': ['igny8_core.api.schema_extensions.postprocess_schema_filter_tags'],
# Swagger UI configuration
'SWAGGER_UI_SETTINGS': {
'deepLinking': True,
'displayOperationId': False,
'defaultModelsExpandDepth': 1, # Collapse models by default
'defaultModelExpandDepth': 1, # Collapse model properties by default
'defaultModelRendering': 'model', # Show models in a cleaner format
'displayRequestDuration': True,
'docExpansion': 'none', # Collapse all operations by default
'filter': True, # Enable filter box
'showExtensions': True,
'showCommonExtensions': True,
'tryItOutEnabled': True, # Enable "Try it out" by default
},
# ReDoc configuration
'REDOC_UI_SETTINGS': {
'hideDownloadButton': False,
'hideHostname': False,
'hideLoading': False,
'hideSingleRequestSampleTab': False,
'expandResponses': '200,201', # Expand successful responses
'jsonSampleExpandLevel': 2, # Expand JSON samples 2 levels
'hideFab': False,
'theme': {
'colors': {
'primary': {
'main': '#32329f'
}
}
}
},
# Schema presentation improvements
'SCHEMA_COERCE_PATH_PK': True,
'SCHEMA_COERCE_METHOD_NAMES': {
'retrieve': 'get',
'list': 'list',
'create': 'post',
'update': 'put',
'partial_update': 'patch',
'destroy': 'delete',
},
# Custom response format documentation
'EXTENSIONS_INFO': {
'x-code-samples': [