From ed4a091d6ee9e400a8ce339856b0d489c966cb1b Mon Sep 17 00:00:00 2001 From: GW_MC <72297530+GWMCwing@users.noreply.github.com> Date: Thu, 18 Dec 2025 18:26:27 +0800 Subject: [PATCH] update swagger and api-client --- apps/api/swagger.json | 58 +++++++++++++++++++ .../app/generated/api-client/api-client.ts | 45 ++++++++++++++ .../generated/api-client/tanstack-client.ts | 31 ++++++++++ 3 files changed, 134 insertions(+) diff --git a/apps/api/swagger.json b/apps/api/swagger.json index 1b35dde..71bd824 100644 --- a/apps/api/swagger.json +++ b/apps/api/swagger.json @@ -9,6 +9,44 @@ "version": "0.1.0" }, "paths": { + "/api/auth/login": { + "post": { + "tags": [ + "Authentication" + ], + "summary": "Login endpoint", + "description": "Authenticates a user and returns a JWT in an HttpOnly cookie.", + "operationId": "login", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/LoginRequest" + } + } + }, + "required": true + }, + "responses": { + "200": { + "description": "User authenticated successfully", + "content": { + "application/json": { + "schema": { + "default": null + } + } + } + }, + "401": { + "description": "Authentication failed" + }, + "500": { + "description": "Internal server error" + } + } + } + }, "/api/health/info": { "get": { "tags": [ @@ -70,6 +108,22 @@ "description": "Application version" } } + }, + "LoginRequest": { + "type": "object", + "description": "Login request payload", + "required": [ + "username", + "password" + ], + "properties": { + "password": { + "type": "string" + }, + "username": { + "type": "string" + } + } } } }, @@ -77,6 +131,10 @@ { "name": "Health", "description": "Health information API" + }, + { + "name": "Authentication", + "description": "Authentication API" } ] } \ No newline at end of file diff --git a/apps/frontend/app/generated/api-client/api-client.ts b/apps/frontend/app/generated/api-client/api-client.ts index 8a5e6b3..4f648e5 100644 --- a/apps/frontend/app/generated/api-client/api-client.ts +++ b/apps/frontend/app/generated/api-client/api-client.ts @@ -6,6 +6,7 @@ export namespace Schemas { up_since: string; version: string; }; + export type LoginRequest = { password: string; username: string }; // } @@ -13,6 +14,15 @@ export namespace Schemas { export namespace Endpoints { // + export type post_Login = { + method: "POST"; + path: "/api/auth/login"; + requestFormat: "json"; + parameters: { + body: Schemas.LoginRequest; + }; + responses: { 200: unknown; 401: unknown; 500: unknown }; + }; export type get_Get_health_info = { method: "GET"; path: "/api/health/info"; @@ -26,6 +36,9 @@ export namespace Endpoints { // export type EndpointByMethod = { + post: { + "/api/auth/login": Endpoints.post_Login; + }; get: { "/api/health/info": Endpoints.get_Get_health_info; }; @@ -34,6 +47,7 @@ export type EndpointByMethod = { // // +export type PostEndpoints = EndpointByMethod["post"]; export type GetEndpoints = EndpointByMethod["get"]; // @@ -267,6 +281,37 @@ export class ApiClient { return; }; + // + post( + path: Path, + ...params: MaybeOptionalArg< + TEndpoint extends { parameters: infer UParams } + ? NotNever extends true + ? UParams & { overrides?: RequestInit; withResponse?: false; throwOnStatusError?: boolean } + : { overrides?: RequestInit; withResponse?: false; throwOnStatusError?: boolean } + : { overrides?: RequestInit; withResponse?: false; throwOnStatusError?: boolean } + > + ): Promise, { data: {} }>["data"]>; + + post( + path: Path, + ...params: MaybeOptionalArg< + TEndpoint extends { parameters: infer UParams } + ? NotNever extends true + ? UParams & { overrides?: RequestInit; withResponse?: true; throwOnStatusError?: boolean } + : { overrides?: RequestInit; withResponse?: true; throwOnStatusError?: boolean } + : { overrides?: RequestInit; withResponse?: true; throwOnStatusError?: boolean } + > + ): Promise>; + + post( + path: Path, + ...params: MaybeOptionalArg + ): Promise { + return this.request("post", path, ...params); + } + // + // get( path: Path, diff --git a/apps/frontend/app/generated/api-client/tanstack-client.ts b/apps/frontend/app/generated/api-client/tanstack-client.ts index e76a8a3..0cd843e 100644 --- a/apps/frontend/app/generated/api-client/tanstack-client.ts +++ b/apps/frontend/app/generated/api-client/tanstack-client.ts @@ -41,6 +41,7 @@ const createQueryKey = ( }; // +export type PostEndpoints = EndpointByMethod["post"]; export type GetEndpoints = EndpointByMethod["get"]; // @@ -69,6 +70,36 @@ type InferResponseData = export class TanstackQueryApiClient { constructor(public client: ApiClient) {} + // + post( + path: Path, + ...params: MaybeOptionalArg + ) { + const queryKey = createQueryKey(path as string, params[0]); + const query = { + /** type-only property if you need easy access to the endpoint params */ + "~endpoint": {} as TEndpoint, + queryKey, + queryFn: {} as "You need to pass .queryOptions to the useQuery hook", + queryOptions: queryOptions({ + queryFn: async ({ queryKey, signal }) => { + const requestParams = { + ...(params[0] || {}), + ...(queryKey[0] || {}), + overrides: { signal }, + withResponse: false as const, + }; + const res = await this.client.post(path, requestParams as never); + return res as InferResponseData; + }, + queryKey: queryKey, + }), + }; + + return query; + } + // + // get( path: Path,