Skip to content

✨ Add a client based on operationId#129

Merged
NatoBoram merged 4 commits into
mainfrom
feature/operation-id-client
Jun 22, 2026
Merged

✨ Add a client based on operationId#129
NatoBoram merged 4 commits into
mainfrom
feature/operation-id-client

Conversation

@NatoBoram

@NatoBoram NatoBoram commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Removed deprecated Bitbucket Cloud Add-on “linkers” endpoints.
    • Updated pull request status types; DRAFT and QUEUED are no longer supported.
  • New Features

    • Added automated OpenAPI-based client generation.
    • Added client creation helpers for both Bitbucket Cloud and Bitbucket Server.
  • Documentation

    • Updated README usage examples to reflect class-based client usage and pnpm add.
  • Chores

    • Updated OpenAPI tooling scripts/config and development dependencies.
    • Updated/added tests for the new client APIs.

Signed-off-by: Nathan Gendron <nato@coderabbit.ai>
@NatoBoram NatoBoram self-assigned this Jun 22, 2026
@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The Bitbucket Cloud Swagger spec is refreshed (deprecated /addon/linkers* endpoints removed, PR state enum narrowed to OPEN/MERGED/DECLINED/SUPERSEDED). createBitbucketCloudClient and createBitbucketServerClient factories are moved into dedicated create_client.ts modules. A new scripts/generate_clients.ts + scripts/openapi.sh pipeline automates typed client class generation from OpenAPI specs. README documentation is updated to showcase class-based client instantiation.

Changes

OpenAPI Spec Refresh, Factory Extraction, and Code-Gen Pipeline

Layer / File(s) Summary
Swagger spec refresh and generated type update
src/cloud/openapi/swagger.v3.json, src/cloud/openapi/openapi-typescript.ts
Removes deprecated /addon/linkers* paths, bumps x-revision, and narrows the PR state enum to OPEN | MERGED | DECLINED | SUPERSEDED in both the raw spec and the generated TypeScript types.
create_client factory modules and public API wiring
src/cloud/create_client.ts, src/server/create_client.ts, src/cloud/index.ts, src/server/index.ts, src/cloud/create_client.test.ts, src/server/create_client.test.ts, src/cloud/client.test.ts, src/server/client.test.ts, src/cloud/interfaces/paths.test.ts
Extracts createBitbucketCloudClient and createBitbucketServerClient into their own modules, re-exports them from each barrel index.ts, updates client.test.ts files to instantiate the generated class directly, adds dedicated factory tests, and fixes the import path in paths.test.ts.
Code-generation pipeline: scripts and tooling config
scripts/generate_clients.ts, scripts/openapi.sh, package.json, tsconfig.eslint.json
Adds generate_clients.ts to parse OpenAPI specs and emit typed client class files; adds openapi.sh to orchestrate spec download, type generation, autofix, client generation, and lint; wires an openapi npm script; adds openapi-typescript-helpers to devDependencies; and extends tsconfig.eslint.json to include scripts/.
Documentation updates for client usage
README.md
Updates installation guidance from pnpm i to pnpm add and replaces factory-function usage examples with class-based instantiation (BitbucketCloudClient and BitbucketServerClient), clarifying method naming via operationId.

Sequence Diagram(s)

sequenceDiagram
  participant Dev as Developer
  participant openapi_sh as openapi.sh
  participant curl as curl
  participant openapi_ts as openapi-typescript
  participant gen_clients as generate_clients.ts
  participant lint as pnpm lint:fix

  Dev->>openapi_sh: pnpm run openapi
  openapi_sh->>curl: fetch Cloud Swagger JSON
  openapi_sh->>openapi_ts: emit src/cloud/openapi/openapi-typescript.ts
  openapi_sh->>curl: fetch Server Swagger JSON
  openapi_sh->>openapi_ts: emit src/server/openapi/openapi-typescript.ts
  openapi_sh->>gen_clients: node generate_clients.ts
  gen_clients-->>openapi_sh: src/cloud/client.ts + src/server/client.ts
  openapi_sh->>lint: pnpm run lint:fix
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

enhancement, dependencies, documentation, javascript

Poem

🐰 A hop through the spec, old linkers goodbye,
The state enum trimmed — no DRAFT in the sky.
New factories sprouted from modules so clean,
A script spins up clients from JSON unseen.
With openapi.sh the pipeline runs free,
This rabbit types fast — typed clients for thee! 🎉

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning No pull request description was provided by the author, leaving key context about why the changes were made and implementation details unexplained. Add a detailed description explaining the motivation, implementation approach, and benefits of the operationId-based client generation. Reference relevant issues or discussions.
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title succinctly describes the main change: adding a client based on operationId, which aligns with the introduction of BitbucketCloudClient and BitbucketServerClient classes generated from OpenAPI specs.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/operation-id-client

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 OpenGrep (1.23.0)
scripts/generate_clients.ts

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

