@@ -21,26 +21,26 @@ from databricks.sdk.service import {{.Package.Name}}{{end}}
2121{{if .Fields -}}{{if not .IsRequest}}@dataclass
2222class {{.PascalName}}{{if eq "List" .PascalName}}Request{{end}}:{{if .Description}}
2323 """{{.Comment " " 100}}"""
24- {{end}}{{- range .RequiredFields | alphanumOnly }}
24+ {{end}}{{- range .RequiredFields}}
2525 {{template "safe-snake-name" .}}: {{template "type" .Entity}}{{if .Description}}
2626 """{{.Comment " " 100 | trimSuffix "\""}}"""{{end}}
2727 {{end}}
28- {{- range .NonRequiredFields | alphanumOnly }}
28+ {{- range .NonRequiredFields}}
2929 {{template "safe-snake-name" .}}: Optional[{{template "type" .Entity}}] = None{{if .Description}}
3030 """{{.Comment " " 100 | trimSuffix "\""}}"""{{end}}
3131 {{end}}
32- {{if .HasJsonField -}}
32+ {{if or .HasJsonField .HasHeaderField .HasByteStreamField -}}
3333 def as_dict(self) -> dict:
3434 """Serializes the {{.PascalName}}{{if eq "List" .PascalName}}Request{{end}} into a dictionary suitable for use as a JSON request body."""
3535 body = {}
36- {{range .Fields | alphanumOnly }}if self.{{template "safe-snake-name" .}}{{with .Entity.IsPrimitive}} is not None{{end}}: body['{{.Name}}'] = {{template "as_request_type" .}}
36+ {{range .Fields}}if self.{{template "safe-snake-name" .}}{{with .Entity.IsPrimitive}} is not None{{end}}: body['{{.Name}}'] = {{template "as_request_type" .}}
3737 {{end -}}
3838 return body
3939
4040 @classmethod
4141 def from_dict(cls, d: Dict[str, any]) -> {{.PascalName}}{{if eq "List" .PascalName}}Request{{end}}:
4242 """Deserializes the {{.PascalName}}{{if eq "List" .PascalName}}Request{{end}} from a dictionary."""
43- return cls({{range $i, $f := .Fields | alphanumOnly }}{{if $i}}, {{end}}{{template "safe-snake-name" $f}}={{template "from_dict_type" $f}}{{end}})
43+ return cls({{range $i, $f := .Fields}}{{if $i}}, {{end}}{{template "safe-snake-name" $f}}={{template "from_dict_type" $f}}{{end}})
4444 {{end}}
4545{{end}}
4646{{else if .ArrayValue}}type {{.PascalName}} []{{template "type" .ArrayValue}}
@@ -187,6 +187,9 @@ class {{.Name}}API:{{if .Description}}
187187 {{template "method-serialize" .}}
188188 {{- end}}
189189 {{template "method-headers" . }}
190+ {{if and .Response .Response.HasHeaderField -}}
191+ {{template "method-response-headers" . }}
192+ {{- end}}
190193 {{template "method-call" .}}
191194
192195 {{if and .Wait (and (not .IsCrudRead) (not (eq .SnakeName "get_run"))) }}
@@ -211,7 +214,7 @@ class {{.Name}}API:{{if .Description}}
211214 {{if or .Request.HasJsonField .Request.HasQueryField -}}
212215 {{if .Request.HasJsonField}}body = {}{{end}}{{if .Request.HasQueryField}}
213216 query = {}{{end}}
214- {{- range .Request.Fields}}{{ if not .IsPath }}
217+ {{- range .Request.Fields}}{{ if and ( not .IsPath) (not .IsHeader) }}
215218 {{- if .IsQuery }}
216219 if {{template "safe-snake-name" .}} is not None: query['{{.Name}}'] = {{template "method-param-bind" .}}{{end}}
217220 {{- if .IsJson }}
@@ -227,6 +230,12 @@ class {{.Name}}API:{{if .Description}}
227230 }
228231{{- end }}
229232
233+ {{ define "method-response-headers" -}}
234+ response_headers = [
235+ {{- range $h := .ResponseHeaders}}'{{ $h.Name }}',{{ end -}}
236+ ]
237+ {{- end }}
238+
230239{{- define "method-param-bind" -}}
231240 {{- if not .Entity }}None # ERROR: No Type
232241 {{- else if .Entity.ArrayValue }}[
@@ -282,7 +291,7 @@ class {{.Name}}API:{{if .Description}}
282291 {{ if .Pagination.Token -}}
283292 if '{{.Pagination.Token.Bind.Name}}' not in json or not json['{{.Pagination.Token.Bind.Name}}']:
284293 return
285- {{if eq "GET" .Verb}}query{{else}}body{{end}}['{{.Pagination.Token.PollField.Name}}'] = json['{{.Pagination.Token.Bind.Name}}']
294+ {{if or ( eq "GET" .Verb) (eq "HEAD" .Verb) }}query{{else}}body{{end}}['{{.Pagination.Token.PollField.Name}}'] = json['{{.Pagination.Token.Bind.Name}}']
286295 {{- else if eq .Path "/api/2.0/clusters/events" -}}
287296 if 'next_page' not in json or not json['next_page']:
288297 return
@@ -307,9 +316,7 @@ class {{.Name}}API:{{if .Description}}
307316 {{if .Response -}}
308317 res = {{end}}{{template "method-do" .}}
309318 {{if .Response -}}
310- {{- if .IsResponseByteStream -}}
311- return {{.Response.PascalName}}({{.ResponseBodyField.CamelName}}=res)
312- {{- else if .Response.ArrayValue -}}
319+ {{- if .Response.ArrayValue -}}
313320 return [{{.Response.ArrayValue.PascalName}}.from_dict(v) for v in res]
314321 {{- else if .Response.MapValue -}}
315322 return res
@@ -330,6 +337,9 @@ self._api.do('{{.Verb}}',
330337 {{- else if .Request.HasJsonField}}, body=body{{end}}
331338 {{end}}
332339 , headers=headers
340+ {{if and .Response .Response.HasHeaderField -}}
341+ , response_headers=response_headers
342+ {{- end}}
333343 {{- if and .IsRequestByteStream .RequestBodyField }}, data={{template "safe-snake-name" .RequestBodyField}}{{ end }}
334344 {{- if .IsResponseByteStream }}, raw=True{{ end }})
335345{{- end}}
0 commit comments