Skip to content

fix(ui-react): generate client from combined spec for npm run generate#6387

Merged
gustavosbarreto merged 1 commit into
masterfrom
fix/ui-react-openapi-generate-source
May 28, 2026
Merged

fix(ui-react): generate client from combined spec for npm run generate#6387
gustavosbarreto merged 1 commit into
masterfrom
fix/ui-react-openapi-generate-source

Conversation

@gustavosbarreto
Copy link
Copy Markdown
Member

Fixes #6386.

npm run generate for @shellhub/console defaulted its input to http://openapi:8080/openapi/openapi.json. That URL is served by the openapi container, which picks community-openapi.yaml, enterprise-openapi.yaml, or cloud-openapi.yaml based on SHELLHUB_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 manual npm run generate after startup overwrote that client with the edition-filtered one. Easy footgun.

What changes

  • New ui-react/scripts/generate-client.sh: bundles openapi/spec/openapi.yaml via redocly into /tmp/openapi.json and runs openapi-ts. If OPENAPI_SPEC_PATH is already set (the production Dockerfile builder stage does this), it skips the bundle step and uses that spec.
  • apps/console/package.json: generate now calls the script.
  • openapi-ts.config.ts: throws if OPENAPI_SPEC_PATH is unset, with a message pointing at npm run generate. The old HTTP fallback was the bug source.
  • scripts/entrypoint-dev.sh: replaces the inline bundle + generate with npm run generate, then starts a chokidar-cli watcher on openapi/spec/**/*.yaml in the background that re-runs the same script on changes. Vite HMR picks up the regenerated types.gen.ts without recreating the container.

The production Dockerfile is unchanged: its builder stage still bundles into apps/console/openapi.json and runs OPENAPI_SPEC_PATH=./openapi.json npm run generate -w @shellhub/console, which the new script honors.

`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
@gustavosbarreto gustavosbarreto requested a review from a team as a code owner May 28, 2026 17:26
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 28, 2026

Claude finished @gustavosbarreto's task in 55s —— View job


Code Review Complete

Reviewed 4 files across code quality, security, testing, language patterns, and architecture — no issues found. The code looks good as-is.

Highlights:

  • The openapi-ts.config.ts guard correctly prevents the footgun of generating from the edition-filtered URL.
  • generate-client.sh cleanly centralizes the bundle+generate logic with proper set -e and OPENAPI_SPEC_PATH pass-through for the Dockerfile builder stage.
  • The Dockerfile production build path was verified unchanged — the spec-bundler stage pre-bundles and the builder stage sets OPENAPI_SPEC_PATH, which the new script honors by skipping the bundle step.
  • The chokidar watcher in entrypoint-dev.sh is a nice DX improvement for hot-reloading spec changes without container restarts.
  • No cross-repo impact on the cloud/enterprise repos.

To request another review round, comment /review.


@gustavosbarreto gustavosbarreto merged commit c10a8aa into master May 28, 2026
13 checks passed
@gustavosbarreto gustavosbarreto deleted the fix/ui-react-openapi-generate-source branch May 28, 2026 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ui-react: regenerate openapi client on spec changes without container recreate

1 participant