diff --git a/frontend/modify-openapi-operationids.js b/frontend/modify-openapi-operationids.js deleted file mode 100644 index b22fd17f9e..0000000000 --- a/frontend/modify-openapi-operationids.js +++ /dev/null @@ -1,36 +0,0 @@ -import * as fs from "node:fs" - -async function modifyOpenAPIFile(filePath) { - try { - const data = await fs.promises.readFile(filePath) - const openapiContent = JSON.parse(data) - - const paths = openapiContent.paths - for (const pathKey of Object.keys(paths)) { - const pathData = paths[pathKey] - for (const method of Object.keys(pathData)) { - const operation = pathData[method] - if (operation.tags && operation.tags.length > 0) { - const tag = operation.tags[0] - const operationId = operation.operationId - const toRemove = `${tag}-` - if (operationId.startsWith(toRemove)) { - const newOperationId = operationId.substring(toRemove.length) - operation.operationId = newOperationId - } - } - } - } - - await fs.promises.writeFile( - filePath, - JSON.stringify(openapiContent, null, 2), - ) - console.log("File successfully modified") - } catch (err) { - console.error("Error:", err) - } -} - -const filePath = "./openapi.json" -modifyOpenAPIFile(filePath) diff --git a/frontend/openapi-ts.config.ts b/frontend/openapi-ts.config.ts index 178d04b3bf..3cd5ff3c46 100644 --- a/frontend/openapi-ts.config.ts +++ b/frontend/openapi-ts.config.ts @@ -10,6 +10,19 @@ export default defineConfig({ name: "@hey-api/sdk", // NOTE: this doesn't allow tree-shaking asClass: true, + operationId: true, + methodNameBuilder: (operation) => { + // @ts-ignore + let name: string = operation.name + // @ts-ignore + let service: string = operation.service + + if (service && name.toLowerCase().startsWith(service.toLowerCase())) { + name = name.slice(service.length) + } + + return name.charAt(0).toLowerCase() + name.slice(1) + }, }, ], }) diff --git a/frontend/src/client/sdk.gen.ts b/frontend/src/client/sdk.gen.ts index 4a6723ea70..92ded2bde8 100644 --- a/frontend/src/client/sdk.gen.ts +++ b/frontend/src/client/sdk.gen.ts @@ -4,46 +4,46 @@ import type { CancelablePromise } from "./core/CancelablePromise" import { OpenAPI } from "./core/OpenAPI" import { request as __request } from "./core/request" import type { - ReadItemsData, - ReadItemsResponse, - CreateItemData, - CreateItemResponse, - ReadItemData, - ReadItemResponse, - UpdateItemData, - UpdateItemResponse, - DeleteItemData, - DeleteItemResponse, - LoginAccessTokenData, - LoginAccessTokenResponse, - TestTokenResponse, - RecoverPasswordData, - RecoverPasswordResponse, - ResetPasswordData, - ResetPasswordResponse, - RecoverPasswordHtmlContentData, - RecoverPasswordHtmlContentResponse, - ReadUsersData, - ReadUsersResponse, - CreateUserData, - CreateUserResponse, - ReadUserMeResponse, - DeleteUserMeResponse, - UpdateUserMeData, - UpdateUserMeResponse, - UpdatePasswordMeData, - UpdatePasswordMeResponse, - RegisterUserData, - RegisterUserResponse, - ReadUserByIdData, - ReadUserByIdResponse, - UpdateUserData, - UpdateUserResponse, - DeleteUserData, - DeleteUserResponse, - TestEmailData, - TestEmailResponse, - HealthCheckResponse, + ItemsReadItemsData, + ItemsReadItemsResponse, + ItemsCreateItemData, + ItemsCreateItemResponse, + ItemsReadItemData, + ItemsReadItemResponse, + ItemsUpdateItemData, + ItemsUpdateItemResponse, + ItemsDeleteItemData, + ItemsDeleteItemResponse, + LoginLoginAccessTokenData, + LoginLoginAccessTokenResponse, + LoginTestTokenResponse, + LoginRecoverPasswordData, + LoginRecoverPasswordResponse, + LoginResetPasswordData, + LoginResetPasswordResponse, + LoginRecoverPasswordHtmlContentData, + LoginRecoverPasswordHtmlContentResponse, + UsersReadUsersData, + UsersReadUsersResponse, + UsersCreateUserData, + UsersCreateUserResponse, + UsersReadUserMeResponse, + UsersDeleteUserMeResponse, + UsersUpdateUserMeData, + UsersUpdateUserMeResponse, + UsersUpdatePasswordMeData, + UsersUpdatePasswordMeResponse, + UsersRegisterUserData, + UsersRegisterUserResponse, + UsersReadUserByIdData, + UsersReadUserByIdResponse, + UsersUpdateUserData, + UsersUpdateUserResponse, + UsersDeleteUserData, + UsersDeleteUserResponse, + UtilsTestEmailData, + UtilsTestEmailResponse, + UtilsHealthCheckResponse, } from "./types.gen" export class ItemsService { @@ -57,8 +57,8 @@ export class ItemsService { * @throws ApiError */ public static readItems( - data: ReadItemsData = {}, - ): CancelablePromise { + data: ItemsReadItemsData = {}, + ): CancelablePromise { return __request(OpenAPI, { method: "GET", url: "/api/v1/items/", @@ -81,8 +81,8 @@ export class ItemsService { * @throws ApiError */ public static createItem( - data: CreateItemData, - ): CancelablePromise { + data: ItemsCreateItemData, + ): CancelablePromise { return __request(OpenAPI, { method: "POST", url: "/api/v1/items/", @@ -103,8 +103,8 @@ export class ItemsService { * @throws ApiError */ public static readItem( - data: ReadItemData, - ): CancelablePromise { + data: ItemsReadItemData, + ): CancelablePromise { return __request(OpenAPI, { method: "GET", url: "/api/v1/items/{id}", @@ -127,8 +127,8 @@ export class ItemsService { * @throws ApiError */ public static updateItem( - data: UpdateItemData, - ): CancelablePromise { + data: ItemsUpdateItemData, + ): CancelablePromise { return __request(OpenAPI, { method: "PUT", url: "/api/v1/items/{id}", @@ -152,8 +152,8 @@ export class ItemsService { * @throws ApiError */ public static deleteItem( - data: DeleteItemData, - ): CancelablePromise { + data: ItemsDeleteItemData, + ): CancelablePromise { return __request(OpenAPI, { method: "DELETE", url: "/api/v1/items/{id}", @@ -177,8 +177,8 @@ export class LoginService { * @throws ApiError */ public static loginAccessToken( - data: LoginAccessTokenData, - ): CancelablePromise { + data: LoginLoginAccessTokenData, + ): CancelablePromise { return __request(OpenAPI, { method: "POST", url: "/api/v1/login/access-token", @@ -196,7 +196,7 @@ export class LoginService { * @returns UserPublic Successful Response * @throws ApiError */ - public static testToken(): CancelablePromise { + public static testToken(): CancelablePromise { return __request(OpenAPI, { method: "POST", url: "/api/v1/login/test-token", @@ -212,8 +212,8 @@ export class LoginService { * @throws ApiError */ public static recoverPassword( - data: RecoverPasswordData, - ): CancelablePromise { + data: LoginRecoverPasswordData, + ): CancelablePromise { return __request(OpenAPI, { method: "POST", url: "/api/v1/password-recovery/{email}", @@ -235,8 +235,8 @@ export class LoginService { * @throws ApiError */ public static resetPassword( - data: ResetPasswordData, - ): CancelablePromise { + data: LoginResetPasswordData, + ): CancelablePromise { return __request(OpenAPI, { method: "POST", url: "/api/v1/reset-password/", @@ -257,8 +257,8 @@ export class LoginService { * @throws ApiError */ public static recoverPasswordHtmlContent( - data: RecoverPasswordHtmlContentData, - ): CancelablePromise { + data: LoginRecoverPasswordHtmlContentData, + ): CancelablePromise { return __request(OpenAPI, { method: "POST", url: "/api/v1/password-recovery-html-content/{email}", @@ -283,8 +283,8 @@ export class UsersService { * @throws ApiError */ public static readUsers( - data: ReadUsersData = {}, - ): CancelablePromise { + data: UsersReadUsersData = {}, + ): CancelablePromise { return __request(OpenAPI, { method: "GET", url: "/api/v1/users/", @@ -307,8 +307,8 @@ export class UsersService { * @throws ApiError */ public static createUser( - data: CreateUserData, - ): CancelablePromise { + data: UsersCreateUserData, + ): CancelablePromise { return __request(OpenAPI, { method: "POST", url: "/api/v1/users/", @@ -326,7 +326,7 @@ export class UsersService { * @returns UserPublic Successful Response * @throws ApiError */ - public static readUserMe(): CancelablePromise { + public static readUserMe(): CancelablePromise { return __request(OpenAPI, { method: "GET", url: "/api/v1/users/me", @@ -339,7 +339,7 @@ export class UsersService { * @returns Message Successful Response * @throws ApiError */ - public static deleteUserMe(): CancelablePromise { + public static deleteUserMe(): CancelablePromise { return __request(OpenAPI, { method: "DELETE", url: "/api/v1/users/me", @@ -355,8 +355,8 @@ export class UsersService { * @throws ApiError */ public static updateUserMe( - data: UpdateUserMeData, - ): CancelablePromise { + data: UsersUpdateUserMeData, + ): CancelablePromise { return __request(OpenAPI, { method: "PATCH", url: "/api/v1/users/me", @@ -377,8 +377,8 @@ export class UsersService { * @throws ApiError */ public static updatePasswordMe( - data: UpdatePasswordMeData, - ): CancelablePromise { + data: UsersUpdatePasswordMeData, + ): CancelablePromise { return __request(OpenAPI, { method: "PATCH", url: "/api/v1/users/me/password", @@ -399,8 +399,8 @@ export class UsersService { * @throws ApiError */ public static registerUser( - data: RegisterUserData, - ): CancelablePromise { + data: UsersRegisterUserData, + ): CancelablePromise { return __request(OpenAPI, { method: "POST", url: "/api/v1/users/signup", @@ -421,8 +421,8 @@ export class UsersService { * @throws ApiError */ public static readUserById( - data: ReadUserByIdData, - ): CancelablePromise { + data: UsersReadUserByIdData, + ): CancelablePromise { return __request(OpenAPI, { method: "GET", url: "/api/v1/users/{user_id}", @@ -445,8 +445,8 @@ export class UsersService { * @throws ApiError */ public static updateUser( - data: UpdateUserData, - ): CancelablePromise { + data: UsersUpdateUserData, + ): CancelablePromise { return __request(OpenAPI, { method: "PATCH", url: "/api/v1/users/{user_id}", @@ -470,8 +470,8 @@ export class UsersService { * @throws ApiError */ public static deleteUser( - data: DeleteUserData, - ): CancelablePromise { + data: UsersDeleteUserData, + ): CancelablePromise { return __request(OpenAPI, { method: "DELETE", url: "/api/v1/users/{user_id}", @@ -495,8 +495,8 @@ export class UtilsService { * @throws ApiError */ public static testEmail( - data: TestEmailData, - ): CancelablePromise { + data: UtilsTestEmailData, + ): CancelablePromise { return __request(OpenAPI, { method: "POST", url: "/api/v1/utils/test-email/", @@ -514,7 +514,7 @@ export class UtilsService { * @returns boolean Successful Response * @throws ApiError */ - public static healthCheck(): CancelablePromise { + public static healthCheck(): CancelablePromise { return __request(OpenAPI, { method: "GET", url: "/api/v1/utils/health-check/", diff --git a/frontend/src/client/types.gen.ts b/frontend/src/client/types.gen.ts index 54f5ee5730..c2a58d06cb 100644 --- a/frontend/src/client/types.gen.ts +++ b/frontend/src/client/types.gen.ts @@ -100,122 +100,122 @@ export type ValidationError = { type: string } -export type ReadItemsData = { +export type ItemsReadItemsData = { limit?: number skip?: number } -export type ReadItemsResponse = ItemsPublic +export type ItemsReadItemsResponse = ItemsPublic -export type CreateItemData = { +export type ItemsCreateItemData = { requestBody: ItemCreate } -export type CreateItemResponse = ItemPublic +export type ItemsCreateItemResponse = ItemPublic -export type ReadItemData = { +export type ItemsReadItemData = { id: string } -export type ReadItemResponse = ItemPublic +export type ItemsReadItemResponse = ItemPublic -export type UpdateItemData = { +export type ItemsUpdateItemData = { id: string requestBody: ItemUpdate } -export type UpdateItemResponse = ItemPublic +export type ItemsUpdateItemResponse = ItemPublic -export type DeleteItemData = { +export type ItemsDeleteItemData = { id: string } -export type DeleteItemResponse = Message +export type ItemsDeleteItemResponse = Message -export type LoginAccessTokenData = { +export type LoginLoginAccessTokenData = { formData: Body_login_login_access_token } -export type LoginAccessTokenResponse = Token +export type LoginLoginAccessTokenResponse = Token -export type TestTokenResponse = UserPublic +export type LoginTestTokenResponse = UserPublic -export type RecoverPasswordData = { +export type LoginRecoverPasswordData = { email: string } -export type RecoverPasswordResponse = Message +export type LoginRecoverPasswordResponse = Message -export type ResetPasswordData = { +export type LoginResetPasswordData = { requestBody: NewPassword } -export type ResetPasswordResponse = Message +export type LoginResetPasswordResponse = Message -export type RecoverPasswordHtmlContentData = { +export type LoginRecoverPasswordHtmlContentData = { email: string } -export type RecoverPasswordHtmlContentResponse = string +export type LoginRecoverPasswordHtmlContentResponse = string -export type ReadUsersData = { +export type UsersReadUsersData = { limit?: number skip?: number } -export type ReadUsersResponse = UsersPublic +export type UsersReadUsersResponse = UsersPublic -export type CreateUserData = { +export type UsersCreateUserData = { requestBody: UserCreate } -export type CreateUserResponse = UserPublic +export type UsersCreateUserResponse = UserPublic -export type ReadUserMeResponse = UserPublic +export type UsersReadUserMeResponse = UserPublic -export type DeleteUserMeResponse = Message +export type UsersDeleteUserMeResponse = Message -export type UpdateUserMeData = { +export type UsersUpdateUserMeData = { requestBody: UserUpdateMe } -export type UpdateUserMeResponse = UserPublic +export type UsersUpdateUserMeResponse = UserPublic -export type UpdatePasswordMeData = { +export type UsersUpdatePasswordMeData = { requestBody: UpdatePassword } -export type UpdatePasswordMeResponse = Message +export type UsersUpdatePasswordMeResponse = Message -export type RegisterUserData = { +export type UsersRegisterUserData = { requestBody: UserRegister } -export type RegisterUserResponse = UserPublic +export type UsersRegisterUserResponse = UserPublic -export type ReadUserByIdData = { +export type UsersReadUserByIdData = { userId: string } -export type ReadUserByIdResponse = UserPublic +export type UsersReadUserByIdResponse = UserPublic -export type UpdateUserData = { +export type UsersUpdateUserData = { requestBody: UserUpdate userId: string } -export type UpdateUserResponse = UserPublic +export type UsersUpdateUserResponse = UserPublic -export type DeleteUserData = { +export type UsersDeleteUserData = { userId: string } -export type DeleteUserResponse = Message +export type UsersDeleteUserResponse = Message -export type TestEmailData = { +export type UtilsTestEmailData = { emailTo: string } -export type TestEmailResponse = Message +export type UtilsTestEmailResponse = Message -export type HealthCheckResponse = boolean +export type UtilsHealthCheckResponse = boolean diff --git a/scripts/generate-client.sh b/scripts/generate-client.sh index f7a564fdf0..1e76864d42 100644 --- a/scripts/generate-client.sh +++ b/scripts/generate-client.sh @@ -6,7 +6,6 @@ set -x cd backend python -c "import app.main; import json; print(json.dumps(app.main.app.openapi()))" > ../openapi.json cd .. -node frontend/modify-openapi-operationids.js mv openapi.json frontend/ cd frontend npm run generate-client