-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathimpl.java.tmpl
More file actions
79 lines (70 loc) · 2.7 KB
/
Copy pathimpl.java.tmpl
File metadata and controls
79 lines (70 loc) · 2.7 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// 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<String, String> headers = new HashMap<>();
{{- range $key, $value := .FixedRequestHeaders }}
headers.put("{{$key}}", "{{$value}}");
{{- end -}}
{{- end }}