Yamale icon indicating copy to clipboard operation
Yamale copied to clipboard

Subset not working with includes

Open sbliven opened this issue 2 years ago • 3 comments

The subset validator accepts both single items and lists when used with primitives. However it does not validate single objects when included.

schema.yaml

primative_list: subset(str())
primative_single: subset(str())
complex_list: subset(include('person'))
complex_single: subset(include('person'))
---
person:
  first: str()
  last: str()

test.yaml

primative_list:
- foo
- bar
primative_single: foo
complex_list:
- first: joe
  last: dread
- first: sam
  last: scott

# Should validate but doesn't
complex_single:
  first: fred
  last: jones

Errors

complex_single.last: Required field missing
complex_single.first: Required field missing

This seems potentially related to #133 and #217, which also involve errors when combining validators.

sbliven avatar Oct 24 '23 21:10 sbliven

Hey This is a big thing. Please prioritize this.

fclante avatar Jun 28 '24 11:06 fclante

We have a similar issue to this but in this case i believe its a mismatch between the schema intent and actual data structure.

subset validates a list so:

complex_single: subset(include('person'))

should be :

complex_single: any(include('person'))

HenrikDK avatar Nov 08 '24 19:11 HenrikDK

@HenrikDK Your examples don't quite match the schema intent. I think you are suggesting this work-around:

complex_list: any(include('person'), list(include('person')))
complex_single: any(include('person'), list(include('person')))

While this works, it's much more verbose than subset.

sbliven avatar Dec 03 '24 15:12 sbliven