Skip to content

Conversation

@vinnividivicci
Copy link
Contributor

Problem:
The cardinality variable was only assigned for three specific cases:

  • minOccurs=1, maxOccurs="unbounded" → "required"
  • minOccurs=0, maxOccurs="unbounded" → "optional"
  • minOccurs=0, maxOccurs=0 → "prohibited"

However, the IDS schema allows other valid combinations such as:

  • minOccurs=0, maxOccurs=1 (commonly used for optional specifications)
  • minOccurs=1, maxOccurs=1 (exactly one occurrence required)
  • Any other valid XML Schema cardinality values

When processing IDS files with these combinations, the cardinality variable remained unassigned, causing an UnboundLocalError.

Solution:
Added fallback logic to handle all valid IDS cardinality combinations:

  • If minOccurs >= 1: cardinality = "required" (must occur at least once)
  • Otherwise (minOccurs == 0): cardinality = "optional" (may occur)

This maintains semantic compatibility with the existing codebase, which expects cardinality to be one of the semantic strings ("required", "optional", "prohibited") rather than numeric ranges.

The report_specification() method in the Json reporter class was raising
an UnboundLocalError when processing IDS specifications with certain
minOccurs/maxOccurs combinations that weren't explicitly handled.

Problem:
The cardinality variable was only assigned for three specific cases:
- minOccurs=1, maxOccurs="unbounded" → "required"
- minOccurs=0, maxOccurs="unbounded" → "optional"
- minOccurs=0, maxOccurs=0 → "prohibited"

However, the IDS schema allows other valid combinations such as:
- minOccurs=0, maxOccurs=1 (commonly used for optional specifications)
- minOccurs=1, maxOccurs=1 (exactly one occurrence required)
- Any other valid XML Schema cardinality values

When processing IDS files with these combinations, the cardinality
variable remained unassigned, causing an UnboundLocalError at line 382
when attempting to use it in ResultsSpecification().

Solution:
Added fallback logic to handle all valid IDS cardinality combinations:
- If minOccurs >= 1: cardinality = "required" (must occur at least once)
- Otherwise (minOccurs == 0): cardinality = "optional" (may occur)

This maintains semantic compatibility with the existing codebase, which
expects cardinality to be one of the semantic strings ("required",
"optional", "prohibited") rather than numeric ranges. This is critical
for:
- HTML template rendering (line 457: .capitalize())
- Conditional logic for skipped specs (line 454)
- UI rendering for prohibited specs (line 456)

Testing:
- Tested with IDS file containing minOccurs=0 without explicit maxOccurs
  (defaults to 1 per XML Schema specification)
- Validation now completes successfully without UnboundLocalError
- HTML report generation works correctly with semantic cardinality labels
- Maintains backward compatibility with existing IDS files

Fixes: Validation failure when using valid IDS cardinality combinations
@vinnividivicci
Copy link
Contributor Author

The build is failing, but it doesn't seem to have anything to do with my commit..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants