Skip to content

refactor(ui): migrate API client codegen from hey-api to orval - #7023

Draft
luizhf42 wants to merge 3 commits into
masterfrom
feat/ui/orval
Draft

refactor(ui): migrate API client codegen from hey-api to orval#7023
luizhf42 wants to merge 3 commits into
masterfrom
feat/ui/orval

Conversation

@luizhf42

@luizhf42 luizhf42 commented Sep 2, 2026

Copy link
Copy Markdown
Member

Warning

WIP — this branch is under active development and not ready for review.

Migrates the console's OpenAPI client codegen from @hey-api/openapi-ts to Orval. Tracked in shellhub-io/team#236.

Done

  • Orval codegen setuporval.config.ts, customInstance.ts (replaces the interceptor chain), totalCount() accessor via non-enumerable property on array responses, ErrorType/BodyType exports, mutationInvalidates declarative config
  • Query hook inlining — deleted 17 thin query wrapper hooks and 6 associated tests; consumers call Orval-generated hooks directly (useGetSessions, useGetDevicesAdmin, etc.)
  • Admin cargo-cult options removedstaleTime, retry (401 is dead code since customInstance redirects), refetchOnWindowFocus: false, enabled: isAdmin (redundant behind AdminRoute)
  • Filter inliningbuildNameFilter, buildUsernameFilter, encodeAddressFilter, buildPublicKeyFilter moved from deleted hooks into their single consumer pages using toBase64Json
  • useNamespaces.ts trimmed — removed useInitRole (inlined into NamespaceGuard) and useNamespaceMembers (inlined into MembersTab); switched to Orval hooks
  • useLatestAnnouncement inlined — chained queries now live in AnnouncementModalTrigger
  • useInvitations inlineduseResolveInvitation + useNamespaceInvitations moved into consumers
  • signUpStore.ts fixedregisterUser response was being discarded (always null signUpToken/signUpTenant); now reads the UserAuth return properly. Depends on fix(server): return 204 from registerUser when no auth is issued #7042 for the correct 200/204 split

Remaining

MutatorOptions.method must be optional (~100 TS errors)

customInstance.ts declares method as required, but every generated function in api.ts spreads { ...options, method: 'GET' } — callers should not need to supply it. Making it optional fixes all generated-code errors and unblocks signUpStore.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 (returns T directly), passes { path, body, throwOnError } shape
  • useNamespaceMutations.tsresult.data.token but Orval returns T directly (no .data wrapper)
  • useContainerMutations.ts / useDeviceMutations.ts — tag creation passes wrong arg count, { body } shape
  • useContainerActionRunner.ts / useDeviceActionRunner.ts{ path } shape
  • useSSHApproval.ts:140{ path } shape in confirmSshApproval/rejectSshApproval

Broken imports from deleted modules (5 files)

  • DeviceDetails.tsxuseInstallKeys (deleted)
  • ManageTagsDrawer.tsxuseTags (deleted)
  • mockNamespaces.ts@/client/sdk.gen (old codegen)
  • mockTags.ts@/client/sdk.gen (old codegen)
  • useSupportIdentifier.test.tsuseSupportIdentifier (deleted in prior commit)

Old hey-api interceptor files to delete (3 files)

fetchClient.ts, fetchInterceptors.ts, fetchInterceptors.test.ts — replaced by customInstance.ts, still import @/client/client.gen.

Generated faker/MSW needs @faker-js/faker (2 errors)

api.faker.ts and api.msw.ts reference @faker-js/faker which 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 (6 no-unsafe-return), useAcceptDeviceByCode.ts (12 no-unsafe-member-access), useNamespaceMutations.ts (10 no-unsafe-member-access), ManageTagsDrawer.tsx (implicit any).

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`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants