-
Notifications
You must be signed in to change notification settings - Fork 369
settings schema.json #1874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
settings schema.json #1874
Changes from all commits
78e27c3
c21d996
ce42904
c25f5b7
5e81b2d
50766b0
56a67bf
475436d
29a734c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||
} | ||
} |
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; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace Object type with a more specific type. As flagged by static analysis, using - let schema: Object;
+ let schema: JSONSchema; 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Biome (1.9.4)[error] 17-17: Don't use 'Object' as a type. Prefer explicitly define the object shape. This type means "any non-nullable value", which is slightly better than 'unknown', but it's still a broad type. (lint/complexity/noBannedTypes) |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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 = {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+18
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve error handling and add timeout for fetch. The current error handling is too broad and simply logs to console. Consider:
try {
- const data = await fetch(endpoint);
+ const controller = new AbortController();
+ const timeoutId = setTimeout(() => controller.abort(), 5000);
+ const data = await fetch(endpoint, {
+ signal: controller.signal,
+ });
+ clearTimeout(timeoutId);
+
+ if (!data.ok) {
+ throw new Error(`Failed to fetch schema: ${data.statusText}`);
+ }
+
const fullSchema: object = await data.json();
const schemaRef: string = fullSchema?.["$ref"];
schema = fullSchema?.[schemaRef];
} catch (e) {
- console.log("cannot find schema:", e);
- schema = {};
+ if (e instanceof Error) {
+ console.error("Schema fetch error:", e.message);
+ }
+ throw new Error("Failed to load schema configuration");
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const fileMatch = allFilepaths.get(endpoint) ?? []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
uri: endpoint, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fileMatch, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
schema, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const SchemaEndpoints = Array.from(allFilepaths.keys()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export { getSchemaEndpointInfo, SchemaEndpoints }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Focus on Adding Validation for Configuration Paths
The search confirms that the configuration directory (via
getApi().getConfigDir()
) is used consistently across the codebase (in at least three locations) without any validation. Consider adding checks to ensure the returned paths are valid and handle cases where they might be undefined or malformed.connections.json
is directly derived from the config without checks.ai.json
is similarly derived without validation.🔗 Analysis chain
Add validation for configuration paths.
The current implementation assumes the configuration directory and endpoints are always valid. Consider adding validation to handle cases where these paths might be undefined or invalid.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 916