File: checks.py

package info (click to toggle)
python-drf-spectacular 0.28.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,748 kB
  • sloc: python: 14,174; javascript: 114; sh: 61; makefile: 30
file content (26 lines) | stat: -rw-r--r-- 999 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from django.core.checks import Error, Warning, register


@register(deploy=True)
def schema_check(app_configs, **kwargs):
    """ Perform dummy generation and emit warnings/errors as part of Django's check framework """
    from drf_spectacular.drainage import GENERATOR_STATS
    from drf_spectacular.settings import spectacular_settings

    if not spectacular_settings.ENABLE_DJANGO_DEPLOY_CHECK:
        return []

    errors = []
    try:
        with GENERATOR_STATS.silence():
            spectacular_settings.DEFAULT_GENERATOR_CLASS().get_schema(request=None, public=True)
    except Exception as exc:
        errors.append(
            Error(f'Schema generation threw exception "{exc}"', id='drf_spectacular.E001')
        )
    if GENERATOR_STATS:
        for w in GENERATOR_STATS._warn_cache:
            errors.append(Warning(w, id='drf_spectacular.W001'))
        for e in GENERATOR_STATS._error_cache:
            errors.append(Warning(e, id='drf_spectacular.W002'))
    return errors