From 89cbfdbfc8ac27ee60d61c70a34fd339777b4a78 Mon Sep 17 00:00:00 2001 From: szekelyzol Date: Thu, 11 Apr 2024 09:37:01 +0000 Subject: [PATCH] Add API rate limiting to the OAS --- README.md | 1 + api/openapi.yaml | 37 +++++ docs/TooManyRequests.md | 18 +++ docs/VideosApi.md | 2 + .../java/video/api/uploader/VideosApi.java | 56 +++++++ .../uploader/api/models/TooManyRequests.java | 147 ++++++++++++++++++ .../payloads/videos/upload/responses/429.json | 5 + .../uploadWithUploadToken/responses/429.json | 5 + 8 files changed, 271 insertions(+) create mode 100644 docs/TooManyRequests.md create mode 100644 src/main/java/video/api/uploader/api/models/TooManyRequests.java create mode 100644 src/test/resources/payloads/videos/upload/responses/429.json create mode 100644 src/test/resources/payloads/videos/uploadWithUploadToken/responses/429.json diff --git a/README.md b/README.md index a3d2ac2..50f0853 100644 --- a/README.md +++ b/README.md @@ -209,6 +209,7 @@ Method | HTTP request | Description - [Metadata](https://github.com/apivideo/api.video-android-uploader/blob/main/docs/Metadata.md) - [NotFound](https://github.com/apivideo/api.video-android-uploader/blob/main/docs/NotFound.md) - [RefreshTokenPayload](https://github.com/apivideo/api.video-android-uploader/blob/main/docs/RefreshTokenPayload.md) + - [TooManyRequests](https://github.com/apivideo/api.video-android-uploader/blob/main/docs/TooManyRequests.md) - [Video](https://github.com/apivideo/api.video-android-uploader/blob/main/docs/Video.md) - [VideoAssets](https://github.com/apivideo/api.video-android-uploader/blob/main/docs/VideoAssets.md) - [VideoSource](https://github.com/apivideo/api.video-android-uploader/blob/main/docs/VideoSource.md) diff --git a/api/openapi.yaml b/api/openapi.yaml index 1f577a6..edd7ea2 100644 --- a/api/openapi.yaml +++ b/api/openapi.yaml @@ -272,6 +272,18 @@ paths: schema: $ref: '#/components/schemas/not-found' description: Not Found + "429": + content: + application/json: + examples: + response: + value: + type: https://docs.api.video/reference/too-many-requests + title: Too many requests. + status: 429 + schema: + $ref: '#/components/schemas/too-many-requests' + description: Too Many Requests security: - apiKey: [] summary: Upload a video @@ -545,6 +557,18 @@ paths: schema: $ref: '#/components/schemas/bad-request' description: Bad Request + "429": + content: + application/json: + examples: + response: + value: + type: https://docs.api.video/reference/too-many-requests + title: Too many requests. + status: 429 + schema: + $ref: '#/components/schemas/too-many-requests' + description: Too Many Requests security: [] summary: Upload with an delegated upload token tags: @@ -743,6 +767,19 @@ components: type: integer title: NotFound type: object + too-many-requests: + properties: + type: + description: A link to the error documentation. + type: string + title: + description: A description of the error that occurred. + type: string + status: + description: The HTTP status code. + type: integer + title: TooManyRequests + type: object video: example: videoId: vi4k0jvEUuaTdRAEjQ4Jfrgz diff --git a/docs/TooManyRequests.md b/docs/TooManyRequests.md new file mode 100644 index 0000000..643afd9 --- /dev/null +++ b/docs/TooManyRequests.md @@ -0,0 +1,18 @@ + + +# TooManyRequests + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**type** | **String** | A link to the error documentation. | [optional] +**title** | **String** | A description of the error that occurred. | [optional] +**status** | **Integer** | The HTTP status code. | [optional] + + +## Implemented Interfaces + +* Serializable + + diff --git a/docs/VideosApi.md b/docs/VideosApi.md index 4beaf18..d74db61 100644 --- a/docs/VideosApi.md +++ b/docs/VideosApi.md @@ -119,6 +119,7 @@ Video result = session.uploadLastPart(new File("sample.mp4.partn")); **201** | Created | - | **400** | Bad Request | - | **404** | Not Found | - | +**429** | Too Many Requests | - | # **uploadWithUploadToken** @@ -212,4 +213,5 @@ No authorization required |-------------|-------------|------------------| **201** | Created | - | **400** | Bad Request | - | +**429** | Too Many Requests | - | diff --git a/src/main/java/video/api/uploader/VideosApi.java b/src/main/java/video/api/uploader/VideosApi.java index a1654ea..0151d97 100644 --- a/src/main/java/video/api/uploader/VideosApi.java +++ b/src/main/java/video/api/uploader/VideosApi.java @@ -18,6 +18,7 @@ import video.api.uploader.api.models.BadRequest; import java.io.File; import video.api.uploader.api.models.NotFound; +import video.api.uploader.api.models.TooManyRequests; import video.api.uploader.api.models.Video; import java.lang.reflect.Type; @@ -135,6 +136,11 @@ public void setApiClient(ApiClient apiClient) { * Not Found * - * + * + * 429 + * Too Many Requests + * - + * * */ private okhttp3.Call uploadCall(String videoId, File file, final ApiCallback _callback) throws ApiException { @@ -308,6 +314,11 @@ private okhttp3.Call uploadChunkValidateBeforeCall(String videoId, File file, lo * Not Found * - * + * + * 429 + * Too Many Requests + * - + * * */ public Video upload(String videoId, File file) throws ApiException { @@ -376,6 +387,11 @@ public Video upload(String videoId, File file) throws ApiException { * Not Found * - * + * + * 429 + * Too Many Requests + * - + * * */ public Video upload(String videoId, File file, UploadProgressListener uploadProgressListener) throws ApiException { @@ -442,6 +458,11 @@ public Video upload(String videoId, File file, UploadProgressListener uploadProg * Not Found * - * + * + * 429 + * Too Many Requests + * - + * * */ public ApiResponse