fix(ui-react): generate client from combined spec for npm run generate#6387
Merged
Merged
Conversation
`npm run generate` defaulted to `http://openapi:8080/openapi/openapi.json`, which the openapi container serves filtered by the active edition (community / enterprise / cloud). Running it on a community instance produced a client missing enterprise and cloud schemas, breaking lint and type-check on any code that referenced those types. The dev entrypoint sidestepped this by bundling `/openapi/spec/openapi.yaml` directly, but a manual `npm run generate` after that overwrote the client with the edition-filtered version. Extract the bundle + generate steps into `scripts/generate-client.sh` and wire the npm script to it, so both the dev entrypoint and manual runs use the combined spec. The script honors a pre-set `OPENAPI_SPEC_PATH` so the production Dockerfile builder stage (which bundles in an earlier stage) keeps working. Remove the HTTP fallback in `openapi-ts.config.ts`: it was the source of the bug, and the new script always sets the env var. Add a chokidar watcher in the dev entrypoint that re-runs the script whenever `openapi/spec/**/*.yaml` changes, so editing the spec no longer requires recreating the container; Vite HMR picks up the fresh `types.gen.ts`. Fixes: #6386
|
Claude finished @gustavosbarreto's task in 55s —— View job Code Review CompleteReviewed 4 files across code quality, security, testing, language patterns, and architecture — no issues found. The code looks good as-is. Highlights:
To request another review round, comment |
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.
Fixes #6386.
npm run generatefor@shellhub/consoledefaulted its input tohttp://openapi:8080/openapi/openapi.json. That URL is served by theopenapicontainer, which pickscommunity-openapi.yaml,enterprise-openapi.yaml, orcloud-openapi.yamlbased onSHELLHUB_CLOUD/SHELLHUB_ENTERPRISE. Running the script on a community instance produced a client missing the enterprise and cloud schemas, so any code referencing them broke lint and type-check.The dev entrypoint avoided this by bundling
openapi/spec/openapi.yaml(combined, all editions) directly, but a manualnpm run generateafter startup overwrote that client with the edition-filtered one. Easy footgun.What changes
ui-react/scripts/generate-client.sh: bundlesopenapi/spec/openapi.yamlvia redocly into/tmp/openapi.jsonand runsopenapi-ts. IfOPENAPI_SPEC_PATHis already set (the production Dockerfile builder stage does this), it skips the bundle step and uses that spec.apps/console/package.json:generatenow calls the script.openapi-ts.config.ts: throws ifOPENAPI_SPEC_PATHis unset, with a message pointing atnpm run generate. The old HTTP fallback was the bug source.scripts/entrypoint-dev.sh: replaces the inline bundle + generate withnpm run generate, then starts achokidar-cliwatcher onopenapi/spec/**/*.yamlin the background that re-runs the same script on changes. Vite HMR picks up the regeneratedtypes.gen.tswithout recreating the container.The production Dockerfile is unchanged: its builder stage still bundles into
apps/console/openapi.jsonand runsOPENAPI_SPEC_PATH=./openapi.json npm run generate -w @shellhub/console, which the new script honors.