diff --git a/cmd/generateschema/main-generateschema.go b/cmd/generateschema/main-generateschema.go index bb0d09d6a4..a102899851 100644 --- a/cmd/generateschema/main-generateschema.go +++ b/cmd/generateschema/main-generateschema.go @@ -15,25 +15,50 @@ import ( ) const WaveSchemaSettingsFileName = "schema/settings.json" +const WaveSchemaConnectionsFileName = "schema/connections.json" -func main() { +func generateSettingsSchema() error { settingsSchema := jsonschema.Reflect(&wconfig.SettingsType{}) jsonSettingsSchema, err := json.MarshalIndent(settingsSchema, "", " ") if err != nil { - log.Fatalf("failed to parse local schema: %v", err) - } - /* - err = os.MkdirAll(WaveSchemaSettingsFileName, 0755) - if err != nil { - log.Fatalf("failed to create schema dir: %v", err) - } - */ + return fmt.Errorf("failed to parse local schema: %v", err) + } written, err := utilfn.WriteFileIfDifferent(WaveSchemaSettingsFileName, jsonSettingsSchema) if !written { fmt.Fprintf(os.Stderr, "no changes to %s\n", WaveSchemaSettingsFileName) } if err != nil { - log.Fatalf("failed to write local schema: %v", err) + return fmt.Errorf("failed to write local schema: %v", err) + } + return nil +} + +func generateConnectionsSchema() error { + connExample := make(map[string]wconfig.ConnKeywords) + connectionSchema := jsonschema.Reflect(connExample) + + jsonSettingsSchema, err := json.MarshalIndent(connectionSchema, "", " ") + if err != nil { + return fmt.Errorf("failed to parse local schema: %v", err) + } + written, err := utilfn.WriteFileIfDifferent(WaveSchemaConnectionsFileName, jsonSettingsSchema) + if !written { + fmt.Fprintf(os.Stderr, "no changes to %s\n", WaveSchemaConnectionsFileName) + } + if err != nil { + return fmt.Errorf("failed to write local schema: %v", err) + } + return nil +} + +func main() { + err := generateSettingsSchema() + if err != nil { + log.Fatalf("settings schema error: %v", err) + } + err = generateConnectionsSchema() + if err != nil { + log.Fatalf("connections schema error: %v", err) } } diff --git a/frontend/app/view/codeeditor/schemaendpoints.ts b/frontend/app/view/codeeditor/schemaendpoints.ts index 19b1a546a6..4c9d98670a 100644 --- a/frontend/app/view/codeeditor/schemaendpoints.ts +++ b/frontend/app/view/codeeditor/schemaendpoints.ts @@ -12,14 +12,13 @@ type EndpointInfo = { const allFilepaths: Map> = new Map(); allFilepaths.set(`${getWebServerEndpoint()}/schema/settings.json`, [`${getApi().getConfigDir()}/settings.json`]); +allFilepaths.set(`${getWebServerEndpoint()}/schema/connections.json`, [`${getApi().getConfigDir()}/connections.json`]); async function getSchemaEndpointInfo(endpoint: string): Promise { let schema: Object; try { const data = await fetch(endpoint); - const fullSchema: object = await data.json(); - const schemaRef: string = fullSchema?.["$ref"]; - schema = fullSchema?.[schemaRef]; + schema = await data.json(); } catch (e) { console.log("cannot find schema:", e); schema = {}; diff --git a/schema/connections.json b/schema/connections.json new file mode 100644 index 0000000000..014a569dd7 --- /dev/null +++ b/schema/connections.json @@ -0,0 +1,132 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$defs": { + "ConnKeywords": { + "properties": { + "conn:wshenabled": { + "type": "boolean" + }, + "conn:askbeforewshinstall": { + "type": "boolean" + }, + "conn:wshpath": { + "type": "string" + }, + "conn:shellpath": { + "type": "string" + }, + "conn:ignoresshconfig": { + "type": "boolean" + }, + "display:hidden": { + "type": "boolean" + }, + "display:order": { + "type": "number" + }, + "term:*": { + "type": "boolean" + }, + "term:fontsize": { + "type": "number" + }, + "term:fontfamily": { + "type": "string" + }, + "term:theme": { + "type": "string" + }, + "cmd:env": { + "additionalProperties": { + "type": "string" + }, + "type": "object" + }, + "cmd:initscript": { + "type": "string" + }, + "cmd:initscript.sh": { + "type": "string" + }, + "cmd:initscript.bash": { + "type": "string" + }, + "cmd:initscript.zsh": { + "type": "string" + }, + "cmd:initscript.pwsh": { + "type": "string" + }, + "cmd:initscript.fish": { + "type": "string" + }, + "ssh:user": { + "type": "string" + }, + "ssh:hostname": { + "type": "string" + }, + "ssh:port": { + "type": "string" + }, + "ssh:identityfile": { + "items": { + "type": "string" + }, + "type": "array" + }, + "ssh:batchmode": { + "type": "boolean" + }, + "ssh:pubkeyauthentication": { + "type": "boolean" + }, + "ssh:passwordauthentication": { + "type": "boolean" + }, + "ssh:kbdinteractiveauthentication": { + "type": "boolean" + }, + "ssh:preferredauthentications": { + "items": { + "type": "string" + }, + "type": "array" + }, + "ssh:addkeystoagent": { + "type": "boolean" + }, + "ssh:identityagent": { + "type": "string" + }, + "ssh:identitiesonly": { + "type": "boolean" + }, + "ssh:proxyjump": { + "items": { + "type": "string" + }, + "type": "array" + }, + "ssh:userknownhostsfile": { + "items": { + "type": "string" + }, + "type": "array" + }, + "ssh:globalknownhostsfile": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": { + "$ref": "#/$defs/ConnKeywords" + }, + "type": "object" +} \ No newline at end of file