Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions ui-react/apps/console/openapi-ts.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { defineConfig } from "@hey-api/openapi-ts";

const input = process.env.OPENAPI_SPEC_PATH;
if (!input) {
// The openapi container only serves the spec for the active edition, so
// generating from its URL produces a client missing the other editions'
// schemas. Use `npm run generate -w @shellhub/console`, which bundles the
// combined spec before invoking openapi-ts.
throw new Error("OPENAPI_SPEC_PATH is not set; run `npm run generate -w @shellhub/console`.");
}

export default defineConfig({
input:
process.env.OPENAPI_SPEC_PATH || "http://openapi:8080/openapi/openapi.json",
input,
output: "src/client",
plugins: [
"@hey-api/typescript",
Expand Down
2 changes: 1 addition & 1 deletion ui-react/apps/console/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"lint": "eslint src",
"test": "vitest run",
"test:watch": "vitest",
"generate": "openapi-ts"
"generate": "../../scripts/generate-client.sh"
},
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.6.0",
Expand Down
12 changes: 7 additions & 5 deletions ui-react/scripts/entrypoint-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ SCRIPTS_DIR="$(dirname "$(readlink -f "$0")")"
mkdir -p apps/console/public
"$SCRIPTS_DIR/gen-config.sh" apps/console/public/config.json

# Generate OpenAPI client from the combined spec (all editions)
echo "Bundling OpenAPI spec..."
npx @redocly/cli@1.0.0-beta.100 bundle /openapi/spec/openapi.yaml -o /tmp/openapi.json --force
echo "Generating OpenAPI client..."
OPENAPI_SPEC_PATH=/tmp/openapi.json npx -w @shellhub/console openapi-ts
# Generate the OpenAPI client from the combined spec, then keep regenerating
# it whenever any spec file changes so Vite HMR picks up the new types
# without needing to recreate the container.
npm run generate -w @shellhub/console
# chokidar-cli shells out to $SHELL, which isn't set in this alpine image.
SHELL=/bin/sh npx -y chokidar-cli@3.0.0 '/openapi/spec/**/*.yaml' --debounce 500 \
-c 'npm run generate -w @shellhub/console' &

npm run dev:console
14 changes: 14 additions & 0 deletions ui-react/scripts/generate-client.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh
set -e

# Bundle the combined OpenAPI spec (all editions) and generate the typed
# client. The Dockerfile builder stage sets OPENAPI_SPEC_PATH to a spec
# it bundled in an earlier stage; skip the bundle step in that case.
if [ -z "$OPENAPI_SPEC_PATH" ]; then
npx @redocly/cli@1.0.0-beta.100 bundle /openapi/spec/openapi.yaml -o /tmp/openapi.json --force
OPENAPI_SPEC_PATH=/tmp/openapi.json
export OPENAPI_SPEC_PATH
fi

cd "$(dirname "$0")/../apps/console"
exec npx openapi-ts
Loading