Add typed settings areas to the REST API
/api/v1/settings/router/firewall, .../router/lans/<name>, .../system, down to a single option: GET reads, PUT replaces, PATCH merges, DELETE removes, with the settings' ETag/If-Match and the same limits as the whole-document edit (editSettings is now shared). Values are checked against a JSON Schema made from the option documentation (schema.go reads the types, which nixosOptionsDoc describes in words); a wrong type, a value out of range or an unknown key is refused with its place. The OpenAPI document has the area paths with their schemas; the API reference page lists every area's options. Tests: unit tests for the type reader, the validator and the paths; the real option file and a router's own settings validate (ROUTER_OPTIONS_JSON, LIVE_SETTINGS_JSON); a subtest in apply. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AeFqV9dZrK6nipHkPfyM4F
This commit is contained in:
@@ -221,7 +221,9 @@ type app struct {
|
||||
|
||||
tokens *tokenStore
|
||||
settingsMu sync.Mutex // edits through the API read, patch and write the settings file
|
||||
optionsFile string // JSON documentation of the router options, for the MCP resource ("" if none)
|
||||
schemaOnce sync.Once
|
||||
schemaVal map[string]any // the settings schema, from optionsFile (nil if none)
|
||||
optionsFile string // JSON documentation of the router options, for the MCP resource ("" if none)
|
||||
}
|
||||
|
||||
func withOptions(a *app, file string) *app {
|
||||
|
||||
Reference in New Issue
Block a user