1
Fork 0
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:
ふぁ 2024-09-29 19:01:46 +09:00
parent 28e49c7ddb
commit 0bf572706a
No known key found for this signature in database
GPG key ID: 83A8A5E74872A8AA
6 changed files with 38 additions and 9 deletions

View file

@ -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": {

View file

@ -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)