Skip to content

Commit

Permalink
update lib api types (#649)
Browse files Browse the repository at this point in the history
* update lib api types

* fix: fix warning from data contract

* fix: inline type on RequestParams
  • Loading branch information
Eein authored Nov 10, 2024
1 parent f81bc78 commit 4683361
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lib/api/Account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}) =>
Expand Down
2 changes: 1 addition & 1 deletion lib/api/AccountRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
98 changes: 91 additions & 7 deletions lib/api/Leaderboards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -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<LeaderboardViewModel[], ProblemDetails | void>({
Expand All @@ -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 = (
Expand All @@ -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<void, ProblemDetails | void>({
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,
})
}
93 changes: 87 additions & 6 deletions lib/api/LeaderboardsRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import type {
CreateLeaderboardRequest,
LeaderboardViewModel,
UpdateLeaderboardRequest,
} from './data-contracts'

export namespace Leaderboards {
Expand Down Expand Up @@ -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
Expand All @@ -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 = {}
Expand All @@ -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 {
Expand All @@ -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
}
}
22 changes: 17 additions & 5 deletions lib/api/data-contracts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/* tslint:disable */
/*
* ---------------------------------------------------------------
Expand Down Expand Up @@ -51,6 +50,7 @@ export interface CategoryViewModel {
}

export interface ChangePasswordRequest {
/** @minLength 1 */
password: string
}

Expand Down Expand Up @@ -86,17 +86,19 @@ export interface CreateCategoryRequest {
export interface CreateLeaderboardRequest {
/**
* The display name of the `Leaderboard` to create.
* @minLength 1
* @example "Foo Bar"
*/
name: string
/**
* 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`. */
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 "[email protected]"
*/
email: string
/**
* The `User`'s password. It:
* <ul><li>supports Unicode;</li><li>must be [8, 80] in length;</li><li>must have at least:</li><ul><li>one uppercase letter;</li><li>one lowercase letter; and</li><li>one number.</li></ul></ul>
* @minLength 1
* @example "P4ssword"
*/
password: string
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -353,6 +364,7 @@ export interface GetLeaderboardBySlugParams {
slug: string
}

export interface GetLeaderboardsParams {
ids?: number[]
export interface ListLeaderboardsParams {
/** @default false */
includeDeleted?: boolean
}

0 comments on commit 4683361

Please sign in to comment.