File: utils.py

package info (click to toggle)
apispec 6.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 652 kB
  • sloc: python: 4,852; makefile: 150; sh: 10
file content (47 lines) | stat: -rw-r--r-- 1,241 bytes parent folder | download | duplicates (2)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""Utilities to get elements of generated spec"""

from apispec import exceptions
from apispec.core import APISpec
from apispec.utils import build_reference


def get_schemas(spec):
    if spec.openapi_version.major < 3:
        return spec.to_dict()["definitions"]
    return spec.to_dict()["components"]["schemas"]


def get_responses(spec):
    if spec.openapi_version.major < 3:
        return spec.to_dict()["responses"]
    return spec.to_dict()["components"]["responses"]


def get_parameters(spec):
    if spec.openapi_version.major < 3:
        return spec.to_dict()["parameters"]
    return spec.to_dict()["components"]["parameters"]


def get_headers(spec):
    if spec.openapi_version.major < 3:
        return spec.to_dict()["headers"]
    return spec.to_dict()["components"]["headers"]


def get_examples(spec):
    return spec.to_dict()["components"]["examples"]


def get_security_schemes(spec):
    if spec.openapi_version.major < 3:
        return spec.to_dict()["securityDefinitions"]
    return spec.to_dict()["components"]["securitySchemes"]


def get_paths(spec):
    return spec.to_dict()["paths"]


def build_ref(spec, component_type, obj):
    return build_reference(component_type, spec.openapi_version.major, obj)