twitter-openapi-typescript-generated 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.openapi-generator-ignore +1 -2
- package/README.md +2 -2
- package/package.json +25 -26
- package/tools/openapi-generator-config.yaml +10 -0
- package/tools/win/clean.ps1 +21 -0
- package/tools/win/gen.ps1 +8 -0
- package/tools/win/init.ps1 +1 -0
- package/tools/win/replace.py +40 -0
- package/twitter-openapi/.vscode/extensions.json +3 -0
- package/twitter-openapi/.vscode/settings.json +9 -0
- package/twitter-openapi/LICENSE.txt +661 -0
- package/twitter-openapi/README.md +38 -0
- package/twitter-openapi/dist/dart/openapi-3.0.yaml +111 -0
- package/twitter-openapi/dist/dart/paths/bookmarks.yaml +134 -0
- package/twitter-openapi/dist/dart/paths/follow.yaml +262 -0
- package/twitter-openapi/dist/dart/paths/other.yaml +96 -0
- package/twitter-openapi/dist/dart/paths/post.yaml +834 -0
- package/twitter-openapi/dist/dart/paths/profile.yaml +152 -0
- package/twitter-openapi/dist/dart/paths/timeline.yaml +380 -0
- package/twitter-openapi/dist/dart/paths/tweet.yaml +134 -0
- package/twitter-openapi/dist/dart/paths/user.yaml +112 -0
- package/twitter-openapi/dist/dart/paths/usertweets.yaml +484 -0
- package/twitter-openapi/dist/dart/paths/v1.1-get.yaml +300 -0
- package/twitter-openapi/dist/dart/paths/v1.1-post.yaml +295 -0
- package/twitter-openapi/dist/dart/paths/v2.0-get.yaml +331 -0
- package/twitter-openapi/dist/dart/response/error.yaml +90 -0
- package/twitter-openapi/dist/dart/schemas/content.yaml +181 -0
- package/twitter-openapi/dist/dart/schemas/general.yaml +13 -0
- package/twitter-openapi/dist/dart/schemas/instruction.yaml +83 -0
- package/twitter-openapi/dist/dart/schemas/timeline.yaml +25 -0
- package/twitter-openapi/dist/dart/schemas/tweet.yaml +251 -0
- package/twitter-openapi/dist/dart/schemas/typename.yaml +19 -0
- package/twitter-openapi/dist/dart/schemas/user.yaml +206 -0
- package/twitter-openapi/dist/docs/openapi-3.0.yaml +135 -0
- package/twitter-openapi/dist/docs/paths/bookmarks.yaml +248 -0
- package/twitter-openapi/dist/docs/paths/follow.yaml +486 -0
- package/twitter-openapi/dist/docs/paths/other.yaml +96 -0
- package/twitter-openapi/dist/docs/paths/post.yaml +638 -0
- package/twitter-openapi/dist/docs/paths/profile.yaml +159 -0
- package/twitter-openapi/dist/docs/paths/timeline.yaml +730 -0
- package/twitter-openapi/dist/docs/paths/tweet.yaml +272 -0
- package/twitter-openapi/dist/docs/paths/user.yaml +152 -0
- package/twitter-openapi/dist/docs/paths/usertweets.yaml +1010 -0
- package/twitter-openapi/dist/docs/paths/v1.1-get.yaml +242 -0
- package/twitter-openapi/dist/docs/paths/v1.1-post.yaml +237 -0
- package/twitter-openapi/dist/docs/paths/v2.0-get.yaml +302 -0
- package/twitter-openapi/dist/docs/response/error.yaml +90 -0
- package/twitter-openapi/dist/docs/schemas/content.yaml +181 -0
- package/twitter-openapi/dist/docs/schemas/general.yaml +13 -0
- package/twitter-openapi/dist/docs/schemas/instruction.yaml +83 -0
- package/twitter-openapi/dist/docs/schemas/timeline.yaml +25 -0
- package/twitter-openapi/dist/docs/schemas/tweet.yaml +251 -0
- package/twitter-openapi/dist/docs/schemas/typename.yaml +19 -0
- package/twitter-openapi/dist/docs/schemas/user.yaml +206 -0
- package/twitter-openapi/dist/test/openapi-3.0.yaml +135 -0
- package/twitter-openapi/dist/test/paths/bookmarks.yaml +105 -0
- package/twitter-openapi/dist/test/paths/follow.yaml +204 -0
- package/twitter-openapi/dist/test/paths/other.yaml +96 -0
- package/twitter-openapi/dist/test/paths/post.yaml +485 -0
- package/twitter-openapi/dist/test/paths/profile.yaml +123 -0
- package/twitter-openapi/dist/test/paths/timeline.yaml +293 -0
- package/twitter-openapi/dist/test/paths/tweet.yaml +105 -0
- package/twitter-openapi/dist/test/paths/user.yaml +83 -0
- package/twitter-openapi/dist/test/paths/usertweets.yaml +368 -0
- package/twitter-openapi/dist/test/paths/v1.1-get.yaml +242 -0
- package/twitter-openapi/dist/test/paths/v1.1-post.yaml +277 -0
- package/twitter-openapi/dist/test/paths/v2.0-get.yaml +302 -0
- package/twitter-openapi/dist/test/response/error.yaml +90 -0
- package/twitter-openapi/dist/test/schemas/content.yaml +181 -0
- package/twitter-openapi/dist/test/schemas/general.yaml +13 -0
- package/twitter-openapi/dist/test/schemas/instruction.yaml +83 -0
- package/twitter-openapi/dist/test/schemas/timeline.yaml +25 -0
- package/twitter-openapi/dist/test/schemas/tweet.yaml +251 -0
- package/twitter-openapi/dist/test/schemas/typename.yaml +19 -0
- package/twitter-openapi/dist/test/schemas/user.yaml +206 -0
- package/twitter-openapi/dist/typescript/openapi-3.0.yaml +135 -0
- package/twitter-openapi/dist/typescript/paths/bookmarks.yaml +105 -0
- package/twitter-openapi/dist/typescript/paths/follow.yaml +204 -0
- package/twitter-openapi/dist/typescript/paths/other.yaml +96 -0
- package/twitter-openapi/dist/typescript/paths/post.yaml +660 -0
- package/twitter-openapi/dist/typescript/paths/profile.yaml +123 -0
- package/twitter-openapi/dist/typescript/paths/timeline.yaml +293 -0
- package/twitter-openapi/dist/typescript/paths/tweet.yaml +105 -0
- package/twitter-openapi/dist/typescript/paths/user.yaml +83 -0
- package/twitter-openapi/dist/typescript/paths/usertweets.yaml +368 -0
- package/twitter-openapi/dist/typescript/paths/v1.1-get.yaml +242 -0
- package/twitter-openapi/dist/typescript/paths/v1.1-post.yaml +237 -0
- package/twitter-openapi/dist/typescript/paths/v2.0-get.yaml +302 -0
- package/twitter-openapi/dist/typescript/response/error.yaml +90 -0
- package/twitter-openapi/dist/typescript/schemas/content.yaml +181 -0
- package/twitter-openapi/dist/typescript/schemas/general.yaml +13 -0
- package/twitter-openapi/dist/typescript/schemas/instruction.yaml +83 -0
- package/twitter-openapi/dist/typescript/schemas/timeline.yaml +25 -0
- package/twitter-openapi/dist/typescript/schemas/tweet.yaml +251 -0
- package/twitter-openapi/dist/typescript/schemas/typename.yaml +19 -0
- package/twitter-openapi/dist/typescript/schemas/user.yaml +206 -0
- package/twitter-openapi/requirements.txt +0 -0
- package/twitter-openapi/src/config/component/response_header.yaml +32 -0
- package/twitter-openapi/src/config/component/response_header_legacy.yaml +35 -0
- package/twitter-openapi/src/config/component/security_schemes.yaml +67 -0
- package/twitter-openapi/src/config/placeholder.json +535 -0
- package/twitter-openapi/src/openapi/openapi-3.0.yaml +68 -0
- package/twitter-openapi/src/openapi/paths/bookmarks.yaml +42 -0
- package/twitter-openapi/src/openapi/paths/follow.yaml +73 -0
- package/twitter-openapi/src/openapi/paths/other.yaml +101 -0
- package/twitter-openapi/src/openapi/paths/post.yaml +246 -0
- package/twitter-openapi/src/openapi/paths/profile.yaml +81 -0
- package/twitter-openapi/src/openapi/paths/timeline.yaml +98 -0
- package/twitter-openapi/src/openapi/paths/tweet.yaml +35 -0
- package/twitter-openapi/src/openapi/paths/user.yaml +35 -0
- package/twitter-openapi/src/openapi/paths/usertweets.yaml +94 -0
- package/twitter-openapi/src/openapi/paths/v1.1-get.yaml +25 -0
- package/twitter-openapi/src/openapi/paths/v1.1-post.yaml +25 -0
- package/twitter-openapi/src/openapi/paths/v2.0-get.yaml +15 -0
- package/twitter-openapi/src/openapi/response/error.yaml +97 -0
- package/twitter-openapi/src/openapi/schemas/content.yaml +190 -0
- package/twitter-openapi/src/openapi/schemas/general.yaml +12 -0
- package/twitter-openapi/src/openapi/schemas/instruction.yaml +90 -0
- package/twitter-openapi/src/openapi/schemas/timeline.yaml +27 -0
- package/twitter-openapi/src/openapi/schemas/tweet.yaml +264 -0
- package/twitter-openapi/src/openapi/schemas/typename.yaml +21 -0
- package/twitter-openapi/src/openapi/schemas/user.yaml +210 -0
- package/twitter-openapi/tools/__pycache__/build_config.cpython-310.pyc +0 -0
- package/twitter-openapi/tools/__pycache__/hooks.cpython-310.pyc +0 -0
- package/twitter-openapi/tools/build.py +79 -0
- package/twitter-openapi/tools/build_config.py +200 -0
- package/twitter-openapi/tools/hooks.py +265 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
from hooks import *
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Config:
|
|
5
|
+
OUTPUT_DIR = "dist/{0}"
|
|
6
|
+
INPUT_DIR = "src/openapi"
|
|
7
|
+
|
|
8
|
+
def main(self):
|
|
9
|
+
return {
|
|
10
|
+
"docs": {
|
|
11
|
+
"openapi": [AddSecuritySchemesOnSecuritySchemes()],
|
|
12
|
+
"schemas": [],
|
|
13
|
+
"other":[],
|
|
14
|
+
"request": {
|
|
15
|
+
key: [
|
|
16
|
+
ReplaceQueryIdPlaceholder(split=-1),
|
|
17
|
+
SetResponsesHeader(suffix=None),
|
|
18
|
+
AddParametersOnContent(
|
|
19
|
+
split=-1, contentType="application/json"
|
|
20
|
+
),
|
|
21
|
+
]
|
|
22
|
+
for key in ["default", "user", "user-list", "tweet"]
|
|
23
|
+
}
|
|
24
|
+
| {
|
|
25
|
+
key: [
|
|
26
|
+
ReplaceQueryIdPlaceholder(split=-1),
|
|
27
|
+
SetResponsesHeader(suffix=None),
|
|
28
|
+
AddParametersOnParameters(
|
|
29
|
+
split=-1,
|
|
30
|
+
schemaType=None,
|
|
31
|
+
),
|
|
32
|
+
]
|
|
33
|
+
for key in ["post"]
|
|
34
|
+
}
|
|
35
|
+
| {
|
|
36
|
+
key: [
|
|
37
|
+
SetResponsesHeader(suffix="legacy"),
|
|
38
|
+
AddParametersOnParameters(
|
|
39
|
+
split=2,
|
|
40
|
+
schemaType=None,
|
|
41
|
+
),
|
|
42
|
+
]
|
|
43
|
+
for key in ["v1.1-get", "v2.0-get"]
|
|
44
|
+
}
|
|
45
|
+
| {
|
|
46
|
+
key: [
|
|
47
|
+
SetResponsesHeader(suffix="legacy"),
|
|
48
|
+
AddParametersOnBody(
|
|
49
|
+
split=2,
|
|
50
|
+
schemaType=None,
|
|
51
|
+
contentType="application/x-www-form-urlencoded",
|
|
52
|
+
),
|
|
53
|
+
]
|
|
54
|
+
for key in ["v1.1-post", "v2.0-post"]
|
|
55
|
+
}
|
|
56
|
+
| {"other": []},
|
|
57
|
+
},
|
|
58
|
+
"dart": {
|
|
59
|
+
"openapi": [],
|
|
60
|
+
"schemas": [],
|
|
61
|
+
"other":[],
|
|
62
|
+
"request": {
|
|
63
|
+
key: [
|
|
64
|
+
ReplaceQueryIdPlaceholder(split=-1),
|
|
65
|
+
AddSecuritySchemesOnHeader(split=-1),
|
|
66
|
+
SetResponsesHeader(suffix=None),
|
|
67
|
+
AddParametersOnParameters(
|
|
68
|
+
split=-1,
|
|
69
|
+
schemaType="string",
|
|
70
|
+
),
|
|
71
|
+
]
|
|
72
|
+
for key in ["default", "user", "user-list", "tweet"]
|
|
73
|
+
}
|
|
74
|
+
| {
|
|
75
|
+
key: [
|
|
76
|
+
ReplaceQueryIdPlaceholder(split=-1),
|
|
77
|
+
AddSecuritySchemesOnHeader(split=-1),
|
|
78
|
+
SetResponsesHeader(suffix=None),
|
|
79
|
+
AddParametersOnBody(
|
|
80
|
+
split=-1,
|
|
81
|
+
schemaType=None,
|
|
82
|
+
contentType="application/json",
|
|
83
|
+
),
|
|
84
|
+
]
|
|
85
|
+
for key in ["post"]
|
|
86
|
+
}
|
|
87
|
+
| {
|
|
88
|
+
key: [
|
|
89
|
+
SetResponsesHeader(suffix="legacy"),
|
|
90
|
+
AddSecuritySchemesOnHeader(split=-1),
|
|
91
|
+
AddParametersOnParameters(
|
|
92
|
+
split=2,
|
|
93
|
+
schemaType=None,
|
|
94
|
+
),
|
|
95
|
+
]
|
|
96
|
+
for key in ["v1.1-get", "v2.0-get"]
|
|
97
|
+
}
|
|
98
|
+
| {
|
|
99
|
+
key: [
|
|
100
|
+
SetResponsesHeader(suffix="legacy"),
|
|
101
|
+
AddSecuritySchemesOnHeader(split=-1),
|
|
102
|
+
AddParametersOnBody(
|
|
103
|
+
split=2,
|
|
104
|
+
schemaType=None,
|
|
105
|
+
contentType="application/x-www-form-urlencoded",
|
|
106
|
+
),
|
|
107
|
+
]
|
|
108
|
+
for key in ["v1.1-post", "v2.0-post"]
|
|
109
|
+
}
|
|
110
|
+
| {"other": []},
|
|
111
|
+
},
|
|
112
|
+
"typescript": {
|
|
113
|
+
"openapi": [AddSecuritySchemesOnSecuritySchemes()],
|
|
114
|
+
"schemas": [],
|
|
115
|
+
"other":[],
|
|
116
|
+
"request": {
|
|
117
|
+
key: [
|
|
118
|
+
ReplaceQueryIdPlaceholder(split=-1),
|
|
119
|
+
SetResponsesHeader(suffix=None),
|
|
120
|
+
AddParametersOnParameters(
|
|
121
|
+
split=-1,
|
|
122
|
+
schemaType="string",
|
|
123
|
+
),
|
|
124
|
+
]
|
|
125
|
+
for key in ["default", "user", "user-list", "tweet"]
|
|
126
|
+
}
|
|
127
|
+
| {
|
|
128
|
+
key: [
|
|
129
|
+
ReplaceQueryIdPlaceholder(split=-1),
|
|
130
|
+
SetResponsesHeader(suffix=None),
|
|
131
|
+
AddParametersOnBody(
|
|
132
|
+
split=-1,
|
|
133
|
+
schemaType=None,
|
|
134
|
+
contentType="application/json",
|
|
135
|
+
),
|
|
136
|
+
]
|
|
137
|
+
for key in ["post"]
|
|
138
|
+
}
|
|
139
|
+
| {
|
|
140
|
+
key: [
|
|
141
|
+
SetResponsesHeader(suffix="legacy"),
|
|
142
|
+
AddParametersOnParameters(
|
|
143
|
+
split=2,
|
|
144
|
+
schemaType=None,
|
|
145
|
+
),
|
|
146
|
+
]
|
|
147
|
+
for key in ["v1.1-get", "v2.0-get"]
|
|
148
|
+
}
|
|
149
|
+
| {
|
|
150
|
+
key: [
|
|
151
|
+
SetResponsesHeader(suffix="legacy"),
|
|
152
|
+
AddParametersOnBody(
|
|
153
|
+
split=2,
|
|
154
|
+
schemaType=None,
|
|
155
|
+
contentType="application/x-www-form-urlencoded",
|
|
156
|
+
),
|
|
157
|
+
]
|
|
158
|
+
for key in ["v1.1-post", "v2.0-post"]
|
|
159
|
+
}
|
|
160
|
+
| {"other": []},
|
|
161
|
+
},
|
|
162
|
+
"test": {
|
|
163
|
+
"openapi": [AddSecuritySchemesOnSecuritySchemes()],
|
|
164
|
+
"schemas": [],
|
|
165
|
+
"other":[],
|
|
166
|
+
"request": {
|
|
167
|
+
key: [
|
|
168
|
+
ReplaceQueryIdPlaceholder(split=-1),
|
|
169
|
+
SetResponsesHeader(suffix=None),
|
|
170
|
+
AddParametersOnParameters(
|
|
171
|
+
split=-1,
|
|
172
|
+
schemaType="string",
|
|
173
|
+
),
|
|
174
|
+
]
|
|
175
|
+
for key in ["default", "user", "user-list", "tweet"]
|
|
176
|
+
}
|
|
177
|
+
| {
|
|
178
|
+
key: [
|
|
179
|
+
ReplaceQueryIdPlaceholder(split=-1),
|
|
180
|
+
SetResponsesHeader(suffix=None),
|
|
181
|
+
AddParametersOnParameters(
|
|
182
|
+
split=-1,
|
|
183
|
+
schemaType="string",
|
|
184
|
+
),
|
|
185
|
+
]
|
|
186
|
+
for key in ["post"]
|
|
187
|
+
}
|
|
188
|
+
| {
|
|
189
|
+
key: [
|
|
190
|
+
SetResponsesHeader(suffix="legacy"),
|
|
191
|
+
AddParametersOnParameters(
|
|
192
|
+
split=2,
|
|
193
|
+
schemaType="object",
|
|
194
|
+
),
|
|
195
|
+
]
|
|
196
|
+
for key in ["v1.1-get", "v1.1-post", "v2.0-get", "v2.0-post"]
|
|
197
|
+
}
|
|
198
|
+
| {"other": []},
|
|
199
|
+
},
|
|
200
|
+
}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import yaml
|
|
2
|
+
import json
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class HookBase:
|
|
6
|
+
PLACEHOLDER: dict
|
|
7
|
+
|
|
8
|
+
def __init__(self):
|
|
9
|
+
with open("src/config/placeholder.json", mode="r", encoding="utf-8") as f:
|
|
10
|
+
self.PLACEHOLDER = json.load(f)
|
|
11
|
+
|
|
12
|
+
def placeholder_to_yaml(self, obj, default=False, example=False) -> dict:
|
|
13
|
+
fn = lambda x: self.placeholder_to_yaml(x, default=default, example=example)
|
|
14
|
+
if type(obj) is dict:
|
|
15
|
+
properties = {i: fn(obj[i]) for i in obj}
|
|
16
|
+
value = {
|
|
17
|
+
"type": "object",
|
|
18
|
+
"properties": properties,
|
|
19
|
+
}
|
|
20
|
+
value.update({"required": [i for i in obj]} if len(obj) > 0 else {})
|
|
21
|
+
value.update({"default": properties} if default else {})
|
|
22
|
+
value.update({"example": properties} if example else {})
|
|
23
|
+
return value
|
|
24
|
+
elif type(obj) is list and len(obj) > 0:
|
|
25
|
+
properties = fn(obj[0])
|
|
26
|
+
value = {
|
|
27
|
+
"type": "array",
|
|
28
|
+
"items": properties,
|
|
29
|
+
}
|
|
30
|
+
value.update({"default": [properties]} if default else {})
|
|
31
|
+
value.update({"example": [properties]} if example else {})
|
|
32
|
+
return value
|
|
33
|
+
elif type(obj) is list and len(obj) == 0:
|
|
34
|
+
value = {
|
|
35
|
+
"type": "array",
|
|
36
|
+
"items": {"type": "object"},
|
|
37
|
+
}
|
|
38
|
+
value.update({"default": []} if default else {})
|
|
39
|
+
value.update({"example": []} if example else {})
|
|
40
|
+
return value
|
|
41
|
+
elif type(obj) is str:
|
|
42
|
+
return {"type": "string", "example": obj, "default": obj}
|
|
43
|
+
elif type(obj) is bool:
|
|
44
|
+
return {"type": "boolean", "example": obj, "default": obj}
|
|
45
|
+
elif type(obj) is int:
|
|
46
|
+
return {"type": "integer", "example": obj, "default": obj}
|
|
47
|
+
|
|
48
|
+
def load_component(self, name: str) -> dict:
|
|
49
|
+
with open(f"src/config/component/{name}.yaml", mode="r", encoding="utf-8") as f:
|
|
50
|
+
return yaml.safe_load(f)
|
|
51
|
+
|
|
52
|
+
def load_placeholder(self) -> dict:
|
|
53
|
+
with open("src/config/placeholder.json", mode="r", encoding="utf-8") as f:
|
|
54
|
+
return yaml.safe_load(f)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
# HookBase extends
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class OpenapiHookBase(HookBase):
|
|
61
|
+
def hook(self, value: dict)->dict:
|
|
62
|
+
return value
|
|
63
|
+
|
|
64
|
+
class OtherHookBase(HookBase):
|
|
65
|
+
def hook(self)->tuple[str, dict]:
|
|
66
|
+
return "", {}
|
|
67
|
+
|
|
68
|
+
class SchemasHookBase(HookBase):
|
|
69
|
+
def hook(self, value: dict)->dict:
|
|
70
|
+
return value
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class RequestHookBase(HookBase):
|
|
74
|
+
split: int
|
|
75
|
+
path_name: str
|
|
76
|
+
|
|
77
|
+
def __init__(self, split=1):
|
|
78
|
+
super().__init__()
|
|
79
|
+
self.split = split
|
|
80
|
+
|
|
81
|
+
def hook(self, path: str, value: dict)->tuple[str, dict]:
|
|
82
|
+
value["parameters"] = value.get("parameters", [])
|
|
83
|
+
self.path_name = "/".join(path.split("/")[self.split :])
|
|
84
|
+
return path, value
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
# OpenapiHookBase extends
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class AddSecuritySchemesOnSecuritySchemes(OpenapiHookBase):
|
|
91
|
+
def hook(self, value: dict):
|
|
92
|
+
value = super().hook(value)
|
|
93
|
+
component = self.load_component("security_schemes")
|
|
94
|
+
param = component["components"]["securitySchemes"]
|
|
95
|
+
value["components"]["securitySchemes"].update(param)
|
|
96
|
+
value["security"].extend(component["security"])
|
|
97
|
+
return value
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
# SchemasHookBase extends
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class RemoveDiscriminator(SchemasHookBase):
|
|
104
|
+
def hook(self, value: dict):
|
|
105
|
+
if value.get("discriminator") is not None:
|
|
106
|
+
del value["discriminator"]
|
|
107
|
+
return value
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
# RequestHookBase extends
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
class AddSecuritySchemesOnHeader(RequestHookBase):
|
|
114
|
+
def hook(self, path: str, value: dict):
|
|
115
|
+
path, value = super().hook(path, value)
|
|
116
|
+
component = self.load_component("security_schemes")
|
|
117
|
+
param = component["paths"]["/parameters"]["get"]["parameters"]
|
|
118
|
+
value["parameters"].extend(param)
|
|
119
|
+
return path, value
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
class ReplaceQueryIdPlaceholder(RequestHookBase):
|
|
123
|
+
def hook(self, path: str, value: dict):
|
|
124
|
+
path, value = super().hook(path, value)
|
|
125
|
+
new = self.PLACEHOLDER[self.path_name]["queryId"]
|
|
126
|
+
return path.replace(r"{{queryId}}", new), value
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
class SetResponsesHeader(RequestHookBase):
|
|
130
|
+
suffix: str
|
|
131
|
+
|
|
132
|
+
def __init__(self, suffix: str | None = None):
|
|
133
|
+
super().__init__()
|
|
134
|
+
self.suffix = "" if suffix is None else "_" + suffix
|
|
135
|
+
|
|
136
|
+
def hook(self, path: str, value: dict):
|
|
137
|
+
path, value = super().hook(path, value)
|
|
138
|
+
component = self.load_component("response_header" + self.suffix)
|
|
139
|
+
value["responses"]["200"]["headers"] = component["components"]["headers"]
|
|
140
|
+
return path, value
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
# OnParameters
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
class AddParametersOnParameters(RequestHookBase):
|
|
147
|
+
schemaType: str | None
|
|
148
|
+
|
|
149
|
+
def __init__(self, split: str = 1, schemaType: str | None = None):
|
|
150
|
+
super().__init__(split=split)
|
|
151
|
+
self.schemaType = schemaType
|
|
152
|
+
|
|
153
|
+
def hook(self, path: str, value: dict):
|
|
154
|
+
path, value = super().hook(path, value)
|
|
155
|
+
data = self.PLACEHOLDER[self.path_name]
|
|
156
|
+
for key in data.keys():
|
|
157
|
+
if self.schemaType == "string":
|
|
158
|
+
example = json.dumps(data[key])
|
|
159
|
+
schema = {
|
|
160
|
+
"type": "string",
|
|
161
|
+
"default": example,
|
|
162
|
+
"example": example,
|
|
163
|
+
}
|
|
164
|
+
elif self.schemaType == "object":
|
|
165
|
+
example = json.dumps(data[key])
|
|
166
|
+
schema = {
|
|
167
|
+
"type": "object",
|
|
168
|
+
"default": example,
|
|
169
|
+
"example": example,
|
|
170
|
+
}
|
|
171
|
+
else:
|
|
172
|
+
schema = self.placeholder_to_yaml(data[key])
|
|
173
|
+
value["parameters"].append(
|
|
174
|
+
{
|
|
175
|
+
"name": key,
|
|
176
|
+
"in": "query",
|
|
177
|
+
"required": True,
|
|
178
|
+
"schema": schema,
|
|
179
|
+
}
|
|
180
|
+
)
|
|
181
|
+
return path, value
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
# OnBody
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
class AddParametersOnBody(RequestHookBase):
|
|
188
|
+
schemaType: str | None
|
|
189
|
+
contentType: str | None
|
|
190
|
+
|
|
191
|
+
def __init__(
|
|
192
|
+
self,
|
|
193
|
+
split: str = 1,
|
|
194
|
+
contentType: str = "application/json",
|
|
195
|
+
schemaType: str | None = None,
|
|
196
|
+
):
|
|
197
|
+
super().__init__(split)
|
|
198
|
+
self.schemaType = schemaType
|
|
199
|
+
self.contentType = contentType
|
|
200
|
+
|
|
201
|
+
def hook(self, path: str, value: dict):
|
|
202
|
+
path, value = super().hook(path, value)
|
|
203
|
+
data = self.PLACEHOLDER[self.path_name]
|
|
204
|
+
|
|
205
|
+
if self.schemaType == "string":
|
|
206
|
+
example = json.dumps(data)
|
|
207
|
+
schema = {
|
|
208
|
+
"type": "string",
|
|
209
|
+
"default": example,
|
|
210
|
+
"example": example,
|
|
211
|
+
}
|
|
212
|
+
elif self.schemaType == "object":
|
|
213
|
+
example = json.dumps(data)
|
|
214
|
+
schema = {
|
|
215
|
+
"type": "object",
|
|
216
|
+
"default": example,
|
|
217
|
+
"example": example,
|
|
218
|
+
}
|
|
219
|
+
else:
|
|
220
|
+
schema = {
|
|
221
|
+
"properties": {
|
|
222
|
+
i: self.placeholder_to_yaml(data[i]) for i in data.keys()
|
|
223
|
+
},
|
|
224
|
+
"required": [i for i in data.keys()],
|
|
225
|
+
}
|
|
226
|
+
value["requestBody"] = {
|
|
227
|
+
"description": "body",
|
|
228
|
+
"required": True,
|
|
229
|
+
"content": {
|
|
230
|
+
self.contentType: {
|
|
231
|
+
"schema": schema,
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
}
|
|
235
|
+
return path, value
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
# OnContent
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
class AddParametersOnContent(RequestHookBase):
|
|
242
|
+
contentType: str
|
|
243
|
+
|
|
244
|
+
def __init__(self, split: str = 1, contentType: str = "application/json"):
|
|
245
|
+
super().__init__(split=split)
|
|
246
|
+
self.contentType = contentType
|
|
247
|
+
|
|
248
|
+
def hook(self, path: str, value: dict):
|
|
249
|
+
path, value = super().hook(path, value)
|
|
250
|
+
data = self.PLACEHOLDER[self.path_name]
|
|
251
|
+
for key in data.keys():
|
|
252
|
+
value["parameters"].append(
|
|
253
|
+
{
|
|
254
|
+
"name": key,
|
|
255
|
+
"in": "query",
|
|
256
|
+
"required": True,
|
|
257
|
+
"content": {
|
|
258
|
+
self.contentType: {
|
|
259
|
+
"schema": self.placeholder_to_yaml(data[key]),
|
|
260
|
+
"required": [i for i in data[key]],
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
}
|
|
264
|
+
)
|
|
265
|
+
return path, value
|