You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm looking for a way to override SWAGGER_UI_SETTINGS for a given SpectacularSwaggerView as I want to serve different schemas for admins and customers.
My urls.py look like this:
urlpatterns= [
...
path("docs/", SpectacularSwaggerView.as_view(url_name="v4-schema"), name="docs"),
path(
"docs/customers/",
SpectacularSwaggerView.as_view(url_name="v4-customers-schema"),
name="customers-docs",
),
path(
"schema/v3/",
SpectacularAPIView.as_view(
api_version="v3", custom_settings={"VERSION": "3.0.0"}
),
name="v3-schema",
),
path(
"schema/v4/",
SpectacularAPIView.as_view(
api_version="v4", custom_settings={"VERSION": "4.0.0"}
),
name="v4-schema",
),
path(
"schema/customers/v3/",
SpectacularAPIView.as_view(
api_version="v3",
custom_settings={
"APPEND_COMPONENTS": {
"securitySchemes": {
"ApiKeyAuth": {
"type": "apiKey",
"in": "header",
"name": "X-API-Key",
}
}
},
"AUTHENTICATION_WHITELIST": ["src.customers.permissions.HasAPIKey"],
"SCHEMA_PATH_PREFIX": r"^(/customers/v3/)$",
"VERSION": "3.0.0",
},
serve_public=False, # Customer will need to Authorize in the UI via API Key
),
name="v3-customers-schema",
),
path(
"schema/customers/v4/",
SpectacularAPIView.as_view(
api_version="v4",
custom_settings={
"APPEND_COMPONENTS": {
"securitySchemes": {
"ApiKeyAuth": {
"type": "apiKey",
"in": "header",
"name": "X-API-Key",
}
}
},
"AUTHENTICATION_WHITELIST": ["src.customers.permissions.HasAPIKey"],
"SCHEMA_PATH_PREFIX": r"^(/customers/v3/)$",
"VERSION": "4.0.0",
},
serve_public=False, # Customer will need to Authorize in the UI via API Key
),
name="v4-customers-schema",
)
]
The issue that I'm encountering is that due to my API having versioning enabled via SWAGGER_UI_SETTINGS.urls I have no way of overriding the schema urls for the customers-docs view as it will always point to urls: [{url: "/schema/v4/", name: "v4"}, {url: "/schema/v3/", name: "v3"}].
My goal is to somehow set urls: [{url: "/schema/customers/v4/", name: "v4"}, {url: "/schema/customers/v3/", name: "v3"}] for the customers-docs view, but that doesn't seem to be possible via custom_settings.
Am I missing something? Is there a better way to achieve what I'm trying to achieve?
Thanks for the help!
The text was updated successfully, but these errors were encountered:
I'm looking for a way to override
SWAGGER_UI_SETTINGS
for a givenSpectacularSwaggerView
as I want to serve different schemas for admins and customers.My urls.py
look like this:And my
SPECTACULAR_SETTINGS
look like this:The issue that I'm encountering is that due to my API having versioning enabled via
SWAGGER_UI_SETTINGS.urls
I have no way of overriding the schema urls for thecustomers-docs
view as it will always point tourls: [{url: "/schema/v4/", name: "v4"}, {url: "/schema/v3/", name: "v3"}]
.My goal is to somehow set
urls: [{url: "/schema/customers/v4/", name: "v4"}, {url: "/schema/customers/v3/", name: "v3"}]
for thecustomers-docs
view, but that doesn't seem to be possible viacustom_settings
.Am I missing something? Is there a better way to achieve what I'm trying to achieve?
Thanks for the help!
The text was updated successfully, but these errors were encountered: