Skip to content

Commit affd846

Browse files
authored
feat: add connections schema (#1900)
This adds the schema needed for the connections.json file
1 parent 6bcf65d commit affd846

File tree

3 files changed

+169
-13
lines changed

3 files changed

+169
-13
lines changed

cmd/generateschema/main-generateschema.go

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,50 @@ import (
1515
)
1616

1717
const WaveSchemaSettingsFileName = "schema/settings.json"
18+
const WaveSchemaConnectionsFileName = "schema/connections.json"
1819

19-
func main() {
20+
func generateSettingsSchema() error {
2021
settingsSchema := jsonschema.Reflect(&wconfig.SettingsType{})
2122

2223
jsonSettingsSchema, err := json.MarshalIndent(settingsSchema, "", " ")
2324
if err != nil {
24-
log.Fatalf("failed to parse local schema: %v", err)
25-
}
26-
/*
27-
err = os.MkdirAll(WaveSchemaSettingsFileName, 0755)
28-
if err != nil {
29-
log.Fatalf("failed to create schema dir: %v", err)
30-
}
31-
*/
25+
return fmt.Errorf("failed to parse local schema: %v", err)
26+
}
3227
written, err := utilfn.WriteFileIfDifferent(WaveSchemaSettingsFileName, jsonSettingsSchema)
3328
if !written {
3429
fmt.Fprintf(os.Stderr, "no changes to %s\n", WaveSchemaSettingsFileName)
3530
}
3631
if err != nil {
37-
log.Fatalf("failed to write local schema: %v", err)
32+
return fmt.Errorf("failed to write local schema: %v", err)
33+
}
34+
return nil
35+
}
36+
37+
func generateConnectionsSchema() error {
38+
connExample := make(map[string]wconfig.ConnKeywords)
39+
connectionSchema := jsonschema.Reflect(connExample)
40+
41+
jsonSettingsSchema, err := json.MarshalIndent(connectionSchema, "", " ")
42+
if err != nil {
43+
return fmt.Errorf("failed to parse local schema: %v", err)
44+
}
45+
written, err := utilfn.WriteFileIfDifferent(WaveSchemaConnectionsFileName, jsonSettingsSchema)
46+
if !written {
47+
fmt.Fprintf(os.Stderr, "no changes to %s\n", WaveSchemaConnectionsFileName)
48+
}
49+
if err != nil {
50+
return fmt.Errorf("failed to write local schema: %v", err)
51+
}
52+
return nil
53+
}
54+
55+
func main() {
56+
err := generateSettingsSchema()
57+
if err != nil {
58+
log.Fatalf("settings schema error: %v", err)
59+
}
60+
err = generateConnectionsSchema()
61+
if err != nil {
62+
log.Fatalf("connections schema error: %v", err)
3863
}
3964
}

frontend/app/view/codeeditor/schemaendpoints.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ type EndpointInfo = {
1212

1313
const allFilepaths: Map<string, Array<string>> = new Map();
1414
allFilepaths.set(`${getWebServerEndpoint()}/schema/settings.json`, [`${getApi().getConfigDir()}/settings.json`]);
15+
allFilepaths.set(`${getWebServerEndpoint()}/schema/connections.json`, [`${getApi().getConfigDir()}/connections.json`]);
1516

1617
async function getSchemaEndpointInfo(endpoint: string): Promise<EndpointInfo> {
1718
let schema: Object;
1819
try {
1920
const data = await fetch(endpoint);
20-
const fullSchema: object = await data.json();
21-
const schemaRef: string = fullSchema?.["$ref"];
22-
schema = fullSchema?.[schemaRef];
21+
schema = await data.json();
2322
} catch (e) {
2423
console.log("cannot find schema:", e);
2524
schema = {};

schema/connections.json

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$defs": {
4+
"ConnKeywords": {
5+
"properties": {
6+
"conn:wshenabled": {
7+
"type": "boolean"
8+
},
9+
"conn:askbeforewshinstall": {
10+
"type": "boolean"
11+
},
12+
"conn:wshpath": {
13+
"type": "string"
14+
},
15+
"conn:shellpath": {
16+
"type": "string"
17+
},
18+
"conn:ignoresshconfig": {
19+
"type": "boolean"
20+
},
21+
"display:hidden": {
22+
"type": "boolean"
23+
},
24+
"display:order": {
25+
"type": "number"
26+
},
27+
"term:*": {
28+
"type": "boolean"
29+
},
30+
"term:fontsize": {
31+
"type": "number"
32+
},
33+
"term:fontfamily": {
34+
"type": "string"
35+
},
36+
"term:theme": {
37+
"type": "string"
38+
},
39+
"cmd:env": {
40+
"additionalProperties": {
41+
"type": "string"
42+
},
43+
"type": "object"
44+
},
45+
"cmd:initscript": {
46+
"type": "string"
47+
},
48+
"cmd:initscript.sh": {
49+
"type": "string"
50+
},
51+
"cmd:initscript.bash": {
52+
"type": "string"
53+
},
54+
"cmd:initscript.zsh": {
55+
"type": "string"
56+
},
57+
"cmd:initscript.pwsh": {
58+
"type": "string"
59+
},
60+
"cmd:initscript.fish": {
61+
"type": "string"
62+
},
63+
"ssh:user": {
64+
"type": "string"
65+
},
66+
"ssh:hostname": {
67+
"type": "string"
68+
},
69+
"ssh:port": {
70+
"type": "string"
71+
},
72+
"ssh:identityfile": {
73+
"items": {
74+
"type": "string"
75+
},
76+
"type": "array"
77+
},
78+
"ssh:batchmode": {
79+
"type": "boolean"
80+
},
81+
"ssh:pubkeyauthentication": {
82+
"type": "boolean"
83+
},
84+
"ssh:passwordauthentication": {
85+
"type": "boolean"
86+
},
87+
"ssh:kbdinteractiveauthentication": {
88+
"type": "boolean"
89+
},
90+
"ssh:preferredauthentications": {
91+
"items": {
92+
"type": "string"
93+
},
94+
"type": "array"
95+
},
96+
"ssh:addkeystoagent": {
97+
"type": "boolean"
98+
},
99+
"ssh:identityagent": {
100+
"type": "string"
101+
},
102+
"ssh:identitiesonly": {
103+
"type": "boolean"
104+
},
105+
"ssh:proxyjump": {
106+
"items": {
107+
"type": "string"
108+
},
109+
"type": "array"
110+
},
111+
"ssh:userknownhostsfile": {
112+
"items": {
113+
"type": "string"
114+
},
115+
"type": "array"
116+
},
117+
"ssh:globalknownhostsfile": {
118+
"items": {
119+
"type": "string"
120+
},
121+
"type": "array"
122+
}
123+
},
124+
"additionalProperties": false,
125+
"type": "object"
126+
}
127+
},
128+
"additionalProperties": {
129+
"$ref": "#/$defs/ConnKeywords"
130+
},
131+
"type": "object"
132+
}

0 commit comments

Comments
 (0)