Expose options from simple alternation match() schemas in UI schema - #7023
Expose options from simple alternation match() schemas in UI schema#7023kingpanther13 wants to merge 4 commits into
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
It seems you haven't yet signed a CLA. Please do so here.
Once you do that we will be able to review and accept this pull request.
Thanks!
Review findings: unanchored patterns made options non-exhaustive hints (vol.Match is a prefix match), and an unescaped dot in the literal charset let wildcard patterns emit misleading options. Options are now exactly the values the pattern accepts. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This seems a rather small group. I think I'd prefer if we release a Samba app which forces the option to be lower case, then do a second release later where we switch from |
|
I originally was going to do a PR on Samba, but I went this direction because I was afraid that the change would silently break people's configs. If you feel that this isn't the right way to go I'll happily file a new PR against Samba instead. |
Yes, let's change the Samba config. The first step won't be a breaking change. The second step we can bundle with other changes like the new Netbios config default, and mark it clearly as a breaking change. |
Proposed change
Schema elements of type
match()are rendered in the UI as plain string fieldswith no suggestions, even when the regex is a simple alternation of literal
values. The Samba add-on's
enabled_shares(
match(^(?i:(addons|addon_configs|backup|config|media|share|ssl))$)) is thevisible case: the configuration UI shows a multi-value field with an empty
suggestion list (home-assistant/frontend#51510).
This extracts literal options from
match()patterns that are fully anchoredalternations of plain literals and includes them as
optionson the UI schemanode. Extraction is strictly conservative: the pattern must be anchored with
^...$, and any regex metacharacter, escape, class, quantifier, or nestedgroup falls back to current behavior. Options are deduplicated preserving
order, and the added tests assert that the emitted options are exactly the
values the pattern accepts (case-insensitively for
(?i)patterns), sosuggestions can never produce a value that fails validation.
Validation (
AppOptions) is unchanged: fields still validate against theoriginal regex, so values that only match case-insensitively remain accepted.
Add-on schemas cannot simply switch such fields to
list()without breakingexisting configs, since
list()validates case-sensitively.Surveyed all
match()patterns across the official add-ons repository and thelargest community repositories (hassio-addons, alexbelgium): 20 of 22 distinct
patterns are unchanged; 2 gain options, both verified to be exactly the
accepted value set.
The frontend counterpart that consumes
optionson multi-value string nodes:home-assistant/frontend#53077. Older frontends ignore the additional key.
Type of change
Additional information
documented in developers.home-assistant.io; authoring syntax is unchanged)
as
dict[str, Any]; the additive key needs no model change)Checklist
ruff format supervisor tests)If API endpoints or add-on configuration are added/changed: