From 4683361bbc300a119eb0202a7f25dc04f166c36a Mon Sep 17 00:00:00 2001 From: William Volin Date: Sun, 10 Nov 2024 16:30:04 -0700 Subject: [PATCH] update lib api types (#649) * update lib api types * fix: fix warning from data contract * fix: inline type on RequestParams --- lib/api/Account.ts | 2 +- lib/api/AccountRoute.ts | 2 +- lib/api/Leaderboards.ts | 98 +++++++++++++++++++++++++++++++++--- lib/api/LeaderboardsRoute.ts | 93 +++++++++++++++++++++++++++++++--- lib/api/data-contracts.ts | 22 ++++++-- 5 files changed, 197 insertions(+), 20 deletions(-) diff --git a/lib/api/Account.ts b/lib/api/Account.ts index 0a80f274..f5ec6ceb 100644 --- a/lib/api/Account.ts +++ b/lib/api/Account.ts @@ -64,7 +64,7 @@ export class Account< * @response `401` `void` The password given was incorrect. * @response `403` `void` The associated `User` is banned. * @response `404` `void` No `User` with the requested details could be found. - * @response `422` `ValidationProblemDetails` The request contains errors. Validation error codes by property: - **Password**: - **NotEmptyValidator**: No password was passed - **PasswordFormat**: Invalid password format - **Email**: - **NotNullValidator**: No email was passed - **EmailValidator**: Invalid email format + * @response `422` `ValidationProblemDetails` The request contains errors. Validation error codes by property: - **Password**: - **NotEmptyValidator**: No password was passed - **PasswordFormat**: Invalid password format - **Email**: - **NotEmptyValidator**: No email was passed - **EmailValidator**: Invalid email format * @response `500` `void` Internal Server Error */ login = (data: LoginRequest, params: RequestParams = {}) => diff --git a/lib/api/AccountRoute.ts b/lib/api/AccountRoute.ts index 6443c87b..4dce8c44 100644 --- a/lib/api/AccountRoute.ts +++ b/lib/api/AccountRoute.ts @@ -52,7 +52,7 @@ export namespace Account { * @response `401` `void` The password given was incorrect. * @response `403` `void` The associated `User` is banned. * @response `404` `void` No `User` with the requested details could be found. - * @response `422` `ValidationProblemDetails` The request contains errors. Validation error codes by property: - **Password**: - **NotEmptyValidator**: No password was passed - **PasswordFormat**: Invalid password format - **Email**: - **NotNullValidator**: No email was passed - **EmailValidator**: Invalid email format + * @response `422` `ValidationProblemDetails` The request contains errors. Validation error codes by property: - **Password**: - **NotEmptyValidator**: No password was passed - **PasswordFormat**: Invalid password format - **Email**: - **NotEmptyValidator**: No email was passed - **EmailValidator**: Invalid email format * @response `500` `void` Internal Server Error */ export namespace Login { diff --git a/lib/api/Leaderboards.ts b/lib/api/Leaderboards.ts index a6874cfc..5d559ae4 100644 --- a/lib/api/Leaderboards.ts +++ b/lib/api/Leaderboards.ts @@ -12,9 +12,10 @@ import type { CreateLeaderboardRequest, GetLeaderboardBySlugParams, - GetLeaderboardsParams, LeaderboardViewModel, + ListLeaderboardsParams, ProblemDetails, + UpdateLeaderboardRequest, ValidationProblemDetails, } from './data-contracts' import { ContentType, HttpClient, type RequestParams } from './http-client' @@ -48,7 +49,7 @@ export class Leaderboards< * * @tags Leaderboards * @name GetLeaderboardBySlug - * @summary Gets a Leaderboard by its slug. + * @summary Gets a leaderboard by its slug. * @request GET:/api/leaderboard * @secure * @response `200` `LeaderboardViewModel` OK @@ -72,16 +73,16 @@ export class Leaderboards< * No description * * @tags Leaderboards - * @name GetLeaderboards - * @summary Gets leaderboards by their IDs. + * @name ListLeaderboards + * @summary Gets all leaderboards. * @request GET:/api/leaderboards * @secure * @response `200` `(LeaderboardViewModel)[]` OK * @response `400` `ProblemDetails` Bad Request * @response `500` `void` Internal Server Error */ - getLeaderboards = ( - query: GetLeaderboardsParams, + listLeaderboards = ( + query: ListLeaderboardsParams, params: RequestParams = {}, ) => this.request({ @@ -104,7 +105,8 @@ export class Leaderboards< * @response `400` `ProblemDetails` Bad Request * @response `401` `void` Unauthorized * @response `403` `void` The requesting `User` is unauthorized to create `Leaderboard`s. - * @response `422` `ValidationProblemDetails` Unprocessable Content + * @response `409` `ValidationProblemDetails` A Leaderboard with the specified slug already exists. + * @response `422` `ValidationProblemDetails` The request contains errors. The following errors can occur: NotEmptyValidator, SlugFormat * @response `500` `void` Internal Server Error */ createLeaderboard = ( @@ -123,4 +125,86 @@ export class Leaderboards< format: 'json', ...params, }) + /** + * No description + * + * @tags Leaderboards + * @name RestoreLeaderboard + * @summary Restores a deleted leaderboard. + * @request PUT:/leaderboard/{id}/restore + * @secure + * @response `200` `LeaderboardViewModel` The restored `Leaderboard`s view model. + * @response `400` `ProblemDetails` Bad Request + * @response `401` `void` Unauthorized + * @response `403` `void` The requesting `User` is unauthorized to restore `Leaderboard`s. + * @response `404` `ProblemDetails` The `Leaderboard` was not found, or it wasn't deleted in the first place. Includes a field, `title`, which will be "Not Found" in the former case, and "Not Deleted" in the latter. + * @response `409` `LeaderboardViewModel` Another `Leaderboard` with the same slug has been created since, and therefore can't be restored. Will include the conflicting board in the response. + * @response `500` `void` Internal Server Error + */ + restoreLeaderboard = (id: number, params: RequestParams = {}) => + this.request< + LeaderboardViewModel, + ProblemDetails | void | LeaderboardViewModel + >({ + path: `/leaderboard/${id}/restore`, + method: 'PUT', + secure: true, + format: 'json', + ...params, + }) + /** + * No description + * + * @tags Leaderboards + * @name DeleteLeaderboard + * @summary Deletes a leaderboard. This request is restricted to Administrators. + * @request DELETE:/leaderboard/{id} + * @secure + * @response `204` `void` No Content + * @response `400` `ProblemDetails` Bad Request + * @response `401` `void` Unauthorized + * @response `403` `void` Forbidden + * @response `404` `ProblemDetails` The leaderboard does not exist (Not Found) or was already deleted (Already Deleted). Use the title field of the response to differentiate between the two cases if necessary. + * @response `500` `void` Internal Server Error + */ + deleteLeaderboard = (id: number, params: RequestParams = {}) => + this.request({ + path: `/leaderboard/${id}`, + method: 'DELETE', + secure: true, + ...params, + }) + /** + * No description + * + * @tags Leaderboards + * @name UpdateLeaderboard + * @summary Updates a leaderboard with the specified new fields. This request is restricted to administrators. This operation is atomic; if an error occurs, the leaderboard will not be updated. All fields of the request body are optional but you must specify at least one. + * @request PATCH:/leaderboard/{id} + * @secure + * @response `204` `void` No Content + * @response `400` `ProblemDetails` Bad Request + * @response `401` `void` Unauthorized + * @response `403` `void` Forbidden + * @response `404` `ProblemDetails` Not Found + * @response `409` `LeaderboardViewModel` The specified slug is already in use by another leaderboard. Returns the conflicting leaderboard. + * @response `422` `ValidationProblemDetails` Unprocessable Content + * @response `500` `void` Internal Server Error + */ + updateLeaderboard = ( + id: number, + data: UpdateLeaderboardRequest, + params: RequestParams = {}, + ) => + this.request< + void, + ProblemDetails | void | LeaderboardViewModel | ValidationProblemDetails + >({ + path: `/leaderboard/${id}`, + method: 'PATCH', + body: data, + secure: true, + type: ContentType.Json, + ...params, + }) } diff --git a/lib/api/LeaderboardsRoute.ts b/lib/api/LeaderboardsRoute.ts index fae24b97..d00d265f 100644 --- a/lib/api/LeaderboardsRoute.ts +++ b/lib/api/LeaderboardsRoute.ts @@ -12,6 +12,7 @@ import type { CreateLeaderboardRequest, LeaderboardViewModel, + UpdateLeaderboardRequest, } from './data-contracts' export namespace Leaderboards { @@ -42,7 +43,7 @@ export namespace Leaderboards { * No description * @tags Leaderboards * @name GetLeaderboardBySlug - * @summary Gets a Leaderboard by its slug. + * @summary Gets a leaderboard by its slug. * @request GET:/api/leaderboard * @secure * @response `200` `LeaderboardViewModel` OK @@ -63,18 +64,19 @@ export namespace Leaderboards { /** * No description * @tags Leaderboards - * @name GetLeaderboards - * @summary Gets leaderboards by their IDs. + * @name ListLeaderboards + * @summary Gets all leaderboards. * @request GET:/api/leaderboards * @secure * @response `200` `(LeaderboardViewModel)[]` OK * @response `400` `ProblemDetails` Bad Request * @response `500` `void` Internal Server Error */ - export namespace GetLeaderboards { + export namespace ListLeaderboards { export type RequestParams = {} export type RequestQuery = { - ids?: number[] + /** @default false */ + includeDeleted?: boolean } export type RequestBody = never export type RequestHeaders = {} @@ -92,7 +94,8 @@ export namespace Leaderboards { * @response `400` `ProblemDetails` Bad Request * @response `401` `void` Unauthorized * @response `403` `void` The requesting `User` is unauthorized to create `Leaderboard`s. - * @response `422` `ValidationProblemDetails` Unprocessable Content + * @response `409` `ValidationProblemDetails` A Leaderboard with the specified slug already exists. + * @response `422` `ValidationProblemDetails` The request contains errors. The following errors can occur: NotEmptyValidator, SlugFormat * @response `500` `void` Internal Server Error */ export namespace CreateLeaderboard { @@ -102,4 +105,82 @@ export namespace Leaderboards { export type RequestHeaders = {} export type ResponseBody = LeaderboardViewModel } + + /** + * No description + * @tags Leaderboards + * @name RestoreLeaderboard + * @summary Restores a deleted leaderboard. + * @request PUT:/leaderboard/{id}/restore + * @secure + * @response `200` `LeaderboardViewModel` The restored `Leaderboard`s view model. + * @response `400` `ProblemDetails` Bad Request + * @response `401` `void` Unauthorized + * @response `403` `void` The requesting `User` is unauthorized to restore `Leaderboard`s. + * @response `404` `ProblemDetails` The `Leaderboard` was not found, or it wasn't deleted in the first place. Includes a field, `title`, which will be "Not Found" in the former case, and "Not Deleted" in the latter. + * @response `409` `LeaderboardViewModel` Another `Leaderboard` with the same slug has been created since, and therefore can't be restored. Will include the conflicting board in the response. + * @response `500` `void` Internal Server Error + */ + export namespace RestoreLeaderboard { + export type RequestParams = { + /** @format int64 */ + id: number + } + export type RequestQuery = {} + export type RequestBody = never + export type RequestHeaders = {} + export type ResponseBody = LeaderboardViewModel + } + + /** + * No description + * @tags Leaderboards + * @name DeleteLeaderboard + * @summary Deletes a leaderboard. This request is restricted to Administrators. + * @request DELETE:/leaderboard/{id} + * @secure + * @response `204` `void` No Content + * @response `400` `ProblemDetails` Bad Request + * @response `401` `void` Unauthorized + * @response `403` `void` Forbidden + * @response `404` `ProblemDetails` The leaderboard does not exist (Not Found) or was already deleted (Already Deleted). Use the title field of the response to differentiate between the two cases if necessary. + * @response `500` `void` Internal Server Error + */ + export namespace DeleteLeaderboard { + export type RequestParams = { + /** @format int64 */ + id: number + } + export type RequestQuery = {} + export type RequestBody = never + export type RequestHeaders = {} + export type ResponseBody = void + } + + /** + * No description + * @tags Leaderboards + * @name UpdateLeaderboard + * @summary Updates a leaderboard with the specified new fields. This request is restricted to administrators. This operation is atomic; if an error occurs, the leaderboard will not be updated. All fields of the request body are optional but you must specify at least one. + * @request PATCH:/leaderboard/{id} + * @secure + * @response `204` `void` No Content + * @response `400` `ProblemDetails` Bad Request + * @response `401` `void` Unauthorized + * @response `403` `void` Forbidden + * @response `404` `ProblemDetails` Not Found + * @response `409` `LeaderboardViewModel` The specified slug is already in use by another leaderboard. Returns the conflicting leaderboard. + * @response `422` `ValidationProblemDetails` Unprocessable Content + * @response `500` `void` Internal Server Error + */ + export namespace UpdateLeaderboard { + export type RequestParams = { + /** @format int64 */ + id: number + } + export type RequestQuery = {} + export type RequestBody = UpdateLeaderboardRequest + export type RequestHeaders = {} + export type ResponseBody = void + } } diff --git a/lib/api/data-contracts.ts b/lib/api/data-contracts.ts index 7266b2e3..47002fbd 100644 --- a/lib/api/data-contracts.ts +++ b/lib/api/data-contracts.ts @@ -1,4 +1,3 @@ - /* tslint:disable */ /* * --------------------------------------------------------------- @@ -51,6 +50,7 @@ export interface CategoryViewModel { } export interface ChangePasswordRequest { + /** @minLength 1 */ password: string } @@ -86,6 +86,7 @@ export interface CreateCategoryRequest { export interface CreateLeaderboardRequest { /** * The display name of the `Leaderboard` to create. + * @minLength 1 * @example "Foo Bar" */ name: string @@ -93,10 +94,11 @@ export interface CreateLeaderboardRequest { * The URL-scoped unique identifier of the `Leaderboard`. * * Must be [2, 80] in length and consist only of alphanumeric characters and hyphens. + * @minLength 1 * @example "foo-bar" */ slug: string - info: string | null + info?: string } /** This request object is sent when creating a `Run`. */ @@ -142,7 +144,7 @@ export interface LeaderboardViewModel { * The general information for the Leaderboard. * @example "Timer starts on selecting New Game and ends when the final boss is beaten." */ - info: string | null + info: string /** * The time the Leaderboard was created. * @format date-time @@ -224,17 +226,20 @@ export interface RegisterRequest { * Usernames are saved case-sensitively, but matched against case-insensitively. * A `User` may not register with the name 'Cool' when another `User` with the name 'cool' * exists. + * @minLength 1 * @example "J'on-Doe" */ username: string /** * The `User`'s email address. + * @minLength 1 * @example "john.doe@example.com" */ email: string /** * The `User`'s password. It: *
  • supports Unicode;
  • must be [8, 80] in length;
  • must have at least:
    • one uppercase letter;
    • one lowercase letter; and
    • one number.
+ * @minLength 1 * @example "P4ssword" */ password: string @@ -266,6 +271,12 @@ export type TimedRunViewModel = BaseRunViewModel & { time: string } +export interface UpdateLeaderboardRequest { + name?: string + slug?: string + info?: string +} + export type UserRole = 'Registered' | 'Confirmed' | 'Administrator' | 'Banned' export interface UserViewModel { @@ -353,6 +364,7 @@ export interface GetLeaderboardBySlugParams { slug: string } -export interface GetLeaderboardsParams { - ids?: number[] +export interface ListLeaderboardsParams { + /** @default false */ + includeDeleted?: boolean }