Skip to content

Commit 79a6d65

Browse files
Api generated from OpenAPI specs (#88)
The codegenerator changes are in databricks/databricks-sdk-go#9
1 parent 7073738 commit 79a6d65

File tree

33 files changed

+5944
-2768
lines changed

33 files changed

+5944
-2768
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"includeTags": ["Clusters", "Jobs", "Repos", "Workspace", "Dbfs"],
3+
"formatter": "yarn fix",
4+
"fileset": {
5+
".codegen/api.ts.tmpl": "{{.Name}}/api.ts",
6+
".codegen/index.ts.tmpl": "{{.Name}}/index.ts",
7+
".codegen/model.ts.tmpl": "{{.Name}}/model.ts"
8+
}
9+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/* eslint-disable @typescript-eslint/naming-convention */
2+
3+
// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT.
4+
5+
import {ApiClient} from "../../api-client";
6+
import * as model from "./model";
7+
import Time from "../../retries/Time";
8+
import retry, {RetriableError} from "../../retries/retries";
9+
10+
{{- range $i, $s := .Services }}
11+
export class {{$s.PascalName}}RetriableError extends RetriableError {}
12+
export class {{$s.PascalName}}Error extends Error {}
13+
14+
/**
15+
{{$s.Comment "* " 80}}
16+
*/
17+
export class {{$s.PascalName}}Service {
18+
constructor(readonly client: ApiClient){}
19+
20+
{{- range $s.Methods}}
21+
/**
22+
{{.Comment " * " 80}}
23+
*/
24+
async {{.CamelName}}({{if .Request}}request: model.{{.Request.PascalName}}{{end}}): Promise<model.{{if .Response}}{{.Response.PascalName}}{{else}}{{.EmptyResponseName.PascalName}}{{end}}> {
25+
const path = {{if .PathParts}}`{{range .PathParts}}{{.Prefix}}{{if .Field}}${request.{{.Field.SnakeName}}}{{end}}{{end}}`{{else}}"{{.Path}}"{{end}}
26+
return await this.client.request(
27+
path,
28+
"{{.Verb}}",
29+
{{if .Request}}request{{end}}
30+
) as model.{{if .Response}}{{.Response.PascalName}}{{else}}{{.EmptyResponseName.PascalName}}{{end}}
31+
}
32+
33+
{{if .Wait}}
34+
/**
35+
* {{.CamelName}} and wait to reach {{range $i, $e := .Wait.Success}}{{if $i}} or {{end}}{{.Content}}{{end}} state
36+
* {{if .Wait.Failure}} or fail on reaching {{range $i, $e := .Wait.Failure}}{{if $i}} or {{end}}{{.Content}}{{end}} state{{end}}
37+
*/
38+
async {{.CamelName}}AndWait({{if .Request}}request: model.{{.Request.PascalName}}{{end}}, timeout?: Time): Promise<model.{{if .Wait.Poll.Response}}{{.Wait.Poll.Response.PascalName}}{{else}}{{.Wait.Poll.EmptyResponseName.PascalName}}{{end}}> {
39+
const response = await this.{{.CamelName}}(request);
40+
41+
return await retry<model.{{if .Wait.Poll.Response}}{{.Wait.Poll.Response.PascalName}}{{else}}{{.Wait.Poll.EmptyResponseName.PascalName}}{{end}}>({
42+
timeout: timeout,
43+
fn: async () => {
44+
const pollResponse = await this.{{.Wait.Poll.CamelName}}({
45+
{{.Wait.Bind.SnakeName}}: {{if .Wait.ForceBindRequest}}request{{else if .Response}}response{{else}}request{{end}}.{{.Wait.Bind.SnakeName}}!
46+
})
47+
const status = pollResponse{{range $i, $e := .Wait.StatusPath}}{{if $i}}!{{end}}.{{$e.SnakeName}}{{end}}
48+
const statusMessage = pollResponse{{range $i, $e := .Wait.MessagePath}}{{if $i}}!{{end}}.{{$e.SnakeName}}{{end}}
49+
switch(status) {
50+
{{range $i, $e := .Wait.Success}}{{if $i}} {{end}}case '{{$e.Content}}':{{end}}{
51+
return pollResponse
52+
}
53+
{{if .Wait.Failure}}{{range $i, $e := .Wait.Failure}}{{if $i}} {{end}}case '{{$e.Content}}':{{end}}{
54+
throw new {{$s.PascalName}}Error(`failed to reach {{range $i, $e := .Wait.Success}}{{if $i}} or {{end}}{{.Content}}{{end}} state, got ${status}: ${statusMessage}`)
55+
}
56+
{{end}}default:{
57+
throw new {{$s.PascalName}}RetriableError(`failed to reach {{range $i, $e := .Wait.Success}}{{if $i}} or {{end}}{{.Content}}{{end}} state, got ${status}: ${statusMessage}`)
58+
}
59+
}
60+
}
61+
});
62+
}
63+
{{end}}
64+
{{end}}
65+
}
66+
{{end}}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./model"
2+
export * from "./api"
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* eslint-disable @typescript-eslint/naming-convention */
2+
3+
// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT.
4+
5+
// all definitions in this file are in alphabetical order
6+
{{range .Types}}{{if .Comment "" 80}}/**
7+
{{.Comment "* " 80}}
8+
*/
9+
{{end}}{{if .Fields}}export interface {{.PascalName}} {
10+
{{range .Fields}}
11+
{{if .Comment "" 80}}/**
12+
{{.Comment " * " 80}}
13+
*/
14+
{{end}}{{.SnakeName}}{{if not .Required}}?{{end}}: {{template "type" .Entity}};{{end}}
15+
}
16+
17+
{{else if .Enum}}export type {{.PascalName}} =
18+
{{range $i, $e:=.Enum }}{{if $e.Comment "" 80}}/**
19+
{{$e.Comment "* " 80}}
20+
*/
21+
{{end}}{{if $i}} |{{end}}"{{$e.Content}}"
22+
{{end}};
23+
{{end}}
24+
{{end}}
25+
26+
{{range .EmptyTypes}}export interface {{.PascalName}}{};
27+
{{end}}
28+
29+
{{- define "type" -}}
30+
{{- if not . }}any /* ERROR */
31+
{{- else if .IsString}}string
32+
{{- else if .IsBool}}boolean
33+
{{- else if .IsInt64}}number
34+
{{- else if .IsFloat64}}number
35+
{{- else if .IsInt}}number
36+
{{- else if .ArrayValue }}Array<{{template "type" .ArrayValue}}>
37+
{{- else if .MapValue }}Record<string, {{template "type" .MapValue}}>
38+
{{- else if .IsObject }}{{.PascalName}}
39+
{{- else if .Enum }}{{.PascalName}}
40+
{{- else}}any /* MISSING TYPE */
41+
{{- end -}}
42+
{{- end -}}

0 commit comments

Comments
 (0)