Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 35 additions & 10 deletions cmd/generateschema/main-generateschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
5 changes: 2 additions & 3 deletions frontend/app/view/codeeditor/schemaendpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ type EndpointInfo = {

const allFilepaths: Map<string, Array<string>> = 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<EndpointInfo> {
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 = {};
Expand Down
132 changes: 132 additions & 0 deletions schema/connections.json
Original file line number Diff line number Diff line change
@@ -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"
}
Loading