23andMe / Yamale

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

schema.add_include having issue #198

Closed daljeet-singh closed 2 years ago

daljeet-singh commented 2 years ago

Maybe I am not using it correctly, New to yamale. I am trying to add extra validation to the schema, but it doesn't seem to be working.

schema = yamale.make_schema('./schema.yaml'))
schema.add_include({  'last_name': 'str(Required=True)' })

It doesn't seem to add this to schema validation.

My use case is, to add additional rules to the schema on the fly before validation.

mildebrandt commented 2 years ago

Hi, thanks for your interest in Yamale.

The add_include API will add another document to the schema. For example, let's say I had this schema:

person: include('human')
---
human:
    name: str()
    age: int()
    friend: include('human', required=False)

I could write that inline in Python like this:

schema = yamale.make_schema(content="""
person: include('human')
""")

schema.add_include(
    {
        "human": {
            "name": "str()",
            "age": "int()",
            "friend": "include('human', required=False)",
        }
     }
)

As of today, there isn't a way to dynamically add to the schema once the schema object is created. You would need to parse the yaml yourself, add any additions you need, and then call make_schema on the new content.

I hope that makes it a little more clear. Please let us know if you have any other questions.

daljeet-singh commented 2 years ago

Thanks, I guess we can close this issue :-)