Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved the operationIds by implementing a post hook function #3021

Merged
merged 7 commits into from
Jul 23, 2023
3 changes: 3 additions & 0 deletions config/settings/common_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ def pipe_delim(pipe_string):
'DESCRIPTION': '',
'VERSION': '1.0.0',
'SERVE_INCLUDE_SCHEMA': False,
'POSTPROCESSING_HOOKS': [
'config.settings.openapi.remove_url_prefix_hook',
],
# OTHER SETTINGS
}
FRIENDLY_ERRORS = {
Expand Down
12 changes: 12 additions & 0 deletions config/settings/openapi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def remove_url_prefix_hook(generator, result, request, public):
# Remove namespace and version url prefix from the operation Id of the generated API schema
for path, path_info in result['paths'].items():
for method, operation in path_info.items():
operation_id = operation.get('operationId')
if operation_id:
if path.startswith('/api/db/v0/'):
operation['operationId'] = operation_id.replace('db_v0_', '')
elif path.startswith('/api/ui/v0/'):
operation['operationId'] = operation_id.replace('ui_v0_', '')

return result