-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathimpl.java.tmpl
More file actions
63 lines (55 loc) · 2.48 KB
/
Copy pathimpl.java.tmpl
File metadata and controls
63 lines (55 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// 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.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 .Response -}}{{template "type" .Response}}{{else}}void{{end}} {{.CamelName}}{{if .IsNameReserved}}Content{{end}}({{if .Request}}{{template "type" .Request}} request{{end}}) {
String path = {{if .PathParts -}}
String.format("{{range .PathParts}}{{.Prefix}}{{if or .Field .IsAccountId}}%s{{end}}{{ end }}"{{ range .PathParts }}{{if .Field}}, request.get{{.Field.PascalName}}(){{ else if .IsAccountId }}, apiClient.configuredAccountID(){{end}}{{ end }})
{{- else}}"{{.Path}}"{{end}};
{{ template "headers" . -}}
{{ if not .Response -}}
{{ 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 if .IsResponseByteStream -}}
InputStream response = {{ template "api-call" . }}
return new {{ .Response.PascalName }}().set{{.ResponseBodyField.PascalName}}(response);
{{- else }}return {{ template "api-call" . }}
{{- end}}
}
{{end}}
}
{{ define "api-call" }}
apiClient.{{.Verb}}(path
{{- if .Request}}, {{ template "request-param" .}}{{end}}
, {{ if not .Response -}}Void
{{- else if .IsResponseByteStream}}InputStream
{{- else}}{{template "type" .Response}}{{- end -}}.class
, headers);
{{- end }}
{{ define "request-param" -}}
request{{ if .RequestBodyField }}.get{{.RequestBodyField.PascalName}}(){{end}}
{{- end }}
{{ define "headers" -}}
Map<String, String> headers = new HashMap<>();
{{- range $key, $value := .FixedRequestHeaders }}
headers.put("{{$key}}", "{{$value}}");
{{- end -}}
{{- end }}