Skip to content

feat: add js_openapi_schema macro#722

Open
agentydragon-agent wants to merge 3 commits intoagentydragon:develfrom
agentydragon-agent:claude/setup-openapi-schema-build-T5XZM
Open

feat: add js_openapi_schema macro#722
agentydragon-agent wants to merge 3 commits intoagentydragon:develfrom
agentydragon-agent:claude/setup-openapi-schema-build-T5XZM

Conversation

@agentydragon-agent
Copy link
Copy Markdown
Contributor

Summary

  • Adds tools/js/openapi.bzl with a new js_openapi_schema(name, generator, out) macro that bundles the full OpenAPI → TypeScript type generation pipeline into a single Bazel call
  • Replaces ~20 lines of boilerplate (genrule + openapi-typescript binary + js_run_binary + js_library across two files) with one call in props/frontend/src/lib/BUILD.bazel
  • Removes the now-redundant openapi_schema genrule from props/backend/BUILD.bazel and the generate_schema_bin js_binary + openapi_schema_local genrule from props/frontend/BUILD.bazel
  • Deletes props/frontend/generate-schema.mjs (replaced by the openapi-typescript CLI invoked directly via npm package_json.bzl)

Before (spread across props/frontend/BUILD.bazel and props/frontend/src/lib/BUILD.bazel):

js_binary(name = "generate_schema_bin", ...)
genrule(name = "openapi_schema_local", srcs = ["//props/backend:openapi_schema"], ...)
# in src/lib:
js_run_binary(name = "_generate_schema_run", ...)
js_library(name = "schema", srcs = [":_generate_schema_run"], tags = ["no-lint"])

After (one line in props/frontend/src/lib/BUILD.bazel):

js_openapi_schema(
    name = "schema",
    generator = "//props/backend:export_schema_bin",
)

Test plan

  • bazel build //props/frontend/src/lib:schema builds successfully
  • bazel build //props/frontend:bundle builds successfully

https://claude.ai/code/session_01AVe4v8xDvXAH5hK6o9Yk81

tools/js/openapi.bzl: new macro js_openapi_schema(name, generator, out)
bundles the genrule + openapi-typescript binary + js_run_binary + js_library
into a single call. Eliminates ~20 lines of boilerplate per frontend package.

props/frontend/src/lib/BUILD.bazel: replace four rules across two files with
  js_openapi_schema(name = "schema", generator = "//props/backend:export_schema_bin")

props/backend/BUILD.bazel: remove openapi_schema genrule (macro runs the binary
directly, no intermediate target needed).

props/frontend/BUILD.bazel: remove generate_schema_bin js_binary and
openapi_schema_local genrule (both replaced by the macro).

props/frontend/generate-schema.mjs: deleted (replaced by openapi-typescript CLI
invoked directly via the npm package_json.bzl binary macro).

https://claude.ai/code/session_01AVe4v8xDvXAH5hK6o9Yk81
My local sandbox had pnpm v6 which downgraded the lockfile format from 9.0 to
6.0. Since no new npm packages were added, revert to the original format so CI
can resolve npm packages correctly.

https://claude.ai/code/session_01AVe4v8xDvXAH5hK6o9Yk81
rules_js 2.9.2 defaults to pnpm 8.6.11 which cannot parse lockfileVersion 9
lockfiles. On every fresh CI run this triggers a non-hermetic regeneration via
system pnpm, failing with "pnpm-lock.yaml file updated. Please run your build
again." which kills the entire npm_ducktape repository.

Fix: declare the pnpm extension with pnpm_version = "9.15.9" (+ integrity
hash) and set use_pnpm on npm_translate_lock to point at the new @pnpm
toolchain. The hermetic pnpm v9 can read the committed v9 lockfile without
regenerating it, so the first Bazel run on CI succeeds.

https://claude.ai/code/session_01AVe4v8xDvXAH5hK6o9Yk81
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.

2 participants