1
Fork 0
mirror of https://github.com/thegeneralist01/twitter-openapi synced 2026-01-09 14:50:25 +01:00

fix error schema

Signed-off-by: ふぁ <yuki@yuki0311.com>
This commit is contained in:
ふぁ 2024-09-29 18:08:58 +09:00
parent 162ad96a13
commit 28e49c7ddb
No known key found for this signature in database
GPG key ID: 83A8A5E74872A8AA
9 changed files with 90 additions and 199 deletions

View file

@ -755,7 +755,6 @@ components:
- kind
- name
- source
- retry_after
- tracing
type: object
ErrorExtensions:
@ -775,19 +774,10 @@ components:
required:
- name
- source
- retry_after
- code
- kind
- tracing
type: object
ErrorResponse:
properties:
errors:
$ref: '#/components/schemas/Errors'
required:
- errors
- data
type: object
Errors:
properties:
errors:
@ -814,25 +804,6 @@ components:
type: array
required:
- media
Extensions:
properties:
code:
type: integer
kind:
type: string
name:
type: string
source:
type: string
tracing:
$ref: '#/components/schemas/Tracing'
required:
- name
- source
- code
- kind
- tracing
type: object
FavoriteTweet:
properties:
favorite_tweet:
@ -2482,17 +2453,25 @@ components:
properties:
__typename:
$ref: '#/components/schemas/TypeName'
TweetUnavailable:
properties:
__typename:
$ref: '#/components/schemas/TypeName'
reason:
type: string
TweetUnion:
discriminator:
mapping":
Tweet: '#/components/schemas/Tweet'
TweetTombstone: '#/components/schemas/TweetTombstone'
TweetUnavailable: '#/components/schemas/TweetUnavailable'
TweetWithVisibilityResults: '#/components/schemas/TweetWithVisibilityResults'
propertyName: __typename
oneOf:
- $ref: '#/components/schemas/Tweet'
- $ref: '#/components/schemas/TweetWithVisibilityResults'
- $ref: '#/components/schemas/TweetTombstone'
- $ref: '#/components/schemas/TweetUnavailable'
TweetView:
properties:
count:

View file

@ -755,7 +755,6 @@ components:
- kind
- name
- source
- retry_after
- tracing
type: object
ErrorExtensions:
@ -775,19 +774,10 @@ components:
required:
- name
- source
- retry_after
- code
- kind
- tracing
type: object
ErrorResponse:
properties:
errors:
$ref: '#/components/schemas/Errors'
required:
- errors
- data
type: object
Errors:
properties:
errors:
@ -814,25 +804,6 @@ components:
type: array
required:
- media
Extensions:
properties:
code:
type: integer
kind:
type: string
name:
type: string
source:
type: string
tracing:
$ref: '#/components/schemas/Tracing'
required:
- name
- source
- code
- kind
- tracing
type: object
FavoriteTweet:
properties:
favorite_tweet:
@ -2482,17 +2453,25 @@ components:
properties:
__typename:
$ref: '#/components/schemas/TypeName'
TweetUnavailable:
properties:
__typename:
$ref: '#/components/schemas/TypeName'
reason:
type: string
TweetUnion:
discriminator:
mapping":
Tweet: '#/components/schemas/Tweet'
TweetTombstone: '#/components/schemas/TweetTombstone'
TweetUnavailable: '#/components/schemas/TweetUnavailable'
TweetWithVisibilityResults: '#/components/schemas/TweetWithVisibilityResults'
propertyName: __typename
oneOf:
- $ref: '#/components/schemas/Tweet'
- $ref: '#/components/schemas/TweetWithVisibilityResults'
- $ref: '#/components/schemas/TweetTombstone'
- $ref: '#/components/schemas/TweetUnavailable'
TweetView:
properties:
count:

View file

@ -755,7 +755,6 @@ components:
- kind
- name
- source
- retry_after
- tracing
type: object
ErrorExtensions:
@ -775,19 +774,10 @@ components:
required:
- name
- source
- retry_after
- code
- kind
- tracing
type: object
ErrorResponse:
properties:
errors:
$ref: '#/components/schemas/Errors'
required:
- errors
- data
type: object
Errors:
properties:
errors:
@ -814,25 +804,6 @@ components:
type: array
required:
- media
Extensions:
properties:
code:
type: integer
kind:
type: string
name:
type: string
source:
type: string
tracing:
$ref: '#/components/schemas/Tracing'
required:
- name
- source
- code
- kind
- tracing
type: object
FavoriteTweet:
properties:
favorite_tweet:
@ -2482,17 +2453,25 @@ components:
properties:
__typename:
$ref: '#/components/schemas/TypeName'
TweetUnavailable:
properties:
__typename:
$ref: '#/components/schemas/TypeName'
reason:
type: string
TweetUnion:
discriminator:
mapping":
Tweet: '#/components/schemas/Tweet'
TweetTombstone: '#/components/schemas/TweetTombstone'
TweetUnavailable: '#/components/schemas/TweetUnavailable'
TweetWithVisibilityResults: '#/components/schemas/TweetWithVisibilityResults'
propertyName: __typename
oneOf:
- $ref: '#/components/schemas/Tweet'
- $ref: '#/components/schemas/TweetWithVisibilityResults'
- $ref: '#/components/schemas/TweetTombstone'
- $ref: '#/components/schemas/TweetUnavailable'
TweetView:
properties:
count:

View file

@ -0,0 +1,31 @@
{
"errors": [
{
"message": "_Missing: No status found with that ID.",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": ["threaded_conversation_with_injections_v2"],
"extensions": {
"name": "GenericError",
"source": "Server",
"code": 144,
"kind": "NonFatal",
"tracing": {
"trace_id": "e6de8b2b694ae128"
}
},
"code": 144,
"kind": "NonFatal",
"name": "GenericError",
"source": "Server",
"tracing": {
"trace_id": "e6de8b2b694ae128"
}
}
],
"data": {}
}

View file

@ -4,22 +4,17 @@ info:
version: 0.0.1
paths: {}
components:
schemas:
ErrorResponse:
Errors:
type: object
required:
- errors
- data
properties:
errors:
$ref: "#/components/schemas/Errors"
Errors:
type: array
items:
$ref: "#/components/schemas/Error"
type: array
items:
$ref: "#/components/schemas/Error"
Error:
type: object
@ -32,7 +27,6 @@ components:
- kind
- name
- source
- retry_after
- tracing
properties:
message:
@ -46,7 +40,7 @@ components:
items:
type: string
extensions:
$ref: "#/components/schemas/Extensions"
$ref: "#/components/schemas/ErrorExtensions"
code:
type: integer
kind:
@ -71,7 +65,7 @@ components:
column:
type: integer
Extensions:
ErrorExtensions:
type: object
required:
- name
@ -84,6 +78,8 @@ components:
type: string
source:
type: string
retry_after:
type: integer
code:
type: integer
kind:
@ -98,3 +94,4 @@ components:
properties:
trace_id:
type: string
pattern: "^[0-9a-f]{16}$"

View file

@ -230,7 +230,7 @@ components:
ItemResult:
properties:
__typename:
$ref: "./typename.yaml#/components/schemas/TypeName" # null | TimelineTweet
$ref: "./typename.yaml#/components/schemas/TypeName" # null | TimelineTweet | TweetUnavailable
result:
$ref: "./tweet.yaml#/components/schemas/TweetUnion"

View file

@ -1,99 +0,0 @@
openapi: 3.0.3
info:
title: Twitter OpenAPI
version: 0.0.1
paths: {}
components:
schemas:
Errors:
type: object
required:
- errors
properties:
errors:
type: array
items:
$ref: "#/components/schemas/Error"
Error:
type: object
required:
- message
- locations
- path
- extensions
- code
- kind
- name
- source
- retry_after
- tracing
properties:
message:
type: string
locations:
type: array
items:
$ref: "#/components/schemas/Location"
path:
type: array
items:
type: string
extensions:
$ref: "#/components/schemas/ErrorExtensions"
code:
type: integer
kind:
type: string
name:
type: string
source:
type: string
retry_after:
type: integer
tracing:
$ref: "#/components/schemas/Tracing"
Location:
type: object
required:
- line
- column
properties:
line:
type: integer
column:
type: integer
ErrorExtensions:
type: object
required:
- name
- source
- retry_after
- code
- kind
- tracing
properties:
name:
type: string
source:
type: string
retry_after:
type: integer
code:
type: integer
kind:
type: string
tracing:
$ref: "#/components/schemas/Tracing"
Tracing:
type: object
required:
- trace_id
properties:
trace_id:
type: string
pattern: "^[0-9a-f]{16}$"

View file

@ -12,12 +12,14 @@ components:
- $ref: "#/components/schemas/Tweet"
- $ref: "#/components/schemas/TweetWithVisibilityResults"
- $ref: "#/components/schemas/TweetTombstone"
- $ref: "#/components/schemas/TweetUnavailable"
discriminator:
propertyName: __typename
mapping": # deprecated
Tweet: "#/components/schemas/Tweet"
TweetWithVisibilityResults: "#/components/schemas/TweetWithVisibilityResults"
TweetTombstone: "#/components/schemas/TweetTombstone"
TweetUnavailable: "#/components/schemas/TweetUnavailable"
TweetWithVisibilityResults:
required:
@ -138,6 +140,13 @@ components:
$ref: "./typename.yaml#/components/schemas/TypeName" # TweetWithVisibilityResults
additionalProperties: true # todo
TweetUnavailable: # nsfw tweet
properties:
__typename:
$ref: "./typename.yaml#/components/schemas/TypeName" # TweetUnavailable
reason:
type: string
Tweet:
required:
- "rest_id"

View file

@ -211,6 +211,15 @@ if __name__ == "__main__":
task_callback(file, thread=False)
logger.info(f"Match rate: {rate}")
for file in glob.glob("other/**/*.json", recursive=True):
with open(file, "r") as f:
data = json.load(f)
try:
_ = pt.Errors.from_dict(data)
except Exception as e:
error_dump(e)
api_conf = pt.Configuration(
api_key={
"ClientLanguage": "en",
@ -345,6 +354,13 @@ if __name__ == "__main__":
res = pt.TweetApi(api_client).get_tweet_detail_with_http_info(**kwargs)
data = res.data.to_dict()
save_cache(
{
"raw": res.raw_data.decode("utf-8"),
"type": res.data.__class__.__name__,
}
)
rate = match_rate(
data,
json.loads(res.raw_data),