mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-10-14 02:56:36 +00:00
fix(web): render the config form from the schema the save route validates
The form read config_schema.json with a raw json.load while api_v3.save_plugin_config went through SchemaManager. Those are not the same schema: SchemaManager applies expand_style_elements, which turns a compact customization.x-style-elements declaration into the per-element blocks the form knows how to render. Without it, that customization object has an x-style-elements key and no "properties", so the template's object branch matched nothing and the section rendered as empty space -- while saving still validated against the expanded shape. of-the-day ships the compact form, so its customization section has been invisible in the web UI. pages_v3 gains a schema_manager the way it already has config_manager and plugin_manager. use_cache=False matches the save route, so an edited schema is not served stale during plugin development. The raw read stays as a fallback for callers that register this blueprint without one. Checked before making the change: load_schema does nothing here except read, validate and expand -- inject_skin_selector is a separate method it does not call -- so this is not a behaviour change for schemas without the declaration. The test pair renders the same compact schema with and without a SchemaManager, so it documents exactly what was broken as well as what is fixed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -22,6 +22,7 @@ logger = logging.getLogger(__name__)
|
||||
config_manager = None
|
||||
plugin_manager = None
|
||||
plugin_store_manager = None
|
||||
schema_manager = None
|
||||
|
||||
pages_v3 = Blueprint('pages_v3', __name__)
|
||||
|
||||
@@ -830,15 +831,40 @@ def _load_plugin_config_partial(plugin_id):
|
||||
except Exception as e: # nosec B110 - metadata pre-load is optional; schema loads fully below
|
||||
logger.debug("Metadata pre-load skipped for plugin %s: %s", plugin_id, e)
|
||||
|
||||
# Get plugin schema
|
||||
# Get plugin schema.
|
||||
#
|
||||
# Through SchemaManager, not a raw json.load, because that is what
|
||||
# the save route uses (api_v3.save_plugin_config) -- and the two
|
||||
# disagreeing is not academic. SchemaManager applies
|
||||
# expand_style_elements, which turns a compact
|
||||
# customization.x-style-elements declaration into the per-element
|
||||
# blocks this form renders. Reading the file directly meant a plugin
|
||||
# using that form (of-the-day ships one) had a customization section
|
||||
# that rendered nothing at all, while saving still validated against
|
||||
# the expanded shape.
|
||||
#
|
||||
# use_cache=False matches the save route: a plugin's schema changes
|
||||
# on disk during development, and a cached copy would keep serving
|
||||
# the old form.
|
||||
#
|
||||
# The raw read stays as a fallback for callers that never set a
|
||||
# schema_manager (several tests, and any embedder of this blueprint).
|
||||
schema = {}
|
||||
schema_path = _plugin_dir / "config_schema.json"
|
||||
if schema_path.exists():
|
||||
schema_mgr = getattr(pages_v3, 'schema_manager', None)
|
||||
if schema_mgr is not None:
|
||||
try:
|
||||
with open(schema_path, 'r', encoding='utf-8') as f:
|
||||
schema = json.load(f)
|
||||
schema = schema_mgr.load_schema(plugin_id, use_cache=False) or {}
|
||||
except Exception as e:
|
||||
logger.warning("Could not load schema for plugin: %s", e)
|
||||
logger.warning("SchemaManager could not load schema for %s: %s",
|
||||
plugin_id, e)
|
||||
if not schema:
|
||||
schema_path = _plugin_dir / "config_schema.json"
|
||||
if schema_path.exists():
|
||||
try:
|
||||
with open(schema_path, 'r', encoding='utf-8') as f:
|
||||
schema = json.load(f)
|
||||
except Exception as e:
|
||||
logger.warning("Could not load schema for plugin: %s", e)
|
||||
|
||||
# Get web UI actions from plugin manifest
|
||||
web_ui_actions = []
|
||||
|
||||
Reference in New Issue
Block a user