refactor(ui): migrate API client codegen from hey-api to orval - #7023
Draft
luizhf42 wants to merge 3 commits into
Draft
refactor(ui): migrate API client codegen from hey-api to orval#7023luizhf42 wants to merge 3 commits into
luizhf42 wants to merge 3 commits into
Conversation
Orval replaces `@hey-api/openapi-ts` as the OpenAPI client generator. The config enables react-query hooks, and MSW/faker mock generation from the spec. The custom mutator merges `fetchClient` and `fetchInterceptors` into a single function that handles auth, JWT expiry, 401/MFA, connectivity tracking, and error enrichment. `fetchWithResponse` is exported alongside for paginated hooks that need access to response headers.
Delete 11 single-purpose query hooks and trim query exports from 2 mixed files, updating ~20 call sites to import directly from the generated `@/client/api` module.
…lidates` Orval's `mutationInvalidates` config auto-generates `onSuccess` invalidation inside each mutation hook, making the hand-written thin wrappers redundant. This commit drops Zod runtime validation (unused — zero `.parse()` calls across 6 400 generated lines), removes the `inlineParameterRefs` transformer that only existed as a Zod workaround, wires up `mutationInvalidates` for every mutation→query relationship, deletes 17 invalidation-only hook files plus 5 obsolete test files, and trims 6 mixed files down to only the hooks carrying real logic. All call sites now import generated hooks directly from `@/client/api`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Warning
WIP — this branch is under active development and not ready for review.
Migrates the console's OpenAPI client codegen from
@hey-api/openapi-tsto Orval. Tracked in shellhub-io/team#236.Done
orval.config.ts,customInstance.ts(replaces the interceptor chain),totalCount()accessor via non-enumerable property on array responses,ErrorType/BodyTypeexports,mutationInvalidatesdeclarative configuseGetSessions,useGetDevicesAdmin, etc.)staleTime,retry(401 is dead code sincecustomInstanceredirects),refetchOnWindowFocus: false,enabled: isAdmin(redundant behindAdminRoute)buildNameFilter,buildUsernameFilter,encodeAddressFilter,buildPublicKeyFiltermoved from deleted hooks into their single consumer pages usingtoBase64JsonuseNamespaces.tstrimmed — removeduseInitRole(inlined intoNamespaceGuard) anduseNamespaceMembers(inlined intoMembersTab); switched to Orval hooksuseLatestAnnouncementinlined — chained queries now live inAnnouncementModalTriggeruseInvitationsinlined —useResolveInvitation+useNamespaceInvitationsmoved into consumerssignUpStore.tsfixed —registerUserresponse was being discarded (always nullsignUpToken/signUpTenant); now reads theUserAuthreturn properly. Depends on fix(server): return 204 from registerUser when no auth is issued #7042 for the correct 200/204 splitRemaining
MutatorOptions.methodmust be optional (~100 TS errors)customInstance.tsdeclaresmethodas required, but every generated function inapi.tsspreads{ ...options, method: 'GET' }— callers should not need to supply it. Making it optional fixes all generated-code errors and unblockssignUpStore.ts:106({ signal }fails the type check).Mutation call sites still use hey-api
{ path, body }shape (~55 TS errors across ~40 files)Orval generates flat params (
{ uid, name }) or positional args, not the{ path: { uid }, body: { name } }nesting. Every mutation call site needs rewriting. Files:AcceptInvite,BannerEdit,ContainerDetails,SessionDetails,Settings,WebEndpoints,AccessPolicyDrawer,License,DeleteAnnouncementDialog,EditAnnouncement,NewAnnouncement,DeleteNamespaceDialog,EditNamespaceDrawer,CreateUserDrawer,DeleteUserDialog,EditUserDrawer,ResetPasswordDialog,admin/users/index,RuleDrawer,firewall-rules/index,CreateInstallKeyDrawer,EditInstallKeyDrawer,RevokeInstallKeyDialog,useToggleInstallKey,KeyDrawer,public-keys/index,sessions/index,IdentityDrawer,ssh-identities/index,AddMemberDrawer,ApiKeysTab,EditKeyDrawer,EditMemberDrawer,GenerateKeyDrawer,MembersTab,ServiceAccountDrawer,ServiceAccountsTab,ConnectDrawer,ManageTagsDrawer,BillingPayment,DeviceChooserDialog,AcceptDeviceFlow,CustomFieldsSection,devices/index,containers/index.Hooks still using hey-api SDK patterns (~15 TS errors)
useAcceptDeviceByCode.ts— destructures{ data }from Orval functions (returnsTdirectly), passes{ path, body, throwOnError }shapeuseNamespaceMutations.ts—result.data.tokenbut Orval returnsTdirectly (no.datawrapper)useContainerMutations.ts/useDeviceMutations.ts— tag creation passes wrong arg count,{ body }shapeuseContainerActionRunner.ts/useDeviceActionRunner.ts—{ path }shapeuseSSHApproval.ts:140—{ path }shape inconfirmSshApproval/rejectSshApprovalBroken imports from deleted modules (5 files)
DeviceDetails.tsx→useInstallKeys(deleted)ManageTagsDrawer.tsx→useTags(deleted)mockNamespaces.ts→@/client/sdk.gen(old codegen)mockTags.ts→@/client/sdk.gen(old codegen)useSupportIdentifier.test.ts→useSupportIdentifier(deleted in prior commit)Old hey-api interceptor files to delete (3 files)
fetchClient.ts,fetchInterceptors.ts,fetchInterceptors.test.ts— replaced bycustomInstance.ts, still import@/client/client.gen.Generated faker/MSW needs
@faker-js/faker(2 errors)api.faker.tsandapi.msw.tsreference@faker-js/fakerwhich isn't installed. Either add the dep or disable mock generation until the test migration commit.Lint (90 errors)
Most overlap with the TS errors above. Distinct:
useSupportIdentifier.test.ts(6no-unsafe-return),useAcceptDeviceByCode.ts(12no-unsafe-member-access),useNamespaceMutations.ts(10no-unsafe-member-access),ManageTagsDrawer.tsx(implicitany).