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
|
||||
type: apiKey
|
||||
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: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like
|
||||
Gecko) Chrome/129.0.0.0 Safari/537.36
|
||||
in: header
|
||||
name: user-agent
|
||||
type: apiKey
|
||||
|
|
|
|||
|
|
@ -3238,8 +3238,8 @@ components:
|
|||
name: Sec-Fetch-Site
|
||||
type: apiKey
|
||||
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: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like
|
||||
Gecko) Chrome/129.0.0.0 Safari/537.36
|
||||
in: header
|
||||
name: user-agent
|
||||
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
|
||||
type: apiKey
|
||||
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: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like
|
||||
Gecko) Chrome/129.0.0.0 Safari/537.36
|
||||
in: header
|
||||
name: user-agent
|
||||
type: apiKey
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ paths:
|
|||
required: true
|
||||
schema:
|
||||
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."
|
||||
- name: authorization
|
||||
in: header
|
||||
|
|
@ -135,7 +135,7 @@ paths:
|
|||
components:
|
||||
securitySchemes:
|
||||
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
|
||||
name: user-agent
|
||||
type: apiKey
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ from hooks import (
|
|||
AddSecuritySchemesOnSecuritySchemes,
|
||||
RemoveErrorHandle,
|
||||
SetResponsesHeader,
|
||||
SetUserAgentOnSecuritySchemes,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -40,7 +41,10 @@ class Config:
|
|||
additionalHooks.append(RemoveErrorHandle())
|
||||
|
||||
return {
|
||||
"openapi": [AddSecuritySchemesOnSecuritySchemes()],
|
||||
"openapi": [
|
||||
AddSecuritySchemesOnSecuritySchemes(),
|
||||
SetUserAgentOnSecuritySchemes(),
|
||||
],
|
||||
"schemas": [],
|
||||
"other": [],
|
||||
"request": {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import json
|
||||
|
||||
import urllib3
|
||||
import yaml
|
||||
|
||||
|
||||
|
|
@ -60,6 +61,13 @@ class HookBase:
|
|||
with open("src/config/placeholder.json", mode="r", encoding="utf-8") as 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
|
||||
|
||||
|
|
@ -106,6 +114,14 @@ class AddSecuritySchemesOnSecuritySchemes(OpenapiHookBase):
|
|||
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
|
||||
|
||||
|
||||
|
|
@ -151,6 +167,15 @@ class AddSecuritySchemesOnHeader(RequestHookBase):
|
|||
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):
|
||||
def hook(self, path: str, value: dict):
|
||||
path, value = super().hook(path, value)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue