diff --git a/.github/workflows/test-build.yaml b/.github/workflows/test-build.yaml index d74973e..2eb23f5 100644 --- a/.github/workflows/test-build.yaml +++ b/.github/workflows/test-build.yaml @@ -39,7 +39,7 @@ jobs: - name: Get Openapi Generator run: | - wget https://github.com/fa0311/openapi-generator/releases/download/twitter_openapi_python_1.2.0/openapi-generator-cli.jar -O openapi-generator-cli.jar --no-verbose + wget https://github.com/fa0311/openapi-generator/releases/download/twitter_openapi_python_1.3.0/openapi-generator-cli.jar -O openapi-generator-cli.jar --no-verbose if: steps.openapi-generator-cache.outputs.cache-hit != 'true' # Python Setup diff --git a/.github/workflows/test-python.yaml b/.github/workflows/test-python.yaml index 442e7eb..815a532 100644 --- a/.github/workflows/test-python.yaml +++ b/.github/workflows/test-python.yaml @@ -3,6 +3,7 @@ name: test-python on: pull_request_target: types: [labeled] + workflow_dispatch: jobs: build_and_preview: @@ -12,6 +13,8 @@ jobs: steps: - uses: actions/checkout@v3 + with: + ref: "${{ github.event.pull_request.merge_commit_sha }}" # Openapi Generator Setup - name: Get OpenJDK 11 @@ -37,7 +40,7 @@ jobs: - name: Get Openapi Generator run: | - wget https://github.com/fa0311/openapi-generator/releases/download/twitter_openapi_python_1.2.0/openapi-generator-cli.jar -O openapi-generator-cli.jar --no-verbose + wget https://github.com/fa0311/openapi-generator/releases/download/twitter_openapi_python_1.3.0/openapi-generator-cli.jar -O openapi-generator-cli.jar --no-verbose if: steps.openapi-generator-cache.outputs.cache-hit != 'true' # Python Setup diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 3e8680f..1ffce76 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -33,14 +33,14 @@ "command": [ "python3 -m venv .venv;", ".venv/bin/python3 -m pip install -r requirements.txt;", - "wget https://github.com/fa0311/openapi-generator/releases/download/twitter_openapi_python_1.2.0/openapi-generator-cli.jar -O openapi-generator-cli.jar;" + "wget https://github.com/fa0311/openapi-generator/releases/download/twitter_openapi_python_1.3.0/openapi-generator-cli.jar -O openapi-generator-cli.jar;" ] }, "windows": { "command": [ "python -m venv .venv;", ".venv/Scripts/python -m pip install -r requirements.txt;", - "Invoke-WebRequest https://github.com/fa0311/openapi-generator/releases/download/twitter_openapi_python_1.2.0/openapi-generator-cli.jar -OutFile openapi-generator-cli.jar;" + "Invoke-WebRequest https://github.com/fa0311/openapi-generator/releases/download/twitter_openapi_python_1.3.0/openapi-generator-cli.jar -OutFile openapi-generator-cli.jar;" ] } } diff --git a/README.md b/README.md index 4735cf0..6e49199 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ Twitter OpenAPI(Swagger) specification +- [Python](https://github.com/fa0311/twitter_openapi_python) - [Dart](https://github.com/fa0311/twitter_openapi_dart) - [TypeScript](https://github.com/fa0311/twitter-openapi-typescript) - [React Documents](https://github.com/fa0311/twitter-openapi-docs) diff --git a/dist/compatible/openapi-3.0.yaml b/dist/compatible/openapi-3.0.yaml index b109e03..9e460d8 100644 --- a/dist/compatible/openapi-3.0.yaml +++ b/dist/compatible/openapi-3.0.yaml @@ -137,11 +137,13 @@ security: servers: - url: https://twitter.com/i/api tags: -- description: response User +- description: Responses containing User objects. name: user -- description: response User list +- description: Responses containing List[User] objects. + name: users +- description: Responses containing instruction objects. name: user-list -- description: response tweet +- description: Responses containing instruction objects. name: tweet - description: post name: post diff --git a/dist/compatible/paths/other.yaml b/dist/compatible/paths/other.yaml index 02729a8..1f8cae6 100644 --- a/dist/compatible/paths/other.yaml +++ b/dist/compatible/paths/other.yaml @@ -94,7 +94,6 @@ paths: schema: oneOf: - $ref: '#/components/schemas/OtherResponse' - - $ref: ./../schemas/error.yaml#/components/schemas/Errors description: Successful operation tags: - other diff --git a/dist/compatible/paths/user.yaml b/dist/compatible/paths/user.yaml index 7226106..e7720ea 100644 --- a/dist/compatible/paths/user.yaml +++ b/dist/compatible/paths/user.yaml @@ -230,4 +230,4 @@ paths: schema: type: string tags: - - user + - users diff --git a/dist/compatible/schemas/typename.yaml b/dist/compatible/schemas/typename.yaml index 5262109..603a683 100644 --- a/dist/compatible/schemas/typename.yaml +++ b/dist/compatible/schemas/typename.yaml @@ -14,6 +14,7 @@ components: - TweetUnavailable - Tweet - User + - UserUnavailable type: string info: title: Twitter OpenAPI diff --git a/dist/compatible/schemas/user.yaml b/dist/compatible/schemas/user.yaml index b60ab45..61409b7 100644 --- a/dist/compatible/schemas/user.yaml +++ b/dist/compatible/schemas/user.yaml @@ -165,10 +165,7 @@ components: - entities - fast_followers_count - favourites_count - - follow_request_sent - - followed_by - followers_count - - following - friends_count - has_custom_timelines - is_translator @@ -178,12 +175,10 @@ components: - muting - name - normal_followers_count - - notifications - pinned_tweet_ids_str - possibly_sensitive - profile_image_url_https - profile_interstitial_type - - protected - screen_name - status - statuses_count @@ -199,9 +194,27 @@ components: UserResults: properties: result: - $ref: '#/components/schemas/User' + $ref: '#/components/schemas/UserUnion' required: - result + UserUnavailable: + properties: + __typename: + $ref: ./typename.yaml#/components/schemas/TypeName + reason: + type: string + required: + - __typename + - reason + UserUnion: + discriminator: + mapping": + User: '#/components/schemas/User' + UserUnavailable: '#/components/schemas/UserUnavailable' + propertyName: __typename + oneOf: + - $ref: '#/components/schemas/User' + - $ref: '#/components/schemas/UserUnavailable' info: title: Twitter OpenAPI version: 0.0.1 diff --git a/dist/docs/openapi-3.0.yaml b/dist/docs/openapi-3.0.yaml index b109e03..9e460d8 100644 --- a/dist/docs/openapi-3.0.yaml +++ b/dist/docs/openapi-3.0.yaml @@ -137,11 +137,13 @@ security: servers: - url: https://twitter.com/i/api tags: -- description: response User +- description: Responses containing User objects. name: user -- description: response User list +- description: Responses containing List[User] objects. + name: users +- description: Responses containing instruction objects. name: user-list -- description: response tweet +- description: Responses containing instruction objects. name: tweet - description: post name: post diff --git a/dist/docs/paths/other.yaml b/dist/docs/paths/other.yaml index 02729a8..1f8cae6 100644 --- a/dist/docs/paths/other.yaml +++ b/dist/docs/paths/other.yaml @@ -94,7 +94,6 @@ paths: schema: oneOf: - $ref: '#/components/schemas/OtherResponse' - - $ref: ./../schemas/error.yaml#/components/schemas/Errors description: Successful operation tags: - other diff --git a/dist/docs/paths/user.yaml b/dist/docs/paths/user.yaml index cb999a3..46d3227 100644 --- a/dist/docs/paths/user.yaml +++ b/dist/docs/paths/user.yaml @@ -335,4 +335,4 @@ paths: schema: type: string tags: - - user + - users diff --git a/dist/docs/schemas/typename.yaml b/dist/docs/schemas/typename.yaml index 5262109..603a683 100644 --- a/dist/docs/schemas/typename.yaml +++ b/dist/docs/schemas/typename.yaml @@ -14,6 +14,7 @@ components: - TweetUnavailable - Tweet - User + - UserUnavailable type: string info: title: Twitter OpenAPI diff --git a/dist/docs/schemas/user.yaml b/dist/docs/schemas/user.yaml index b60ab45..61409b7 100644 --- a/dist/docs/schemas/user.yaml +++ b/dist/docs/schemas/user.yaml @@ -165,10 +165,7 @@ components: - entities - fast_followers_count - favourites_count - - follow_request_sent - - followed_by - followers_count - - following - friends_count - has_custom_timelines - is_translator @@ -178,12 +175,10 @@ components: - muting - name - normal_followers_count - - notifications - pinned_tweet_ids_str - possibly_sensitive - profile_image_url_https - profile_interstitial_type - - protected - screen_name - status - statuses_count @@ -199,9 +194,27 @@ components: UserResults: properties: result: - $ref: '#/components/schemas/User' + $ref: '#/components/schemas/UserUnion' required: - result + UserUnavailable: + properties: + __typename: + $ref: ./typename.yaml#/components/schemas/TypeName + reason: + type: string + required: + - __typename + - reason + UserUnion: + discriminator: + mapping": + User: '#/components/schemas/User' + UserUnavailable: '#/components/schemas/UserUnavailable' + propertyName: __typename + oneOf: + - $ref: '#/components/schemas/User' + - $ref: '#/components/schemas/UserUnavailable' info: title: Twitter OpenAPI version: 0.0.1 diff --git a/src/openapi/openapi-3.0.yaml b/src/openapi/openapi-3.0.yaml index 4f58931..5104625 100644 --- a/src/openapi/openapi-3.0.yaml +++ b/src/openapi/openapi-3.0.yaml @@ -56,11 +56,13 @@ security: - AuthType: [] tags: - name: user - description: response User + description: Responses containing User objects. + - name: users + description: Responses containing List[User] objects. - name: user-list - description: response User list + description: Responses containing instruction objects. - name: tweet - description: response tweet + description: Responses containing instruction objects. - name: post description: post - name: v1.1-get diff --git a/src/openapi/paths/other.yaml b/src/openapi/paths/other.yaml index de47a86..7bab3ec 100644 --- a/src/openapi/paths/other.yaml +++ b/src/openapi/paths/other.yaml @@ -16,7 +16,6 @@ paths: schema: oneOf: - $ref: "#/components/schemas/OtherResponse" - - $ref: "./../schemas/error.yaml#/components/schemas/Errors" tags: - "other" diff --git a/src/openapi/paths/user.yaml b/src/openapi/paths/user.yaml index d12620d..a8c8755 100644 --- a/src/openapi/paths/user.yaml +++ b/src/openapi/paths/user.yaml @@ -50,7 +50,7 @@ paths: - $ref: "#/components/schemas/UsersResponse" - $ref: "./../schemas/error.yaml#/components/schemas/Errors" tags: - - "user" + - "users" components: schemas: diff --git a/src/openapi/schemas/typename.yaml b/src/openapi/schemas/typename.yaml index 19c79bb..85fd323 100644 --- a/src/openapi/schemas/typename.yaml +++ b/src/openapi/schemas/typename.yaml @@ -21,4 +21,5 @@ components: TweetUnavailable, Tweet, User, + UserUnavailable, ] diff --git a/src/openapi/schemas/user.yaml b/src/openapi/schemas/user.yaml index 1349108..9a94fab 100644 --- a/src/openapi/schemas/user.yaml +++ b/src/openapi/schemas/user.yaml @@ -17,7 +17,17 @@ components: - "result" properties: result: - $ref: "#/components/schemas/User" + $ref: "#/components/schemas/UserUnion" + + UserUnion: + oneOf: + - $ref: "#/components/schemas/User" + - $ref: "#/components/schemas/UserUnavailable" + discriminator: + propertyName: __typename + mapping": # deprecated + User: "#/components/schemas/User" + UserUnavailable: "#/components/schemas/UserUnavailable" User: required: @@ -79,10 +89,10 @@ components: - "entities" - "fast_followers_count" - "favourites_count" - - "follow_request_sent" - - "followed_by" + # 31 # - "follow_request_sent" + # 31 # - "followed_by" - "followers_count" - - "following" + # 31 # - "following" - "friends_count" - "has_custom_timelines" - "is_translator" @@ -92,12 +102,12 @@ components: - "muting" - "name" - "normal_followers_count" - - "notifications" + # 31 # - "notifications" - "pinned_tweet_ids_str" - "possibly_sensitive" - "profile_image_url_https" - "profile_interstitial_type" - - "protected" + # 31 # - "protected" - "screen_name" - "status" - "statuses_count" @@ -211,3 +221,13 @@ components: want_retweets: type: boolean default: false + + UserUnavailable: + required: + - "__typename" + - "reason" + properties: + __typename: + $ref: "./typename.yaml#/components/schemas/TypeName" # UserUnavailable + reason: + type: string diff --git a/test/python/test_serialize.py b/test/python/test_serialize.py index 8839a56..2eb9982 100644 --- a/test/python/test_serialize.py +++ b/test/python/test_serialize.py @@ -131,6 +131,17 @@ for file in glob.glob("cache/*.json"): logger.info(f"Success: {len(glob.glob('cache/*.json'))}") +def error_dump(e): + if ERROR_UNCATCHED: + raise + import traceback + + logger.error("==========[STACK TRACE]==========") + for trace in traceback.format_exc().split("\n"): + logger.error(trace) + logger.info("================================") + + api_conf = pt.Configuration( api_key={ "ClientLanguage": "en", @@ -147,7 +158,7 @@ api_client.user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/5 error_count = 0 -for x in [pt.DefaultApi, pt.TweetApi, pt.UserApi, pt.UserListApi]: +for x in [pt.DefaultApi, pt.TweetApi, pt.UserApi, pt.UsersApi, pt.UserListApi]: for props, fn in x.__dict__.items(): if not callable(fn): continue @@ -185,15 +196,27 @@ for x in [pt.DefaultApi, pt.TweetApi, pt.UserApi, pt.UserListApi]: time.sleep(SLEEP_TIME) except Exception as e: - if ERROR_UNCATCHED: - raise - import traceback - - logger.error("==========[STACK TRACE]==========") - for trace in traceback.format_exc().split("\n"): - logger.error(trace) - logger.info("================================") + error_dump(e) error_count += 1 + +try: + logger.info(f"Try: Self UserByScreenName Test") + kwargs = get_kwargs("UserByScreenName", {"screen_name": "a810810931931"}) + res = pt.UserApi(api_client).get_user_by_screen_name(**kwargs).to_dict() + if not res["data"]["user"]["result"]["legacy"]["screen_name"] == "a810810931931": + raise Exception("UserByScreenName failed") +except Exception as e: + error_dump(e) + error_count += 1 + +try: + logger.info(f"Try: Self UserTweets Test") + kwargs = get_kwargs("UserTweets", {"userId": "1180389371481976833"}) + pt.TweetApi(api_client).get_user_tweets(**kwargs) +except Exception as e: + error_dump(e) + error_count += 1 + if error_count > 0: exit(1) diff --git a/tools/build_config.py b/tools/build_config.py index 5f771ad..7f053ac 100644 --- a/tools/build_config.py +++ b/tools/build_config.py @@ -39,7 +39,7 @@ class Config: AddPathQueryIdOnParameters(split=-1), getParamHook, ] - for key in ["default", "user", "user-list", "tweet"] + for key in ["default", "user", "users", "user-list", "tweet"] } | { key: [ diff --git a/tools/hooks.py b/tools/hooks.py index 2e35c27..4546554 100644 --- a/tools/hooks.py +++ b/tools/hooks.py @@ -118,6 +118,20 @@ class SchemasCheck(SchemasHookBase): return value +class RequiredCheck(SchemasHookBase): + def hook(self, value: dict): + required = value.get("required", []) + + for key, property in value.get("properties", {}).items(): + if key in required and property.get("default") is not None: + print(f"{key} is required and has default value") + d = property.get("default") is None and property.get("nullable", False) + if property not in required and d: + print(f"{key} is not required and has no default value") + + return value + + # RequestHookBase extends