-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds schema.json support to the settings file to provide type hints and other eventual details. This also adds a system to easily add more schema files for other type of configurations.
- Loading branch information
1 parent
1a70c83
commit fc298f2
Showing
10 changed files
with
468 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2025, Command Line Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/invopop/jsonschema" | ||
"github.com/wavetermdev/waveterm/pkg/util/utilfn" | ||
"github.com/wavetermdev/waveterm/pkg/wconfig" | ||
) | ||
|
||
const WaveSchemaSettingsFileName = "schema/settings.json" | ||
|
||
func main() { | ||
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) | ||
} | ||
*/ | ||
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2025, Command Line Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { getApi } from "@/app/store/global"; | ||
import { getWebServerEndpoint } from "@/util/endpoints"; | ||
|
||
type EndpointInfo = { | ||
uri: string; | ||
fileMatch: Array<string>; | ||
schema: object; | ||
}; | ||
|
||
const allFilepaths: Map<string, Array<string>> = new Map(); | ||
allFilepaths.set(`${getWebServerEndpoint()}/schema/settings.json`, [`${getApi().getConfigDir()}/settings.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]; | ||
} catch (e) { | ||
console.log("cannot find schema:", e); | ||
schema = {}; | ||
} | ||
const fileMatch = allFilepaths.get(endpoint) ?? []; | ||
|
||
return { | ||
uri: endpoint, | ||
fileMatch, | ||
schema, | ||
}; | ||
} | ||
|
||
const SchemaEndpoints = Array.from(allFilepaths.keys()); | ||
|
||
export { getSchemaEndpointInfo, SchemaEndpoints }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.