-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbuild_config.py
82 lines (77 loc) · 2.52 KB
/
build_config.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from hooks import (
AddParametersOnBody,
AddParametersOnContent,
AddParametersOnParameters,
AddPathQueryIdOnParameters,
SetResponsesHeader,
)
class Config:
OUTPUT_DIR = "dist/{0}"
INPUT_DIR = "src/openapi"
def hooks_generator(self, queryParameterJson=True):
# https://stackoverflow.com/questions/34820064/defining-an-api-with-swagger-get-call-that-uses-json-in-parameters/45223964
if queryParameterJson:
# ["parameters"][0]["content"]["application/json"]["schema"]
getParamHook = AddParametersOnContent(
split=-1,
contentType="application/json",
ignoreKeys=["queryId"],
)
else:
# ["parameters"][0]["schema"]
getParamHook = AddParametersOnParameters(
split=-1,
schemaType="string",
ignoreKeys=["queryId"],
)
return {
"openapi": [],
"schemas": [],
"other": [],
"request": {
key: [
SetResponsesHeader(),
AddPathQueryIdOnParameters(split=-1),
getParamHook,
]
for key in ["default", "user", "users", "user-list", "tweet"]
}
| {
key: [
SetResponsesHeader(),
AddPathQueryIdOnParameters(split=-1),
AddParametersOnBody(
split=-1,
schemaType=None,
contentType="application/json",
),
]
for key in ["post"]
}
| {
key: [
SetResponsesHeader(),
AddParametersOnParameters(split=2, schemaType=None),
]
for key in ["v1.1-get", "v2.0-get"]
}
| {
key: [
SetResponsesHeader(),
AddParametersOnBody(
split=2,
schemaType=None,
contentType="application/x-www-form-urlencoded",
),
]
for key in ["v1.1-post", "v2.0-post"]
}
| {"other": []},
}
def main(self):
return {
"docs": self.hooks_generator(),
"compatible": self.hooks_generator(
queryParameterJson=False,
),
}