[00.11][ERROR]: unable to find a config; path .coderabbit-opengrep-fallback.yml does not exist

src/cloud/client.ts

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

[00.11][ERROR]: unable to find a config; path .coderabbit-opengrep-fallback.yml does not exist

🔧 markdownlint-cli2 (0.22.1)
README.md

markdownlint-cli2 v0.22.1 (markdownlint v0.40.0)
Error: Unable to use configuration file '/coderabbit-0.markdownlint-cli2.jsonc'; ENOENT: no such file or directory, open '/coderabbit-0.markdownlint-cli2.jsonc'
at throwForConfigurationFile (file:///usr/local/lib/node_modules/markdownlint-cli2/markdownlint-cli2.mjs:48:9)
at readOptionsOrConfig (file:///usr/local/lib/node_modules/markdownlint-cli2/markdownlint-cli2.mjs:169:5)
at async main (file:///usr/local/lib/node_modules/markdownlint-cli2/markdownlint-cli2.mjs:927:21)
at async file:///usr/local/lib/node_modules/markdownlint-cli2/markdownlint-cli2-bin.mjs:14:22 {
[cause]: Error: ENOENT: no such file or directory, open '/coderabbit-0.markdownlint-cli2.jsonc'
at async open (node:internal/fs/promises:640:25)
at async Object.readFile (node:internal/fs/promises:1287:14)
at async readOptionsOrConfig (file:///usr/local/lib/node_modules/markdownlint-cli2/markdownlint-cli2.mjs:141:17)
at async main (file:///usr/local/lib/node_modules/markdownlint-cli2/markdownlint-cli2.mjs:927:21)
at async file:///usr/local/lib/node_modules/markdownlint-cli2/markdownlint-cli2-bin.mjs:14:22 {
errno: -2,
code: 'ENOENT',
syscall: 'open',
path: '/coderabbit-0.markdownlint-cli2.jsonc'
}
}


Comment @coderabbitai help to get the list of available commands and usage tips.

@NatoBoram NatoBoram marked this pull request as ready for review June 22, 2026 17:10
@NatoBoram NatoBoram requested a review from a team as a code owner June 22, 2026 17:10
@NatoBoram NatoBoram requested review from krtkvrm and santoshyadavdev and removed request for a team June 22, 2026 17:10

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
src/server/create_client.test.ts (1)

4-7: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Consider enhancing test coverage.

The current test only verifies that createBitbucketServerClient returns a defined object. Consider adding assertions to verify the returned client has the expected GET, POST, etc. methods from the openapi-fetch client interface, or test that configuration options are properly passed through.

💡 Example enhanced test
test("createBitbucketServerClient", ({ expect }) => {
	const client = createBitbucketServerClient()
	expect(client).toBeDefined()
	expect(client.GET).toBeDefined()
	expect(client.POST).toBeDefined()
})

test("createBitbucketServerClient with options", ({ expect }) => {
	const client = createBitbucketServerClient({
		baseUrl: "https://example.org/rest",
	})
	expect(client).toBeDefined()
})
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/server/create_client.test.ts` around lines 4 - 7, The test for
createBitbucketServerClient only verifies that the client object is defined but
does not validate the client's structure or functionality. Enhance the test by
adding assertions that verify the returned client has the expected HTTP methods
(GET, POST, etc.) from the openapi-fetch client interface. Additionally, add a
separate test case that verifies configuration options like baseUrl are properly
passed through when createBitbucketServerClient is called with options, ensuring
both the client's API surface and its configuration handling are properly
tested.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/generate_clients.ts`:
- Around line 112-113: The import statement for InitParam is using an internal
source path instead of the public API entry point. Change the import statement
for InitParam from "openapi-fetch/src/index.js" to use the main entry point
"openapi-fetch" directly. This ensures the code relies on the package's public
contract rather than internal implementation details that may change.
- Around line 70-76: The JSDoc template string in the jsdoc variable
construction can output literal "undefined" text when summary or description is
missing or undefined. Fix this by providing default values for summary and
description before they are interpolated into the template string. Use the
logical OR operator or optional chaining with nullish coalescing to ensure
summary defaults to an empty string or appropriate placeholder when undefined,
and similarly ensure the description mapping logic only executes when
description is a valid string, preventing undefined or empty strings from being
included in the generated JSDoc comment output.

In `@scripts/openapi.sh`:
- Around line 1-15: The shell script lacks strict error handling, which allows
it to continue executing even after partial failures from curl HTTP errors or
command failures, potentially producing invalid generated clients. Add `set -e`
at the beginning of the script to make it exit immediately on any command
failure, and add the `--fail` flag to all three curl commands (the ones fetching
swagger.v3.json for Bitbucket Cloud and Bitbucket Data Center) to ensure curl
exits with an error status on HTTP failures rather than silently continuing with
empty or partial responses.

---

Nitpick comments:
In `@src/server/create_client.test.ts`:
- Around line 4-7: The test for createBitbucketServerClient only verifies that
the client object is defined but does not validate the client's structure or
functionality. Enhance the test by adding assertions that verify the returned
client has the expected HTTP methods (GET, POST, etc.) from the openapi-fetch
client interface. Additionally, add a separate test case that verifies
configuration options like baseUrl are properly passed through when
createBitbucketServerClient is called with options, ensuring both the client's
API surface and its configuration handling are properly tested.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Central YAML (base), Repository UI (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: 85ef456d-d660-4c53-805b-c32b5077a357

📥 Commits

Reviewing files that changed from the base of the PR and between 493a6d8 and 95b98a9.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (18)
  • package.json
  • scripts/generate_clients.ts
  • scripts/openapi.sh
  • scripts/pnpm_version_patch.sh
  • src/cloud/client.test.ts
  • src/cloud/client.ts
  • src/cloud/create_client.test.ts
  • src/cloud/create_client.ts
  • src/cloud/index.ts
  • src/cloud/interfaces/paths.test.ts
  • src/cloud/openapi/openapi-typescript.ts
  • src/cloud/openapi/swagger.v3.json
  • src/server/client.test.ts
  • src/server/client.ts
  • src/server/create_client.test.ts
  • src/server/create_client.ts
  • src/server/index.ts
  • tsconfig.eslint.json
💤 Files with no reviewable changes (1)
  • scripts/pnpm_version_patch.sh

Comment thread scripts/generate_clients.ts Outdated
Comment thread scripts/generate_clients.ts
Comment thread scripts/openapi.sh
Signed-off-by: Nathan Gendron <nato@coderabbit.ai>
Signed-off-by: Nathan Gendron <nato@coderabbit.ai>
Signed-off-by: Nathan Gendron <nato@coderabbit.ai>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
README.md (2)

18-39: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Clarify which Cloud entry point this example is showing.

The prose says class-based usage, but this snippet still demonstrates createBitbucketCloudClient. Either switch the example to BitbucketCloudClient or explicitly label this as the factory form; mixing both patterns here will confuse readers.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@README.md` around lines 18 - 39, The prose introduces usage of the
BitbucketCloudClient class but the code example demonstrates the
createBitbucketCloudClient factory function instead. Either update the
introductory text to clarify that this example shows the factory function
approach, or replace the code example to demonstrate actual BitbucketCloudClient
class instantiation and usage instead of the factory function
createBitbucketCloudClient.

62-92: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Separate the Server factory and class examples.

This section also blends the factory helper and the new class API: the first snippet instantiates createBitbucketServerClient, while the surrounding text frames the class as the documented path. Please make the section consistently describe one entry point, or clearly split the two.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@README.md` around lines 62 - 92, The README.md Server section shows two
different ways to instantiate a Bitbucket client (the
createBitbucketServerClient factory function and the BitbucketServerClient class
constructor), but the introductory text only frames the class as the documented
approach, creating inconsistency. Either remove the factory function example and
keep only the BitbucketServerClient class constructor example, or clearly add
section headers and introductory text that explicitly explains both approaches
as alternative ways to create the client, making it obvious to readers that both
are valid options.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@README.md`:
- Around line 18-39: The prose introduces usage of the BitbucketCloudClient
class but the code example demonstrates the createBitbucketCloudClient factory
function instead. Either update the introductory text to clarify that this
example shows the factory function approach, or replace the code example to
demonstrate actual BitbucketCloudClient class instantiation and usage instead of
the factory function createBitbucketCloudClient.
- Around line 62-92: The README.md Server section shows two different ways to
instantiate a Bitbucket client (the createBitbucketServerClient factory function
and the BitbucketServerClient class constructor), but the introductory text only
frames the class as the documented approach, creating inconsistency. Either
remove the factory function example and keep only the BitbucketServerClient
class constructor example, or clearly add section headers and introductory text
that explicitly explains both approaches as alternative ways to create the
client, making it obvious to readers that both are valid options.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Central YAML (base), Repository UI (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: bb4e1457-3990-4c37-a37d-1b722f407683

📥 Commits

Reviewing files that changed from the base of the PR and between 95b98a9 and faeaad0.

📒 Files selected for processing (4)
  • README.md
  • scripts/generate_clients.ts
  • scripts/openapi.sh
  • src/cloud/client.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • scripts/openapi.sh
  • scripts/generate_clients.ts

@NatoBoram NatoBoram added this pull request to the merge queue Jun 22, 2026
Merged via the queue into main with commit 85b2454 Jun 22, 2026
3 checks passed
@NatoBoram NatoBoram deleted the feature/operation-id-client branch June 22, 2026 20:58
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.

1 participant