Skip to content

feat: automate frontend API regeneration during live development - #1291

Open
prakharsingh-74 wants to merge 5 commits into
kubeflow:notebooks-v2from
prakharsingh-74:frontend-API-regeneration
Open

feat: automate frontend API regeneration during live development#1291
prakharsingh-74 wants to merge 5 commits into
kubeflow:notebooks-v2from
prakharsingh-74:frontend-API-regeneration

Conversation

@prakharsingh-74

Copy link
Copy Markdown

closes: #857

Description

Currently, the swagger.version Git-hash mechanism prevents the core benefit of Tilt—live iterative development across backend and frontend components—from working when backend API changes are introduced. Uncommitted backend changes are not captured by the Git history, causing local API client generation (npm run generate:api) to fail or fetch outdated schemas.

  1. Automatic Generation in Tilt:

    • Added a backend-swagger local_resource in the Tiltfile that watches backend Go files and automatically runs make swag on the host to update the local openapi/swagger.json.
    • Added a frontend-api-generate local_resource in the Tiltfile that watches openapi/swagger.json and runs npm run generate:api on the host.
    • Updated the resource dependency graph so that the workspace containers wait for their respective generation resources to complete before deploying.
  2. Conditional Local Swagger Generation:

    • Modified generate-api.sh to check for USE_LOCAL_SWAGGER=true or DEV_ENV=tilt. When active, it directly reads the local swagger.json path or fetches it from a running container URL (using Node.js's built-in fetch to keep container dependencies lean) rather than querying git history.
    • Added CRLF stripping to ensure the Git-hash check works reliably on Windows developer hosts.
    • Prefixed the generate:api npm script command with bash for native Windows execution compatibility.
  3. Documentation:

    • Documented the new automated API client regeneration flow in DEVELOPMENT_GUIDE.md.

How to Verify

  1. Verify Local Generation on Host:

    • Run $env:USE_LOCAL_SWAGGER="true"; npm run generate:api (Windows PowerShell) or USE_LOCAL_SWAGGER=true npm run generate:api (macOS/Linux/Git Bash) inside workspaces/frontend. Verify it generates types using the local swagger.json.
  2. Verify Git-Based Generation (CI/Production Mode):

    • Run npm run generate:api without setting the environment variable. Verify it falls back to the original git-hash-based generation.
  3. Verify Tilt E2E Loop:

    • Start Tilt via make tilt-up in developing/.
    • Modify a backend Go struct/handler. Verify that:
      1. Tilt runs make swag locally.
      2. Tilt runs generate-api.sh to update the TypeScript types in src/generated/.
      3. Webpack dev server HMR is triggered inside the frontend container.

Signed-off-by: prakharsingh-74 <prakharsingh7014@gmail.com>
@google-oss-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign andyatmiami, ederign for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@google-oss-prow google-oss-prow Bot added area/frontend area - related to frontend components area/v2 area - version - kubeflow notebooks v2 size/M labels Jul 31, 2026
@prakharsingh-74 prakharsingh-74 changed the title feat(tilt): automate frontend API regeneration during live development feat: automate frontend API regeneration during live development Jul 31, 2026
@prakharsingh-74

Copy link
Copy Markdown
Author

cc: @andyatmiami

@prakharsingh-74

Copy link
Copy Markdown
Author

@andreyvelich sir, can you review this PR if you're free.

@christian-heusel christian-heusel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your contribution, I have left a few review comments below 🤗

A few general notes:

  • Did you use AI in any capacity while creating this contribution? I see that your commit does not carry a Assisted-By: <...> tag, so I wanted to make sure that you're aware of the Kubeflow AI Policy. 🤗 🤖
  • Please do not ping external maintainers for your PR, it's okay to make a bit of noise if a PR goes without review, however for example Andrey does not know anything about the codebase here and will not be available to review your changes.
  • This is more of a preference thing, but if you rebase your changes against notebooks-v2 instead of merging this keeps the history more clean.

"build:clean": "rimraf ./dist",
"build:prod": "webpack --config ./config/webpack.prod.js",
"generate:api": "./scripts/generate-api.sh && npm run prettier",
"generate:api": "bash ./scripts/generate-api.sh && npm run prettier",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to explicitly execute this script with bash? 🤔
The script already has this as shebang, so my intuition would be that this can be dropped 🤔

Comment on lines +13 to +14
if [[ "$SWAGGER_JSON_PATH" =~ ^https?:// ]]; then
node -e "fetch('$SWAGGER_JSON_PATH').then(r => { if (!r.ok) throw new Error('status ' + r.status); return r.text(); }).then(t => process.stdout.write(t)).catch(e => { console.error(e); process.exit(1); })" > "$TMP_SWAGGER"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this is not the right approach to the issue we're fixing, why are we fetching this file from a remote endpoint instead of just using the one on disk or regenerating it in a temporary directory? 🤔

HASH_FILE="./scripts/swagger.version"
SWAGGER_COMMIT_HASH=$(cat "$HASH_FILE")
SWAGGER_JSON_PATH="../backend/openapi/swagger.json"
SWAGGER_COMMIT_HASH=$(tr -d '\r\n' < "$HASH_FILE")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line ending here is not guaranteed to be \r\n, on linux this will just be \n. Probably we should also fix this in .gitattributes so it is predictable accross both os types.

See https://stackoverflow.com/a/426404

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/ci area - related to ci area/frontend area - related to frontend components area/v2 area - version - kubeflow notebooks v2 size/M

Projects

Status: Needs Triage

Development

Successfully merging this pull request may close these issues.

2 participants