Skip to content

Commit

Permalink
Add API rate limiting to the OAS
Browse files Browse the repository at this point in the history
  • Loading branch information
szekelyzol authored Apr 11, 2024
1 parent 333a5a4 commit 89cbfdb
Show file tree
Hide file tree
Showing 8 changed files with 271 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
37 changes: 37 additions & 0 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions docs/TooManyRequests.md
Original file line number Diff line number Diff line change
@@ -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


2 changes: 2 additions & 0 deletions docs/VideosApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | - |

<a name="uploadWithUploadToken"></a>
# **uploadWithUploadToken**
Expand Down Expand Up @@ -212,4 +213,5 @@ No authorization required
|-------------|-------------|------------------|
**201** | Created | - |
**400** | Bad Request | - |
**429** | Too Many Requests | - |

56 changes: 56 additions & 0 deletions src/main/java/video/api/uploader/VideosApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -135,6 +136,11 @@ public void setApiClient(ApiClient apiClient) {
* <td>Not Found</td>
* <td>-</td>
* </tr>
* <tr>
* <td>429</td>
* <td>Too Many Requests</td>
* <td>-</td>
* </tr>
* </table>
*/
private okhttp3.Call uploadCall(String videoId, File file, final ApiCallback _callback) throws ApiException {
Expand Down Expand Up @@ -308,6 +314,11 @@ private okhttp3.Call uploadChunkValidateBeforeCall(String videoId, File file, lo
* <td>Not Found</td>
* <td>-</td>
* </tr>
* <tr>
* <td>429</td>
* <td>Too Many Requests</td>
* <td>-</td>
* </tr>
* </table>
*/
public Video upload(String videoId, File file) throws ApiException {
Expand Down Expand Up @@ -376,6 +387,11 @@ public Video upload(String videoId, File file) throws ApiException {
* <td>Not Found</td>
* <td>-</td>
* </tr>
* <tr>
* <td>429</td>
* <td>Too Many Requests</td>
* <td>-</td>
* </tr>
* </table>
*/
public Video upload(String videoId, File file, UploadProgressListener uploadProgressListener) throws ApiException {
Expand Down Expand Up @@ -442,6 +458,11 @@ public Video upload(String videoId, File file, UploadProgressListener uploadProg
* <td>Not Found</td>
* <td>-</td>
* </tr>
* <tr>
* <td>429</td>
* <td>Too Many Requests</td>
* <td>-</td>
* </tr>
* </table>
*/
public ApiResponse<Video> uploadWithHttpInfo(String videoId, File file) throws ApiException {
Expand Down Expand Up @@ -590,6 +611,11 @@ public UploadProgressiveSession createUploadProgressiveSession(String videoId) {
* <td>Not Found</td>
* <td>-</td>
* </tr>
* <tr>
* <td>429</td>
* <td>Too Many Requests</td>
* <td>-</td>
* </tr>
* </table>
*/
public ApiResponse<Video> uploadWithHttpInfo(String videoId, File file,
Expand Down Expand Up @@ -676,6 +702,11 @@ public void onDownloadProgress(long bytesRead, long contentLength, boolean done)
* <td>Bad Request</td>
* <td>-</td>
* </tr>
* <tr>
* <td>429</td>
* <td>Too Many Requests</td>
* <td>-</td>
* </tr>
* </table>
*/
private okhttp3.Call uploadWithUploadTokenCall(String token, File file, String videoId, final ApiCallback _callback)
Expand Down Expand Up @@ -840,6 +871,11 @@ private okhttp3.Call uploadWithUploadTokenChunkValidateBeforeCall(String token,
* <td>Bad Request</td>
* <td>-</td>
* </tr>
* <tr>
* <td>429</td>
* <td>Too Many Requests</td>
* <td>-</td>
* </tr>
* </table>
*/
public Video uploadWithUploadToken(String token, File file) throws ApiException {
Expand Down Expand Up @@ -883,6 +919,11 @@ public Video uploadWithUploadToken(String token, File file) throws ApiException
* <td>Bad Request</td>
* <td>-</td>
* </tr>
* <tr>
* <td>429</td>
* <td>Too Many Requests</td>
* <td>-</td>
* </tr>
* </table>
*/
public Video uploadWithUploadToken(String token, File file, String videoId,
Expand Down Expand Up @@ -928,6 +969,11 @@ public Video uploadWithUploadToken(String token, File file, String videoId,
* <td>Bad Request</td>
* <td>-</td>
* </tr>
* <tr>
* <td>429</td>
* <td>Too Many Requests</td>
* <td>-</td>
* </tr>
* </table>
*/
public Video uploadWithUploadToken(String token, File file, UploadProgressListener uploadProgressListener)
Expand Down Expand Up @@ -970,6 +1016,11 @@ public Video uploadWithUploadToken(String token, File file, UploadProgressListen
* <td>Bad Request</td>
* <td>-</td>
* </tr>
* <tr>
* <td>429</td>
* <td>Too Many Requests</td>
* <td>-</td>
* </tr>
* </table>
*/
public ApiResponse<Video> uploadWithUploadTokenWithHttpInfo(String token, File file) throws ApiException {
Expand Down Expand Up @@ -1106,6 +1157,11 @@ public UploadWithUploadTokenProgressiveSession createUploadWithUploadTokenProgre
* <td>Bad Request</td>
* <td>-</td>
* </tr>
* <tr>
* <td>429</td>
* <td>Too Many Requests</td>
* <td>-</td>
* </tr>
* </table>
*/
public ApiResponse<Video> uploadWithUploadTokenWithHttpInfo(String token, File file, String videoId,
Expand Down
147 changes: 147 additions & 0 deletions src/main/java/video/api/uploader/api/models/TooManyRequests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
* api.video Java API client
* api.video is an API that encodes on the go to facilitate immediate playback, enhancing viewer streaming experiences across multiple devices and platforms. You can stream live or on-demand online videos within minutes.
*
* The version of the OpenAPI document: 1
* Contact: [email protected]
*
* NOTE: This class is auto generated.
* Do not edit the class manually.
*/

package video.api.uploader.api.models;

import java.util.Objects;
import java.util.Arrays;
import com.google.gson.TypeAdapter;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.IOException;
import java.io.Serializable;

/**
* TooManyRequests
*/

public class TooManyRequests implements Serializable {
private static final long serialVersionUID = 1L;

public static final String SERIALIZED_NAME_TYPE = "type";
@SerializedName(SERIALIZED_NAME_TYPE)
private String type;

public static final String SERIALIZED_NAME_TITLE = "title";
@SerializedName(SERIALIZED_NAME_TITLE)
private String title;

public static final String SERIALIZED_NAME_STATUS = "status";
@SerializedName(SERIALIZED_NAME_STATUS)
private Integer status;

public TooManyRequests type(String type) {
this.type = type;
return this;
}

/**
* A link to the error documentation.
*
* @return type
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "A link to the error documentation.")

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public TooManyRequests title(String title) {
this.title = title;
return this;
}

/**
* A description of the error that occurred.
*
* @return title
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "A description of the error that occurred.")

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public TooManyRequests status(Integer status) {
this.status = status;
return this;
}

/**
* The HTTP status code.
*
* @return status
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "The HTTP status code.")

public Integer getStatus() {
return status;
}

public void setStatus(Integer status) {
this.status = status;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
TooManyRequests tooManyRequests = (TooManyRequests) o;
return Objects.equals(this.type, tooManyRequests.type) && Objects.equals(this.title, tooManyRequests.title)
&& Objects.equals(this.status, tooManyRequests.status);
}

@Override
public int hashCode() {
return Objects.hash(type, title, status);
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class TooManyRequests {\n");
sb.append(" type: ").append(toIndentedString(type)).append("\n");
sb.append(" title: ").append(toIndentedString(title)).append("\n");
sb.append(" status: ").append(toIndentedString(status)).append("\n");
sb.append("}");
return sb.toString();
}

/**
* Convert the given object to string with each line indented by 4 spaces (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}

}
5 changes: 5 additions & 0 deletions src/test/resources/payloads/videos/upload/responses/429.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type" : "https://docs.api.video/reference/too-many-requests",
"title" : "Too many requests.",
"status" : 429
}
Loading

0 comments on commit 89cbfdb

Please sign in to comment.