forked from pulp/pulpcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use postprocessing hooks instead of monkeypatching inner plumbings of drf-spectacular. This should vastly improve stability and the ability to upgrade spectacular. [noissue]
- Loading branch information
Showing
3 changed files
with
52 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from django.conf import settings | ||
|
||
|
||
def add_info_hook(result, generator, request, **kwargs): | ||
# Basically I'm doing it to get pulp logo at redoc page | ||
result["info"]["x-logo"] = { | ||
"url": "https://pulp.plan.io/attachments/download/517478/pulp_logo_word_rectangle.svg" | ||
} | ||
|
||
# Adding plugin version config | ||
result["info"]["x-pulp-app-versions"] = {app.label: app.version for app in request.apps} | ||
|
||
# Add domain-settings value | ||
result["info"]["x-pulp-domain-enabled"] = settings.DOMAIN_ENABLED | ||
|
||
# Add x-isDomain flag to domain path parameters | ||
# Save a copy of the bad operationId in case we generate bindings | ||
for path, path_spec in result["paths"].items(): | ||
for operation, operation_spec in path_spec.items(): | ||
if request.bindings: | ||
# Keep the operation id before sanitization | ||
operation_spec["x-copy-operationId"] = operation_spec["operationId"] | ||
if settings.DOMAIN_ENABLED: | ||
parameters = operation_spec.get("parameters") | ||
if parameters: | ||
for parameter in parameters: | ||
if parameter["name"] == "pulp_domain" and parameter["in"] == "path": | ||
parameter["x-isDomain"] = True | ||
|
||
# Adding current host as server (it will provide a default value for the bindings) | ||
result["servers"] = [{"url": request.build_absolute_uri("/")}] | ||
|
||
return result |