23andMe / Yamale

A schema and validator for YAML.
MIT License
655 stars 88 forks source link

Check if a key present in map #235

Open nirupbbnk opened 7 months ago

nirupbbnk commented 7 months ago

properties: caseID: type: string description: some description detailed_goal: type: string description: some description for goal context: type: string description: some description for context

This is my data , here i want to validate if map has key context , we want to check only if context is present , rest keys are dynamic and may change, We want to validate only context key is present , rest keys can be anything,

properties: map(key=regex('context'))

Currently I am using this , but validation fails as it has other keys , (as other keys are dynamic we can't have static value )

nbaju1 commented 4 months ago

Quite an old issue, but I believe this will do what you want:

Schema:

properties: include('props', required=True, strict=False)
---
props:
    context: include('cont', required=True)     
---
cont:
    type: str()
    description: str()    

This assumes your data is on the following form:


properties:
    context:
        type: string
        description: A string value
    other_key:
        type: string
        description: A string value