Use pattern string instead of compiled pattern in field_specs.py #967
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
field_spec.py#965This PR replaces the compiled NS_PATTERN with the pattern string when creating the field specs.
A side effect of this change is that the pattern no longer needs the lookahead for length check, as we're specifying as part of the pydantic class and that carries into the JSON schema directly without it having to be part of the regex.
Copilot Summary
This pull request simplifies and standardizes the namespace pattern validation logic across several schema and utility files. The main change is the removal of an unnecessary length check from the regular expression pattern, relying instead on explicit
minLengthandmaxLengthconstraints. This makes the regex easier to maintain and ensures consistency between schema validation and Python-side checks.Most important changes:
Schema pattern updates:
(?=.{3,1000}$)) from thepatternfield in the JSON schema definitions forDecisionPoint_2_0_0.schema.json,DecisionPointGroup_2_0_0.schema.json,DecisionTable_2_0_0.schema.json,SelectionList_2_0_0.schema.json, andSsvcObjectRegistry_2_0_0.schema.json, so that the regex only enforces the namespace format, not its length. Length is now enforced solely by theminLengthandmaxLengthschema properties. [1] [2] [3] [4] [5] [6] [7]Python utility and test consistency:
src/ssvc/utils/patterns.pyto remove the length check from the pattern string, matching the schema change.src/ssvc/utils/field_specs.pyto use the raw pattern string from the compiled regex, ensuring consistency between the schema and Python validation.src/test/test_namespaces.pyto accumulate and report all unexpected matches, making debugging easier.