Skip to content

Commit

Permalink
[VNG-Realisatie#218] update spectacular default settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Sonny Bakker committed Sep 21, 2022
1 parent e4b65c4 commit c7fec97
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 16 deletions.
23 changes: 23 additions & 0 deletions vng_api_common/conf/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"BASE_REST_FRAMEWORK",
"BASE_SPECTACULAR_SETTINGS",
"COMMON_SPEC",
"DRF_EXCLUDED_ENDPOINTS",
"LINK_FETCHER",
"ZDS_CLIENT_CLASS",
"GEMMA_URL_TEMPLATE",
Expand Down Expand Up @@ -64,8 +65,30 @@

BASE_SPECTACULAR_SETTINGS = {
"DEFAULT_GENERATOR_CLASS": "vng_api_common.generators.OpenAPISchemaGenerator",
"PREPROCESSING_HOOKS": ["vng_api_common.utils.get_schema_endpoints"],
"POSTPROCESSING_HOOKS": [
"drf_spectacular.hooks.postprocess_schema_enums",
"drf_spectacular.contrib.djangorestframework_camel_case.camelize_serializer_fields",
],
"SCHEMA_PATH_PREFIX": "/api/v1",
"APPEND_COMPONENTS": {
"securitySchemes": {
"JWT-Claims": {
"type": "http",
"bearerFormat": "JWT",
"scheme": "bearer",
}
},
},
"SECURITY": [
{
"JWT-Claims": [],
}
],
}

DRF_EXCLUDED_ENDPOINTS = ["callbacks", "jwtsecret/", "openapi.yaml", "openapi{var}"]

REDOC_SETTINGS = {"EXPAND_RESPONSES": "200,201", "SPEC_URL": "openapi.json"}

# See: https://github.com/Rebilly/ReDoc#redoc-options-object
Expand Down
2 changes: 0 additions & 2 deletions vng_api_common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

FILTER_URL_DID_NOT_RESOLVE = "NO_MATCHING_OBJECT"

DRF_EXCLUDED_ENDPOINTS = ["callbacks", "jwtsecret/", "openapi.yaml", "openapi{var}"]


class VertrouwelijkheidsAanduiding(DjangoChoices):
openbaar = ChoiceItem("openbaar", "Openbaar")
Expand Down
28 changes: 14 additions & 14 deletions vng_api_common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
from rest_framework.utils import formatting
from zds_client.client import ClientError

from vng_api_common.constants import DRF_EXCLUDED_ENDPOINTS

from .client import get_client

try:
Expand Down Expand Up @@ -272,16 +270,18 @@ def get_field_attribute(
return getattr(field, attr_name, None)


def preprocessing_filter_spec(endpoints):
"""exlude endpoints from drf-spectacular"""
filtered = []
def get_schema_endpoints(endpoints):
filtered_endpoints = []

for (path, path_regex, method, callback) in endpoints:
# Remove all but DRF API endpoints
include = True
for excluded_paths in DRF_EXCLUDED_ENDPOINTS:
if path.endswith(excluded_paths):
include = False
break
if include:
filtered.append((path, path_regex, method, callback))
return filtered
is_excluded = any(
(
path.endswith(excluded_path)
for excluded_path in settings.DRF_EXCLUDED_ENDPOINTS
)
)

if not is_excluded:
filtered_endpoints.append((path, path_regex, method, callback))

return filtered_endpoints

0 comments on commit c7fec97

Please sign in to comment.