mirror of
https://github.com/navidrome/navidrome.git
synced 2026-02-13 08:21:09 -05:00
* feat(plugins): add JSONForms schema for plugin configuration Signed-off-by: Deluan <deluan@navidrome.org> * feat: enhance error handling by formatting validation errors with field names Signed-off-by: Deluan <deluan@navidrome.org> * feat: enforce required fields in config validation and improve error handling Signed-off-by: Deluan <deluan@navidrome.org> * format JS code Signed-off-by: Deluan <deluan@navidrome.org> * feat: add config schema validation and enhance manifest structure Signed-off-by: Deluan <deluan@navidrome.org> * feat: refactor plugin config parsing and add unit tests Signed-off-by: Deluan <deluan@navidrome.org> * feat: add config validation error message in Portuguese * feat: enhance AlwaysExpandedArrayLayout with description support and improve array control testing Signed-off-by: Deluan <deluan@navidrome.org> * feat: update Discord Rust plugin configuration to use JSONForm for user tokens and enhance schema validation Signed-off-by: Deluan <deluan@navidrome.org> * fix: resolve React Hooks linting issues in plugin UI components * Apply suggestions from code review Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * format code Signed-off-by: Deluan <deluan@navidrome.org> * feat: migrate schema validation to use santhosh-tekuri/jsonschema and improve error formatting Signed-off-by: Deluan <deluan@navidrome.org> * address PR comments Signed-off-by: Deluan <deluan@navidrome.org> * fix flaky test Signed-off-by: Deluan <deluan@navidrome.org> * feat: enhance array layout and configuration handling with AJV defaults Signed-off-by: Deluan <deluan@navidrome.org> * feat: implement custom tester to exclude enum arrays from AlwaysExpandedArrayLayout Signed-off-by: Deluan <deluan@navidrome.org> * feat: add error boundary for schema rendering and improve error messages Signed-off-by: Deluan <deluan@navidrome.org> * feat: refine non-enum array control logic by utilizing JSONForms schema resolution Signed-off-by: Deluan <deluan@navidrome.org> * feat: add error styling to ToggleEnabledSwitch for disabled state Signed-off-by: Deluan <deluan@navidrome.org> * feat: adjust label positioning and styling in SchemaConfigEditor for improved layout Signed-off-by: Deluan <deluan@navidrome.org> * feat: implement outlined input controls renderers to replace custom fragile CSS Signed-off-by: Deluan <deluan@navidrome.org> * feat: remove margin from last form control inside array items for better spacing Signed-off-by: Deluan <deluan@navidrome.org> * feat: enhance AJV error handling to transform required errors for field-level validation Signed-off-by: Deluan <deluan@navidrome.org> * feat: set default value for User Tokens in manifest.json to improve user experience Signed-off-by: Deluan <deluan@navidrome.org> * format Signed-off-by: Deluan <deluan@navidrome.org> * feat: add margin to outlined input controls for improved spacing Signed-off-by: Deluan <deluan@navidrome.org> * feat: remove redundant margin rule for last form control in array items Signed-off-by: Deluan <deluan@navidrome.org> * feat: adjust font size of label elements in SchemaConfigEditor for improved readability Signed-off-by: Deluan <deluan@navidrome.org> --------- Signed-off-by: Deluan <deluan@navidrome.org> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
74 lines
2.5 KiB
Go
74 lines
2.5 KiB
Go
package plugins
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/santhosh-tekuri/jsonschema/v6"
|
|
)
|
|
|
|
//go:generate go tool go-jsonschema -p plugins --struct-name-from-title -o manifest_gen.go manifest-schema.json
|
|
|
|
// ParseManifest unmarshals manifest JSON and performs cross-field validation.
|
|
// This is the single entry point for manifest parsing after reading from a file.
|
|
func ParseManifest(data []byte) (*Manifest, error) {
|
|
var m Manifest
|
|
if err := json.Unmarshal(data, &m); err != nil {
|
|
return nil, fmt.Errorf("parsing manifest JSON: %w", err)
|
|
}
|
|
if err := m.Validate(); err != nil {
|
|
return nil, fmt.Errorf("validating manifest: %w", err)
|
|
}
|
|
return &m, nil
|
|
}
|
|
|
|
// Validate performs cross-field validation that cannot be expressed in JSON Schema.
|
|
// This validates rules like "SubsonicAPI permission requires users permission".
|
|
func (m *Manifest) Validate() error {
|
|
// SubsonicAPI permission requires users permission
|
|
if m.Permissions != nil && m.Permissions.Subsonicapi != nil {
|
|
if m.Permissions.Users == nil {
|
|
return fmt.Errorf("'subsonicapi' permission requires 'users' permission to be declared")
|
|
}
|
|
}
|
|
|
|
// Validate config schema if present
|
|
if m.Config != nil && m.Config.Schema != nil {
|
|
if err := validateConfigSchema(m.Config.Schema); err != nil {
|
|
return fmt.Errorf("invalid config schema: %w", err)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// validateConfigSchema validates that the schema is a valid JSON Schema that can be compiled.
|
|
func validateConfigSchema(schema map[string]any) error {
|
|
compiler := jsonschema.NewCompiler()
|
|
if err := compiler.AddResource("schema.json", schema); err != nil {
|
|
return fmt.Errorf("invalid schema structure: %w", err)
|
|
}
|
|
if _, err := compiler.Compile("schema.json"); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ValidateWithCapabilities validates the manifest against detected capabilities.
|
|
// This must be called after WASM capability detection since Scrobbler capability
|
|
// is detected from exported functions, not manifest declarations.
|
|
func ValidateWithCapabilities(m *Manifest, capabilities []Capability) error {
|
|
// Scrobbler capability requires users permission
|
|
if hasCapability(capabilities, CapabilityScrobbler) {
|
|
if m.Permissions == nil || m.Permissions.Users == nil {
|
|
return fmt.Errorf("scrobbler capability requires 'users' permission to be declared in manifest")
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// HasExperimentalThreads returns true if the manifest requests experimental threads support.
|
|
func (m *Manifest) HasExperimentalThreads() bool {
|
|
return m.Experimental != nil && m.Experimental.Threads != nil
|
|
}
|