mirror of
https://github.com/thegeneralist01/twitter-openapi
synced 2026-01-11 15:40:26 +01:00
add useragent
Signed-off-by: ふぁ <yuki@yuki0311.com>
This commit is contained in:
parent
28e49c7ddb
commit
0bf572706a
6 changed files with 38 additions and 9 deletions
4
dist/compatible/openapi-3.0.yaml
vendored
4
dist/compatible/openapi-3.0.yaml
vendored
|
|
@ -3238,8 +3238,8 @@ components:
|
||||||
name: Sec-Fetch-Site
|
name: Sec-Fetch-Site
|
||||||
type: apiKey
|
type: apiKey
|
||||||
UserAgent:
|
UserAgent:
|
||||||
description: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,
|
description: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like
|
||||||
like Gecko) Chrome/123.0.0.0 Safari/537.36
|
Gecko) Chrome/129.0.0.0 Safari/537.36
|
||||||
in: header
|
in: header
|
||||||
name: user-agent
|
name: user-agent
|
||||||
type: apiKey
|
type: apiKey
|
||||||
|
|
|
||||||
|
|
@ -3238,8 +3238,8 @@ components:
|
||||||
name: Sec-Fetch-Site
|
name: Sec-Fetch-Site
|
||||||
type: apiKey
|
type: apiKey
|
||||||
UserAgent:
|
UserAgent:
|
||||||
description: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,
|
description: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like
|
||||||
like Gecko) Chrome/123.0.0.0 Safari/537.36
|
Gecko) Chrome/129.0.0.0 Safari/537.36
|
||||||
in: header
|
in: header
|
||||||
name: user-agent
|
name: user-agent
|
||||||
type: apiKey
|
type: apiKey
|
||||||
|
|
|
||||||
4
dist/docs/openapi-3.0.yaml
vendored
4
dist/docs/openapi-3.0.yaml
vendored
|
|
@ -3238,8 +3238,8 @@ components:
|
||||||
name: Sec-Fetch-Site
|
name: Sec-Fetch-Site
|
||||||
type: apiKey
|
type: apiKey
|
||||||
UserAgent:
|
UserAgent:
|
||||||
description: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,
|
description: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like
|
||||||
like Gecko) Chrome/123.0.0.0 Safari/537.36
|
Gecko) Chrome/129.0.0.0 Safari/537.36
|
||||||
in: header
|
in: header
|
||||||
name: user-agent
|
name: user-agent
|
||||||
type: apiKey
|
type: apiKey
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ paths:
|
||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
type: string
|
type: string
|
||||||
default: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"
|
default: "Not Implemented"
|
||||||
description: "UserAgent, some APIs may be rejected if changed."
|
description: "UserAgent, some APIs may be rejected if changed."
|
||||||
- name: authorization
|
- name: authorization
|
||||||
in: header
|
in: header
|
||||||
|
|
@ -135,7 +135,7 @@ paths:
|
||||||
components:
|
components:
|
||||||
securitySchemes:
|
securitySchemes:
|
||||||
UserAgent:
|
UserAgent:
|
||||||
description: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"
|
description: "Not Implemented"
|
||||||
in: header
|
in: header
|
||||||
name: user-agent
|
name: user-agent
|
||||||
type: apiKey
|
type: apiKey
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ from hooks import (
|
||||||
AddSecuritySchemesOnSecuritySchemes,
|
AddSecuritySchemesOnSecuritySchemes,
|
||||||
RemoveErrorHandle,
|
RemoveErrorHandle,
|
||||||
SetResponsesHeader,
|
SetResponsesHeader,
|
||||||
|
SetUserAgentOnSecuritySchemes,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -40,7 +41,10 @@ class Config:
|
||||||
additionalHooks.append(RemoveErrorHandle())
|
additionalHooks.append(RemoveErrorHandle())
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"openapi": [AddSecuritySchemesOnSecuritySchemes()],
|
"openapi": [
|
||||||
|
AddSecuritySchemesOnSecuritySchemes(),
|
||||||
|
SetUserAgentOnSecuritySchemes(),
|
||||||
|
],
|
||||||
"schemas": [],
|
"schemas": [],
|
||||||
"other": [],
|
"other": [],
|
||||||
"request": {
|
"request": {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
import urllib3
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -60,6 +61,13 @@ class HookBase:
|
||||||
with open("src/config/placeholder.json", mode="r", encoding="utf-8") as f:
|
with open("src/config/placeholder.json", mode="r", encoding="utf-8") as f:
|
||||||
return yaml.safe_load(f)
|
return yaml.safe_load(f)
|
||||||
|
|
||||||
|
def load_user_agent(self) -> str:
|
||||||
|
user_agent = urllib3.PoolManager().request(
|
||||||
|
"GET",
|
||||||
|
"https://raw.githubusercontent.com/fa0311/latest-user-agent/main/output.json",
|
||||||
|
)
|
||||||
|
return json.loads(user_agent.data)["chrome-fetch"]
|
||||||
|
|
||||||
|
|
||||||
# HookBase extends
|
# HookBase extends
|
||||||
|
|
||||||
|
|
@ -106,6 +114,14 @@ class AddSecuritySchemesOnSecuritySchemes(OpenapiHookBase):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
class SetUserAgentOnSecuritySchemes(OpenapiHookBase):
|
||||||
|
def hook(self, value: dict):
|
||||||
|
value = super().hook(value)
|
||||||
|
param = value["components"]["securitySchemes"]
|
||||||
|
param["UserAgent"]["description"] = self.load_user_agent()
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
# SchemasHookBase extends
|
# SchemasHookBase extends
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -151,6 +167,15 @@ class AddSecuritySchemesOnHeader(RequestHookBase):
|
||||||
return path, value
|
return path, value
|
||||||
|
|
||||||
|
|
||||||
|
class SetUserAgentOnHeader(RequestHookBase):
|
||||||
|
def hook(self, path: str, value: dict):
|
||||||
|
path, value = super().hook(path, value)
|
||||||
|
component = self.load_component("security_schemes")
|
||||||
|
param = component["paths"]["/parameters"]["get"]["parameters"]
|
||||||
|
value["parameters"].extend(param)
|
||||||
|
return path, value
|
||||||
|
|
||||||
|
|
||||||
class ReplaceQueryIdPlaceholder(RequestHookBase):
|
class ReplaceQueryIdPlaceholder(RequestHookBase):
|
||||||
def hook(self, path: str, value: dict):
|
def hook(self, path: str, value: dict):
|
||||||
path, value = super().hook(path, value)
|
path, value = super().hook(path, value)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue