diff --git a/dist/compatible/openapi-3.0.yaml b/dist/compatible/openapi-3.0.yaml index dfe8d9d..16cf4ee 100644 --- a/dist/compatible/openapi-3.0.yaml +++ b/dist/compatible/openapi-3.0.yaml @@ -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: diff --git a/dist/compatible_discriminator/openapi-3.0.yaml b/dist/compatible_discriminator/openapi-3.0.yaml index 3df951d..45a4738 100644 --- a/dist/compatible_discriminator/openapi-3.0.yaml +++ b/dist/compatible_discriminator/openapi-3.0.yaml @@ -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: diff --git a/dist/docs/openapi-3.0.yaml b/dist/docs/openapi-3.0.yaml index 1706bfb..672b3aa 100644 --- a/dist/docs/openapi-3.0.yaml +++ b/dist/docs/openapi-3.0.yaml @@ -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: diff --git a/other/error/GenericError.json b/other/error/GenericError.json new file mode 100644 index 0000000..1761afc --- /dev/null +++ b/other/error/GenericError.json @@ -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": {} +} diff --git a/src/openapi/response/error.yaml b/src/openapi/response/error.yaml index d285ce1..7006c7a 100644 --- a/src/openapi/response/error.yaml +++ b/src/openapi/response/error.yaml @@ -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}$" diff --git a/src/openapi/schemas/content.yaml b/src/openapi/schemas/content.yaml index e1b2a08..2338389 100644 --- a/src/openapi/schemas/content.yaml +++ b/src/openapi/schemas/content.yaml @@ -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" diff --git a/src/openapi/schemas/error.yaml b/src/openapi/schemas/error.yaml deleted file mode 100644 index 4deed22..0000000 --- a/src/openapi/schemas/error.yaml +++ /dev/null @@ -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}$" diff --git a/src/openapi/schemas/tweet.yaml b/src/openapi/schemas/tweet.yaml index ad88959..d3dfe30 100644 --- a/src/openapi/schemas/tweet.yaml +++ b/src/openapi/schemas/tweet.yaml @@ -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" diff --git a/test/python/test_serialize.py b/test/python/test_serialize.py index 78a78cf..62f5ca9 100644 --- a/test/python/test_serialize.py +++ b/test/python/test_serialize.py @@ -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),