From a1460c561c13fd3005080edf2392c8c3a6fb0e95 Mon Sep 17 00:00:00 2001 From: Parth Bansal Date: Thu, 31 Oct 2024 12:37:54 +0100 Subject: [PATCH] [Internal] Move templates in the code generator (#373) ## Changes Move templates in the code generator. ## Tests The generator is working correctly with the new configuration. --- .codegen.json | 24 +--- .codegen/account.java.tmpl | 75 ---------- .codegen/api.java.tmpl | 219 ----------------------------- .codegen/error-mapper.java.tmpl | 15 -- .codegen/error-overrides.java.tmpl | 24 ---- .codegen/exception.java.tmpl | 25 ---- .codegen/impl.java.tmpl | 79 ----------- .codegen/interface.java.tmpl | 25 ---- .codegen/lib.tmpl | 26 ---- .codegen/model.java.tmpl | 87 ------------ .codegen/workspace.java.tmpl | 84 ----------- 11 files changed, 2 insertions(+), 681 deletions(-) delete mode 100644 .codegen/account.java.tmpl delete mode 100644 .codegen/api.java.tmpl delete mode 100644 .codegen/error-mapper.java.tmpl delete mode 100644 .codegen/error-overrides.java.tmpl delete mode 100644 .codegen/exception.java.tmpl delete mode 100644 .codegen/impl.java.tmpl delete mode 100644 .codegen/interface.java.tmpl delete mode 100644 .codegen/lib.tmpl delete mode 100644 .codegen/model.java.tmpl delete mode 100644 .codegen/workspace.java.tmpl diff --git a/.codegen.json b/.codegen.json index 9a8816c6e..b823e4a2f 100644 --- a/.codegen.json +++ b/.codegen.json @@ -1,26 +1,6 @@ { - "formatter": "mvn spotless:apply", + "mode": "java_v0", "changelog_config": ".codegen/changelog_config.yml", - "template_libraries": [ - ".codegen/lib.tmpl" - ], - "types": { - ".codegen/model.java.tmpl": "databricks-sdk-java/src/main/java/com/databricks/sdk/service/{{.Package.Name}}/{{.PascalName}}.java" - }, - "services": { - ".codegen/interface.java.tmpl": "databricks-sdk-java/src/main/java/com/databricks/sdk/service/{{.Package.Name}}/{{.PascalName}}Service.java", - ".codegen/api.java.tmpl": "databricks-sdk-java/src/main/java/com/databricks/sdk/service/{{.Package.Name}}/{{.PascalName}}API.java", - ".codegen/impl.java.tmpl": "databricks-sdk-java/src/main/java/com/databricks/sdk/service/{{.Package.Name}}/{{.PascalName}}Impl.java" - }, - "exception_types": { - ".codegen/exception.java.tmpl": "databricks-sdk-java/src/main/java/com/databricks/sdk/core/error/platform/{{.PascalName}}.java" - }, - "batch": { - ".codegen/workspace.java.tmpl": "databricks-sdk-java/src/main/java/com/databricks/sdk/WorkspaceClient.java", - ".codegen/account.java.tmpl": "databricks-sdk-java/src/main/java/com/databricks/sdk/AccountClient.java", - ".codegen/error-mapper.java.tmpl": "databricks-sdk-java/src/main/java/com/databricks/sdk/core/error/ErrorMapper.java", - ".codegen/error-overrides.java.tmpl": "databricks-sdk-java/src/main/java/com/databricks/sdk/core/error/ErrorOverrides.java" - }, "version": { "pom.xml": "databricks-sdk-parent\n $VERSION", "databricks-sdk-java/pom.xml": "databricks-sdk-parent\n $VERSION", @@ -32,6 +12,6 @@ "toolchain": { "require": ["mvn", "java"], "setup": ["rm -rf databricks-sdk-java/src/main/java/com/databricks/sdk/service"], - "post_generate": ["mvn --errors clean test"] + "post_generate": ["mvn spotless:apply","mvn --errors clean test"] } } diff --git a/.codegen/account.java.tmpl b/.codegen/account.java.tmpl deleted file mode 100644 index 71307f9a2..000000000 --- a/.codegen/account.java.tmpl +++ /dev/null @@ -1,75 +0,0 @@ -// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. - -package com.databricks.sdk; - -import com.databricks.sdk.core.ApiClient; -import com.databricks.sdk.core.ConfigLoader; -import com.databricks.sdk.core.DatabricksConfig; -import com.databricks.sdk.core.utils.AzureUtils; -import com.databricks.sdk.service.provisioning.*; -{{range .Services}}{{if and .IsAccounts (not .IsDataPlane)}} -import com.databricks.sdk.service.{{.Package.Name}}.{{.PascalName}}API; -import com.databricks.sdk.service.{{.Package.Name}}.{{.PascalName}}Service;{{end}}{{end}} -import com.databricks.sdk.support.Generated; - -/** - * Entry point for accessing Databricks account-level APIs - */ -@Generated -public class AccountClient { - private final ApiClient apiClient; - private final DatabricksConfig config; - {{range .Services}}{{if and .IsAccounts (not .HasParent) (not .IsDataPlane)}} - private {{.PascalName}}API {{(.TrimPrefix "account").CamelName}}API;{{end}}{{end}} - - public AccountClient() { - this(ConfigLoader.getDefault()); - } - - public AccountClient(DatabricksConfig config) { - this.config = config; - apiClient = new ApiClient(config); - {{range .Services}}{{if and .IsAccounts (not .HasParent) (not .IsDataPlane)}} - {{(.TrimPrefix "account").CamelName}}API = new {{.PascalName}}API(apiClient);{{end}}{{end}} - } - - /** Constructor for mocks */ - public AccountClient(boolean mock) { - apiClient = null; - config = null; - } - {{range .Services}}{{if and .IsAccounts (not .HasParent) (not .IsDataPlane)}} - {{if .Description}}/** - {{.Comment " * " 80}} - */{{end}} - public {{.PascalName}}API {{(.TrimPrefix "account").CamelName}}() { - return {{(.TrimPrefix "account").CamelName}}API; - } - {{end}}{{end}} - {{range .Services}}{{if and .IsAccounts (not .HasParent) (not .IsDataPlane)}} - /** Replace the default {{.PascalName}}Service with a custom implementation. */ - public AccountClient with{{(.TrimPrefix "account").PascalName}}Impl({{.PascalName}}Service {{.CamelName}}) { - return this.with{{(.TrimPrefix "account").PascalName}}API(new {{.PascalName}}API({{.CamelName}})); - } - - /** Replace the default {{.PascalName}}API with a custom implementation. */ - public AccountClient with{{(.TrimPrefix "account").PascalName}}API({{.PascalName}}API {{.CamelName}}) { - this.{{(.TrimPrefix "account").CamelName}}API = {{.CamelName}}; - return this; - } - {{end}}{{end}} - public ApiClient apiClient() { - return apiClient; - } - - public DatabricksConfig config() { - return config; - } - - public WorkspaceClient getWorkspaceClient(Workspace workspace) { - String host = this.config.getDatabricksEnvironment().getDeploymentUrl(workspace.getDeploymentName()); - DatabricksConfig config = this.config.newWithWorkspaceHost(host); - AzureUtils.getAzureWorkspaceResourceId(workspace).map(config::setAzureWorkspaceResourceId); - return new WorkspaceClient(config); - } -} diff --git a/.codegen/api.java.tmpl b/.codegen/api.java.tmpl deleted file mode 100644 index 72f03b506..000000000 --- a/.codegen/api.java.tmpl +++ /dev/null @@ -1,219 +0,0 @@ -// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. -package com.databricks.sdk.service.{{.Package.Name}}; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Collection; -import java.util.Map; -import java.time.Duration; -import java.util.Arrays; -import java.util.concurrent.TimeoutException; -import java.util.function.Consumer; -import java.util.function.Function; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.databricks.sdk.core.ApiClient; -import com.databricks.sdk.core.DatabricksException; -import com.databricks.sdk.support.Generated; -import com.databricks.sdk.support.Paginator; -import com.databricks.sdk.support.Wait; - -{{range .Package.ImportedEntities}} -import com.databricks.sdk.service.{{.Package.Name}}.{{.PascalName}};{{end}} - -{{if .Description}}/** - {{.Comment " * " 80}} - */{{end}} -@Generated -public class {{.PascalName}}API { - private static final Logger LOG = LoggerFactory.getLogger({{.PascalName}}API.class); - - private final {{.PascalName}}Service impl; - - {{range .Subservices}} - private {{.PascalName}}API {{.CamelName}}API; - {{end}} - - /** Regular-use constructor */ - public {{.PascalName}}API(ApiClient apiClient) { - impl = new {{.PascalName}}Impl(apiClient); - {{range .Subservices}} - {{.CamelName}}API = new {{.PascalName}}API(apiClient); - {{end}} - } - - /** Constructor for mocks */ - public {{.PascalName}}API({{.PascalName}}Service mock) { - impl = mock; - } - {{range .Waits}} - public {{.Poll.Response.PascalName}} {{.CamelName}}({{range $i, $x := .Binding}}{{if $i}}, {{end}}{{template "type" .PollField.Entity}} {{.PollField.CamelName}}{{end}}) - throws TimeoutException { - return {{.CamelName}}({{range .Binding}}{{.PollField.CamelName}}, {{end}}Duration.ofMinutes({{.Timeout}}), null); - } - - public {{.Poll.Response.PascalName}} {{.CamelName}}({{range .Binding}}{{template "type" .PollField.Entity}} {{.PollField.CamelName}}, {{end}} - Duration timeout, Consumer<{{.Poll.Response.PascalName}}> callback) throws TimeoutException { - long deadline = System.currentTimeMillis() + timeout.toMillis(); - java.util.List<{{.Status.Entity.PascalName}}> targetStates = Arrays.asList({{range $i,$x := .Success}}{{if $i}}, {{end}}{{.Entity.PascalName}}.{{.ConstantName}}{{end}});{{if .Failure}} - java.util.List<{{.Status.Entity.PascalName}}> failureStates = Arrays.asList({{range $i,$x := .Failure}}{{if $i}}, {{end}}{{.Entity.PascalName}}.{{.ConstantName}}{{end}});{{end}} - String statusMessage = "polling..."; - int attempt = 1; - while (System.currentTimeMillis() < deadline) { - {{.Poll.Response.PascalName}} poll = {{template "java-name" .Poll}}(new {{.Poll.Request.PascalName}}(){{range .Binding}}.set{{.PollField.PascalName}}({{.PollField.CamelName}}){{- end}}); - {{.Status.Entity.PascalName}} status = poll{{range .StatusPath}}.get{{.PascalName}}(){{end}}; - {{if .ComplexMessagePath -}} - statusMessage = String.format("current status: %s", status); - if (poll.get{{.MessagePathHead.PascalName}}() != null) { - statusMessage = poll{{range .MessagePath}}.get{{.PascalName}}(){{end}}; - } - {{- else if .MessagePath -}} - statusMessage = poll{{range .MessagePath}}.get{{.PascalName}}(){{end}}; - {{- else -}} - statusMessage = String.format("current status: %s", status); - {{- end}} - if (targetStates.contains(status)) { - return poll; - } - if (callback != null) { - callback.accept(poll); - }{{if .Failure -}} - if (failureStates.contains(status)) { - String msg = String.format("failed to reach {{range $i, $e := .Success}}{{if $i}} or {{end}}{{$e.ConstantName}}{{end}}, got %s: %s", status, statusMessage); - throw new IllegalStateException(msg); - } - {{end}} - String prefix = String.format("{{range $i, $b := .Binding}}{{if $i}}, {{end -}}{{.PollField.CamelName}}=%s{{- end}}"{{range .Binding}}, {{.PollField.CamelName}}{{- end}}); - int sleep = attempt; - if (sleep > 10) { - // sleep 10s max per attempt - sleep = 10; - } - LOG.info("{}: ({}) {} (sleeping ~{}s)", prefix, status, statusMessage, sleep); - try { - Thread.sleep((long) (sleep * 1000L + Math.random() * 1000)); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - throw new DatabricksException("Current thread was interrupted", e); - } - attempt++; - } - throw new TimeoutException(String.format("timed out after %s: %s", timeout, statusMessage)); - } - {{end}} - - {{range .Methods}} - {{if and .Request .Request.RequiredFields}} - public {{template "method-return-type" .}} {{template "java-name" .}}({{range $i, $p := .Request.RequiredFields -}} - {{if $i}}, {{end}}{{template "type-unboxed" .Entity }} {{.CamelName}}{{if .IsNameReserved}}Value{{end}} - {{- end}}) { - {{if or (not .Response.IsEmpty) .Wait -}}return {{end}}{{template "java-name" .}}(new {{.Request.PascalName}}(){{range .Request.RequiredFields}} - .set{{.PascalName}}({{.CamelName}}{{if .IsNameReserved}}Value{{end}}){{end}}); - } - {{end}} - - {{if .Description}}/** - {{.Comment " * " 80}} - */{{end}} - public {{template "method-return-type" .}} {{template "java-name" .}}({{if .Request}}{{template "type" .Request}} request{{end}}) { - {{template "method-call" .}} - } - {{end}} - - {{range .Subservices}} - /** - * {{.Summary}} - */ - public {{.PascalName}}API {{.PascalName}}() { - return {{.CamelName}}API; - } - {{end}} - - public {{.PascalName}}Service impl() { - return impl; - } -} - -{{define "java-name" -}} -{{.CamelName}}{{if .IsNameReserved}}Content{{end}} -{{- end}} - -{{define "method-call" -}} - {{if and .Wait (and (not .IsCrudRead) (not (eq .SnakeName "get_run"))) -}}{{template "method-call-retried" .}} - {{- else if .Pagination -}}{{template "method-call-paginated" .}} - {{- else}}{{template "method-call-default" .}}{{end}} -{{- end}} - -{{define "method-call-paginated" -}} - {{- if and .Pagination.Offset (not (eq .Path "/api/2.1/clusters/events")) -}} - request.set{{.Pagination.Offset.PascalName}}( - {{- if eq .Pagination.Increment 1 -}} - 1 - {{- else if contains .Path "/scim/v2/" -}} - 1 - {{- else -}} - 0 - {{- end}}L);{{end -}} - {{if and .Pagination.Limit (contains .Path "/scim/v2/")}} - if (request.get{{.Pagination.Limit.PascalName}}() == null) { - request.set{{.Pagination.Limit.PascalName}}(100L); - }{{end -}} - return new Paginator<>( - {{ if .Request }}request{{ else }}null{{ end }}, - {{ if .Request }}impl::{{template "java-name" .}}{{ else }}(Void v) -> impl.{{template "java-name" .}}(){{ end }}, - {{template "type" .Response}}::get{{.Pagination.Results.PascalName}}, - response -> - {{ if not .Pagination.MultiRequest }} - null - {{- else if eq .Path "/api/2.1/clusters/events" -}} - response.getNextPage() - {{- else if .Pagination.Token -}} - { - String token = response.get{{.Pagination.Token.Bind.PascalName}}(); - if (token == null || token.isEmpty()) { - return null; - } - return request.set{{.Pagination.Token.PollField.PascalName}}(token); - } - {{- else if eq .Pagination.Increment 1 -}} - { - Long page = request.get{{.Pagination.Offset.PascalName}}(); - if (page == null) { - page = 1L; // redash uses 1-based pagination - } - return request.set{{.Pagination.Offset.PascalName}}(page+1L); - } - {{- else -}} - { - Long offset = request.get{{.Pagination.Offset.PascalName}}(); - if (offset == null) { - offset = 0L; - } - offset += response.get{{.Pagination.Results.PascalName}}().size(); - return request.set{{.Pagination.Offset.PascalName}}(offset); - } - {{- end}} - ){{if .NeedsOffsetDedupe -}}.withDedupe({{.Pagination.Entity.PascalName}}::get{{.IdentifierField.PascalName}}){{end}}; -{{- end}} - -{{define "method-call-retried" -}} - {{if not .Response.IsEmpty}}{{.Response.PascalName}} response = {{end}}impl.{{template "java-name" .}}(request); - return new Wait<>((timeout, callback) -> {{.Wait.CamelName}}({{range .Wait.Binding}}{{if .IsResponseBind}}response{{else}}request{{end}}.get{{.Bind.PascalName}}(), {{end}}timeout, callback){{if not .Response.IsEmpty}}, response{{end}}); -{{- end}} - -{{define "method-call-default" -}} - {{if not .Response.IsEmpty -}}return {{end}}impl.{{template "java-name" .}}({{if .Request}}request{{end}}); -{{- end}} - -{{define "method-return-type" -}} - {{if and .Wait (and (not .IsCrudRead) (not (eq .SnakeName "get_run"))) }}Wait<{{.Wait.Poll.Response.PascalName}},{{if not .Response.IsEmpty}}{{.Response.PascalName}}{{else}}Void{{end}}> - {{- else if not .Response.IsEmpty }}{{if .Response.ArrayValue -}} - Iterable<{{ template "type" .Response.ArrayValue }}> - {{- else if .Pagination -}} - Iterable<{{ template "type" .Pagination.Entity }}> - {{- else -}} - {{template "type" .Response}} - {{- end}}{{else}}void{{end}} -{{- end}} diff --git a/.codegen/error-mapper.java.tmpl b/.codegen/error-mapper.java.tmpl deleted file mode 100644 index 0e6056630..000000000 --- a/.codegen/error-mapper.java.tmpl +++ /dev/null @@ -1,15 +0,0 @@ -// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. - -package com.databricks.sdk.core.error; - -import com.databricks.sdk.support.Generated; - -@Generated -class ErrorMapper extends AbstractErrorMapper { - public ErrorMapper() { - {{range .ErrorStatusCodeMapping}}statusCode({{.StatusCode}}, com.databricks.sdk.core.error.platform.{{.PascalName}}::new); - {{end}} - {{range .ErrorCodeMapping}}errorCode("{{.ErrorCode}}", com.databricks.sdk.core.error.platform.{{.PascalName}}::new); - {{end}} - } -} diff --git a/.codegen/error-overrides.java.tmpl b/.codegen/error-overrides.java.tmpl deleted file mode 100644 index fb9cff735..000000000 --- a/.codegen/error-overrides.java.tmpl +++ /dev/null @@ -1,24 +0,0 @@ -// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. - -package com.databricks.sdk.core.error; - -import java.util.Arrays; -import java.util.List; - -import com.databricks.sdk.support.Generated; - -@Generated -class ErrorOverrides { - static final List> ALL_OVERRIDES = Arrays.asList( -{{- range $i, $x := .ErrorOverrides }} - {{if not (eq $i 0)}}, {{end}}new ErrorOverride<>( - "{{$x.Name}}", - "{{ replaceAll "\\" "\\\\" $x.PathRegex}}", - "{{$x.Verb}}", - "{{ replaceAll "\\" "\\\\" $x.StatusCodeMatcher}}", - "{{ replaceAll "\\" "\\\\" $x.ErrorCodeMatcher}}", - "{{ replaceAll "\\" "\\\\" $x.MessageMatcher}}", - com.databricks.sdk.core.error.platform.{{$x.OverrideErrorCode.PascalName}}.class) -{{- end}} - ); -} diff --git a/.codegen/exception.java.tmpl b/.codegen/exception.java.tmpl deleted file mode 100644 index 2e285c3f5..000000000 --- a/.codegen/exception.java.tmpl +++ /dev/null @@ -1,25 +0,0 @@ -// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. - -package com.databricks.sdk.core.error.platform; - -import com.databricks.sdk.core.DatabricksError; -import com.databricks.sdk.core.error.ErrorDetail; -import com.databricks.sdk.support.Generated; - -import java.util.List; - -/** - {{.Comment " * " 80}} - */ -@Generated -public class {{.PascalName}} extends {{if .Inherit -}}{{.Inherit.PascalName}}{{else}}DatabricksError{{end}} { - public {{.PascalName}}(String message, List details) { - super("{{.Name}}", message, {{if not .Inherit}}{{.StatusCode}}, {{end}}details); - } - - {{if not .Inherit}} - public {{.PascalName}}(String errorCode, String message, List details) { - super(errorCode, message, {{.StatusCode}}, details); - } - {{end}} -} diff --git a/.codegen/impl.java.tmpl b/.codegen/impl.java.tmpl deleted file mode 100644 index 3a0ecd41f..000000000 --- a/.codegen/impl.java.tmpl +++ /dev/null @@ -1,79 +0,0 @@ -// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. -package com.databricks.sdk.service.{{.Package.Name}}; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Collection; -import java.util.Map; -import java.util.HashMap; - -import com.databricks.sdk.core.ApiClient; -import com.databricks.sdk.core.DatabricksException; -import com.databricks.sdk.core.http.Encoding; -import com.databricks.sdk.support.Generated; - -{{range .Package.ImportedEntities}} -import com.databricks.sdk.service.{{.Package.Name}}.{{.PascalName}};{{end}} - -/** Package-local implementation of {{.PascalName}} */ -@Generated -class {{.PascalName}}Impl implements {{.PascalName}}Service { - private final ApiClient apiClient; - - public {{.PascalName}}Impl(ApiClient apiClient) { - this.apiClient = apiClient; - } - {{range .Methods}} - @Override - public {{if not .Response.IsEmpty -}}{{template "type" .Response}}{{else}}void{{end}} {{.CamelName}}{{if .IsNameReserved}}Content{{end}}({{if .Request}}{{template "type" .Request}} request{{end}}) { - String path = {{ template "path" . }}; - {{ template "headers" . -}} - {{ if .Response.IsEmpty -}} - {{ template "api-call" . }} - {{- else if .Response.ArrayValue -}} return apiClient.getCollection(path, null, {{template "type" .Response.ArrayValue}}.class, headers); - {{- else if .Response.MapValue -}} return apiClient.getStringMap(path, {{ template "request-param" .}}, headers); - {{- else }}return {{ template "api-call" . }} - {{- end}} - } - {{end}} -} - -{{- define "path" -}} -{{- if .PathParts -}} - String.format("{{range .PathParts -}} - {{- .Prefix -}} - {{- if or .Field .IsAccountId -}}%s{{- end -}} - {{- end -}}" - {{- range .PathParts -}} - {{- if and .Field .Field.IsPathMultiSegment -}}, Encoding.encodeMultiSegmentPathParameter(request.get{{.Field.PascalName}}()) - {{- else if .Field -}}, request.get{{.Field.PascalName}}() - {{- else if .IsAccountId -}}, apiClient.configuredAccountID() - {{- end -}} - {{- end -}}) -{{- else -}} - "{{.Path}}" -{{- end -}} -{{- end -}} - -{{ define "api-call" }} -apiClient.{{.Verb}}(path - {{- if .Request}}, {{ template "request-param" .}}{{end}} - , {{ if not .Response -}}Void - {{- else}}{{template "type" .Response}}{{- end -}}.class - , headers); -{{- end }} - -{{ define "request-param" -}} - {{- if or (and .Operation .Operation.RequestBody) (eq .Verb "GET") (eq .Verb "DELETE") (eq .Verb "HEAD") -}} - request{{ if .RequestBodyField }}.get{{.RequestBodyField.PascalName}}(){{end}} - {{- else -}} - null - {{- end -}} -{{- end }} - -{{ define "headers" -}} - Map headers = new HashMap<>(); - {{- range $key, $value := .FixedRequestHeaders }} - headers.put("{{$key}}", "{{$value}}"); - {{- end -}} -{{- end }} diff --git a/.codegen/interface.java.tmpl b/.codegen/interface.java.tmpl deleted file mode 100644 index 794c79b2d..000000000 --- a/.codegen/interface.java.tmpl +++ /dev/null @@ -1,25 +0,0 @@ -// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. -package com.databricks.sdk.service.{{.Package.Name}}; - -import java.util.Collection; -import java.util.Map; -import java.io.InputStream; - -import com.databricks.sdk.support.Generated; - -/** - {{.Comment " * " 80}} - * - * This is the high-level interface, that contains generated methods. - * - * Evolving: this interface is under development. Method signatures may change. - */ -@Generated -public interface {{.PascalName}}Service { - {{- range .Methods}} - {{if .Description}}/** - {{.Comment " * " 80}} - */{{end}} - {{if not .Response.IsEmpty -}}{{template "type" .Response}}{{else}}void{{end}} {{.CamelName}}{{if .IsNameReserved}}Content{{end}}({{if .Request}}{{template "type" .Request}} {{.Request.CamelName}}{{if .IsNameReserved}}Content{{end}}{{end}}); - {{end}} -} diff --git a/.codegen/lib.tmpl b/.codegen/lib.tmpl deleted file mode 100644 index 88b42123b..000000000 --- a/.codegen/lib.tmpl +++ /dev/null @@ -1,26 +0,0 @@ -{{- define "type-unboxed" -}} - {{- if .IsBool}}boolean - {{- else if .IsInt64}}long - {{- else if .IsFloat64}}double - {{- else if .IsInt}}long - {{- else }}{{template "type" .}}{{end}} -{{- end -}} - -{{- define "type" -}} - {{- if not . }}Object /* ERROR */ - {{- else if .IsExternal }}com.databricks.sdk.service.{{.Package.Name}}.{{.PascalName}} - {{- else if .IsAny}}Object - {{- else if .IsEmpty}}{{.PascalName}} - {{- else if .IsString}}String - {{- else if .IsBool}}Boolean - {{- else if .IsInt64}}Long - {{- else if .IsFloat64}}Double - {{- else if .IsInt}}Long - {{- else if .ArrayValue }}Collection<{{template "type" .ArrayValue}}> - {{- else if .MapValue }}Map - {{- else if .IsByteStream}}InputStream - {{- else if .IsObject }}{{.PascalName}} - {{- else if .Enum }}{{.PascalName}} - {{- else}}Object /* MISSING TYPE */ - {{- end -}} -{{- end -}} diff --git a/.codegen/model.java.tmpl b/.codegen/model.java.tmpl deleted file mode 100644 index 98028fe99..000000000 --- a/.codegen/model.java.tmpl +++ /dev/null @@ -1,87 +0,0 @@ -// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. - -package com.databricks.sdk.service.{{.Package.Name}}; - -import java.util.Map; -import java.io.InputStream; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.Collection; -import java.util.Objects; - -import com.databricks.sdk.support.Generated; -import com.databricks.sdk.support.Header; -import com.databricks.sdk.support.QueryParam; -import com.databricks.sdk.support.ToStringer; - -{{if .IsExternal}} -There is a small issue with the code generator causing this class to be generated twice. This should be fixed upstream -in the code generator, after which this block can be removed. For now, we skip generating the model for all external -types. -{{skipThisFile}} -{{end}} -{{if .Description}}/** - {{.Comment " * " 80}} - */{{end}} -{{if or .Fields .IsEmpty -}} -@Generated -public class {{.PascalName}} { - {{- range .Fields}} - /** - {{.Comment " * " 80}} - */ - {{if .IsJson}}@JsonProperty("{{.Name}}"){{else}}@JsonIgnore{{end}}{{if .IsQuery}}@QueryParam("{{.Name}}"){{end}}{{if .IsHeader}}@Header("{{.Name}}"){{end}} - private {{template "type" .Entity }} {{.CamelName}}{{if .IsNameReserved}}Value{{end}}; - {{end}} - - {{- range .Fields}} - public {{template "type" .Of}} set{{.PascalName}}({{template "type" .Entity }} {{.CamelName}}{{if .IsNameReserved}}Value{{end}}) { - this.{{.CamelName}}{{if .IsNameReserved}}Value{{end}} = {{.CamelName}}{{if .IsNameReserved}}Value{{end}}; - return this; - } - - public {{template "type" .Entity }} get{{.PascalName}}() { - return {{.CamelName}}{{if .IsNameReserved}}Value{{end}}; - } - {{end}} - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - {{if .IsEmpty -}} - return true; - {{- else -}} - {{.PascalName}} that = ({{.PascalName}}) o; - return {{range $i, $x := .Fields}}{{if $i}}&& {{end}}Objects.equals({{.CamelName}}{{if .IsNameReserved}}Value{{end}}, that.{{.CamelName}}{{if .IsNameReserved}}Value{{end}}) - {{end}}; - {{- end }} - } - - @Override - public int hashCode() { - return Objects.hash({{range $i, $x := .Fields}}{{if $i}}, {{end}}{{.CamelName}}{{if .IsNameReserved}}Value{{end}}{{end}}); - } - - @Override - public String toString() { - return new ToStringer({{.PascalName}}.class){{range .Fields}} - .add("{{.CamelName}}{{if .IsNameReserved}}Value{{end}}", {{.CamelName}}{{if .IsNameReserved}}Value{{end}}) - {{- end}}.toString(); - } -} -{{else if .Enum -}} -@Generated -public enum {{.PascalName}}{ - {{range .Enum -}} - {{ if not (eq .Content .ConstantName) }} - @JsonProperty("{{.Content}}") {{end}}{{.ConstantName}},{{.Comment "// " 80}} - {{ end }} -} -{{ else }} -Any types that have no fields (i.e. primitives or array types) or are not enums are not represented by distinct Java -types in the Java SDK. -{{skipThisFile}} -{{- end}} - diff --git a/.codegen/workspace.java.tmpl b/.codegen/workspace.java.tmpl deleted file mode 100644 index a191ef148..000000000 --- a/.codegen/workspace.java.tmpl +++ /dev/null @@ -1,84 +0,0 @@ -// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. - -package com.databricks.sdk; - -import com.databricks.sdk.core.ApiClient; -import com.databricks.sdk.core.ConfigLoader; -import com.databricks.sdk.core.DatabricksConfig; -{{- /* The mapping of mixin replacements should be defined in the .codegen.json file somehow, so that it can be used - in multiple pipelines in the template itself. Pipelines in go template are not able to reference variables - defined in an outer scope (https://github.com/golang/go/issues/17454). */ -}} -import com.databricks.sdk.mixin.ClustersExt; -import com.databricks.sdk.mixin.DbfsExt; -import com.databricks.sdk.mixin.SecretsExt; -{{range .Services}}{{if and (not .IsAccounts) (not .IsDataPlane)}} -import com.databricks.sdk.service.{{.Package.Name}}.{{.PascalName}}API; -import com.databricks.sdk.service.{{.Package.Name}}.{{.PascalName}}Service; -{{end}}{{end}} -import com.databricks.sdk.support.Generated; - -{{- define "api" -}} - {{- $mixins := dict "ClustersAPI" "ClustersExt" "DbfsAPI" "DbfsExt" "SecretsAPI" "SecretsExt" -}} - {{- $genApi := concat .PascalName "API" -}} - {{- getOrDefault $mixins $genApi $genApi -}} -{{- end -}} - -/** - * Entry point for accessing Databricks workspace-level APIs - */ -@Generated -public class WorkspaceClient { - private final ApiClient apiClient; - private final DatabricksConfig config; - {{range .Services}}{{if and (not .IsAccounts) (not .HasParent) (not .IsDataPlane)}} - private {{template "api" .}} {{.CamelName}}API;{{end}}{{end}} - - public WorkspaceClient() { - this(ConfigLoader.getDefault()); - } - - public WorkspaceClient(DatabricksConfig config) { - this.config = config; - apiClient = new ApiClient(config); - {{range .Services}}{{if and (not .IsAccounts) (not .HasParent) (not .IsDataPlane)}} - {{.CamelName}}API = new {{template "api" .}}(apiClient);{{end}}{{end}} - } - - /** Constructor for mocks */ - public WorkspaceClient(boolean mock) { - this(mock, null /* apiClient */); - } - - /** Constructor for mocks */ - public WorkspaceClient(boolean mock, ApiClient apiClient) { - this.apiClient = apiClient; - this.config = null; - } - {{range .Services}}{{if and (not .IsAccounts) (not .HasParent) (not .IsDataPlane)}} - {{if .Description}}/** - {{.Comment " * " 80}} - */{{end}} - public {{template "api" .}} {{.CamelName}}() { - return {{.CamelName}}API; - } - {{end}}{{end}} - {{range .Services}}{{if and (not .IsAccounts) (not .HasParent) (not .IsDataPlane)}} - /** Replace the default {{.PascalName}}Service with a custom implementation. */ - public WorkspaceClient with{{.PascalName}}Impl({{.PascalName}}Service {{.CamelName}}) { - return this.with{{.PascalName}}API(new {{template "api" .}}({{.CamelName}})); - } - - /** Replace the default {{.PascalName}}API with a custom implementation. */ - public WorkspaceClient with{{.PascalName}}API({{template "api" .}} {{.CamelName}}) { - this.{{.CamelName}}API = {{.CamelName}}; - return this; - } - {{end}}{{end}} - public ApiClient apiClient() { - return apiClient; - } - - public DatabricksConfig config() { - return config; - } -}