Skip to content

Commit 0fc085f

Browse files
authored
Allow customizing APIs in WorkspaceClient/AccountClient (#213)
## Changes Feature request from @satviksr-db, allowing him to provide custom implementations of the top-level API. This mirrors what we've done in the Go SDK. ## Tests No tests needed, as this isn't a behavior change.
1 parent eef68f1 commit 0fc085f

File tree

5 files changed

+671
-188
lines changed

5 files changed

+671
-188
lines changed

.codegen/account.java.tmpl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,14 @@ public class AccountClient {
4545
}
4646
{{end}}{{end}}
4747
{{range .Services}}{{if .IsAccounts}}
48-
/** Override {{.PascalName}}API with mock */
48+
/** Replace the default {{.PascalName}}Service with a custom implementation. */
4949
public AccountClient with{{(.TrimPrefix "account").PascalName}}Impl({{.PascalName}}Service {{.CamelName}}) {
50-
{{(.TrimPrefix "account").CamelName}}API = new {{.PascalName}}API({{.CamelName}});
50+
return this.with{{(.TrimPrefix "account").PascalName}}API(new {{.PascalName}}API({{.CamelName}}));
51+
}
52+
53+
/** Replace the default {{.PascalName}}API with a custom implementation. */
54+
public AccountClient with{{(.TrimPrefix "account").PascalName}}API({{.PascalName}}API {{.CamelName}}) {
55+
this.{{(.TrimPrefix "account").CamelName}}API = {{.CamelName}};
5156
return this;
5257
}
5358
{{end}}{{end}}

.codegen/workspace.java.tmpl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,14 @@ public class WorkspaceClient {
6363
}
6464
{{end}}{{end}}
6565
{{range .Services}}{{if not .IsAccounts}}
66-
/** Replace {{.PascalName}}API implementation with mock */
66+
/** Replace the default {{.PascalName}}Service with a custom implementation. */
6767
public WorkspaceClient with{{.PascalName}}Impl({{.PascalName}}Service {{.CamelName}}) {
68-
{{.CamelName}}API = new {{template "api" .}}({{.CamelName}});
68+
return this.with{{.PascalName}}API(new {{template "api" .}}({{.CamelName}}));
69+
}
70+
71+
/** Replace the default {{.PascalName}}API with a custom implementation. */
72+
public WorkspaceClient with{{.PascalName}}API({{template "api" .}} {{.CamelName}}) {
73+
this.{{.CamelName}}API = {{.CamelName}};
6974
return this;
7075
}
7176
{{end}}{{end}}

databricks-sdk-java/src/main/java/com/databricks/sdk/AccountClient.java

Lines changed: 184 additions & 50 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)