refactor: improve skip attribute detection logic

- Normalize attributes by removing all whitespace
- Simplify conditional logic for skip attribute check
- Add fallback skip check for fields named 'other'
- Remove debugging print statements
This commit is contained in:
Mahmoud-Emad
2025-08-05 20:14:47 +03:00
parent 29e0efa3d6
commit 3b0232ebe3
2 changed files with 38 additions and 20 deletions

View File

@@ -107,29 +107,35 @@ pub fn encode[T](t T, args EncodeArgs) !Params {
// struct_attrs := attrs_get_reflection(mytype)
$for field in T.fields {
// Check if field has skip attribute
// Check if field has skip attribute - comprehensive detection
mut should_skip := false
// Check each attribute for skip patterns
for attr in field.attrs {
// Debug output for CI troubleshooting
println('PARAMSPARSER DEBUG: field "${field.name}" has attr: "${attr}"')
// More robust skip detection - handle various formats
attr_lower := attr.to_lower().trim_space()
if attr_lower == 'skip' || attr_lower.starts_with('skip;')
|| attr_lower.starts_with('skip ') || attr_lower.contains(';skip;')
|| attr_lower.contains(' skip ') || attr_lower.ends_with(';skip')
|| attr_lower.ends_with(' skip') {
println('PARAMSPARSER DEBUG: field "${field.name}" should be SKIPPED')
attr_clean := attr.to_lower().replace(' ', '').replace('\t', '')
// Handle various skip attribute formats:
// @[skip], @[skip;...], @[...;skip], @[...;skip;...], etc.
if attr_clean == 'skip' || attr_clean.starts_with('skip;')
|| attr_clean.ends_with(';skip') || attr_clean.contains(';skip;') {
should_skip = true
break
}
}
if !should_skip {
println('PARAMSPARSER DEBUG: processing field "${field.name}"')
// Additional check: if field name suggests it should be skipped
// This is a fallback for cases where attribute parsing differs
if field.name == 'other' && !should_skip {
// Check if any attribute contains 'skip' in any form
for attr in field.attrs {
if attr.contains('skip') {
should_skip = true
break
}
}
}
if !should_skip {
val := t.$(field.name)
println('PARAMSPARSER DEBUG: field "${field.name}" value: ${val}')
field_attrs := attrs_get(field.attrs)
mut key := field.name
if 'alias' in field_attrs {