refactor(ui): migrate API client codegen from hey-api to orval - #7023
Open
luizhf42 wants to merge 5 commits into
Open
refactor(ui): migrate API client codegen from hey-api to orval#7023luizhf42 wants to merge 5 commits into
luizhf42 wants to merge 5 commits into
Conversation
luizhf42
force-pushed
the
feat/ui/orval
branch
4 times, most recently
from
September 8, 2026 21:12
b62c997 to
6bab4a8
Compare
luizhf42
marked this pull request as ready for review
September 9, 2026 12:08
Member
|
/review |
1 similar comment
Member
|
/review |
Code Review CompleteThe automated review ran but did not post an updated summary — this usually means no new issues were found since the previous review. If you've pushed changes and want a fresh pass, comment |
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.
The hey-api SDK barrel (`@/client`) is replaced by orval's generated `@/client/api` and `@/client/model` imports. Thin single-consumer wrappers are deleted and inlined into their call sites in the next commits. Paginated hooks now use orval-generated hooks directly — `customInstance` attaches `X-Total-Count` as a non-enumerable property on array responses, and a `totalCount()` accessor reads it.
The old `mockSdkGen` / `vi.doMock("@/client/sdk.gen")` approach mocked
at the SDK function layer. MSW intercepts at the HTTP boundary, so tests
now exercise the real React Query hooks, `customInstance`, and Orval
fetch functions with only the HTTP responses faked.
Infrastructure: add `msw.ts` (shared server + `jsonWithTotal`, `setTags`,
`parseBody` helpers), export `VALID_JWT` from `seedAuthStore` (the
factory token now passes `isTokenExpired`), tighten
`onUnhandledRequest` to `"error"`, and delete the old `sdk.ts`,
`globals.d.ts`, `mockNamespaces.ts`, `mockTags.ts` helpers.
luizhf42
force-pushed
the
feat/ui/orval
branch
from
September 9, 2026 21:12
6bab4a8 to
1261319
Compare
luizhf42
added this pull request to stack #7066
September 9, 2026 21:25
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.
Migrates the console's OpenAPI client codegen from
@hey-api/openapi-tsto Orval. Tracked in shellhub-io/team#236.What
Replaces the entire hey-api codegen pipeline — generated SDK, interceptor chain, thin query/mutation wrapper hooks, manual cache invalidation — with Orval's generated hooks and declarative config. 246 files changed, net −4454 lines.
Changes
orval.config.tsreplacesopenapi-ts.config.ts;generate-client.shcallsorvalinstead ofopenapi-ts; output issrc/client/api.ts+src/client/model/customInstance.ts— single custom mutator replaces the three-file interceptor chain (fetchClient.ts,fetchInterceptors.ts,fetchInterceptors.test.ts). Handles auth/JWT expiry, 401/MFA, connectivity monitoring,X-Total-Countattachment on array responses, and error enrichment. ExportsfetchWithHeadersfor the two auth flows that read response headers (x-mfa-token,x-expires-at)totalCount()accessor — reads the non-enumerabletotalCountproperty attached bycustomInstance, replacingpaginatedQueryFnandfetchWithHeadersfor paginated listsmutationInvalidates— 25 invalidation groups inorval.config.tsreplace 15 hand-written mutation hook files. Detail-page invalidation is handled in custom hooks where the entity ID is available (Orval'smatchQuerydoes element-wise key comparison, not prefix matching)useInvalidateByIds. Consumers call Orval-generated hooks directly (useGetDevices,useGetSessionsAdmin,useClsoeSession, etc.)useAddDeviceTag,useAddContainerTag,useDeviceActionRunner,useContainerActionRunner,useAcceptDeviceByCode,useSSHApproval,useNamespaceMutations) updated to Orval's flat variable shape ({ uid, data }instead of{ path: { uid }, body })useTagNames()— centralizes theuseGetTags({ page: 1, per_page: 100 })+.map(t => t.name)pattern used by 4 tag-related componentsuseDeleteNamespaceanduseLeaveNamespaceinlined with a sharedlogoutAndRedirect()helperbuildNameFilter,buildUsernameFilter, etc. moved from deleted hooks into their single consumer pagesuseNamespaces.tstrimmed —useInitRoleinlined intoNamespaceGuard,useNamespaceMembersinlined intoMembersTabuseLatestAnnouncementinlined — chained queries now live inAnnouncementModalTriggersignUpStore.tsfixed —registerUserresponse was being discarded; now reads theUserAuthreturn properly (depends on fix(server): return 204 from registerUser when no auth is issued #7042 for the correct 200/204 split)staleTime,retry(dead code sincecustomInstanceredirects on 401),refetchOnWindowFocus: false,enabled: isAdmin(redundant behindAdminRoute)mockSdkGenwas replaced by MSW handlers, intercepting the endpoints instead of mocking the SDK, validating Orval functionality with thecustomInstance.