Skip to content

Example BGP custom data validator not working #113

Description

@Glynn608

Environment

  • Python version:
$ python3 --version
Python 3.9.6
  • schema-enforcer version:
jsonschema==3.2.0
schema-enforcer==1.1.0

Expected Behavior

The schema should load and validate data against the validate function with exits of self.add_validation_error() and self.add_validation_pass()

Observed Behavior

The schema appears to be registering but doesn't action anything in the script.

Steps to Reproduce

  1. Install the dependancies
  2. Follow this guide - https://blog.networktocode.com/post/schema-enforcer-custom-validators/
  3. https://github.com/networktocode/schema-enforcer/blob/develop/docs/custom_validators.md

Side note, the example4 folder doesn't seems to exist like in the blog post, does anyone have a working example of custom validators using https://github.com/networktocode/schema-enforcer/blob/develop/docs/custom_validators.md#basevalidation?

Maybe I'm missing something in the .toml file? Any examples?

Activity

  1. chipn commented on Sep 16, 2021

    @chipn
    Contributor

    Thanks for submitting this issue, @Glynn608.

    We may have introduced a breaking change which impacted the CheckARIN example. I'm working through that now, but in that case, the validator fails completely. It sounds like you may be seeing something different.

    Can you confirm which example you tried to use? Was it the CheckARIN example or your own code?

  2. Glynn608 commented on Sep 16, 2021

    @Glynn608
    Author

    Initially it was my own code. It didn't fail it, just seemed to not do anything. No errors, no logs.

    I moved onto the CheckARIN example as I assumed I was missing something but also had no luck with that either 🙂

    Can you tag me in the PR with working example when you get round to it please.

  3. chipn commented on Sep 16, 2021

    @chipn
    Contributor

    I've updated the example from the blog and submitted PR #114. Give that a try and let me know if you have any issues.

    I'll update the documentation and tests separately, but that PR will give you a starting point.

    Also, the default behavior of schema-enforcer is to only output errors. You can use the --show-pass flag to see the files that pass.

  4. Glynn608 commented on Sep 17, 2021

    @Glynn608
    Author

    This was a great help I have it functioning now. My config wasn't finding the validators folder :(

    Follow up question, is it intended that the validators folder lives in the schema/ main dir or the dir where the CLI command is executed? Currently the default is the dir where the command is executed.

    gwindebank@gwindeban35-mac [chipn/validator-example]example4
    $ tree
    .
    ├── host_vars
    │   ├── az_rtr_01
    │   │   └── peers.yml
    │   └── az_rtr_02
    │       └── peers.yml
    ├── schema
    │   ├── definitions
    │   ├── schemas
    │   ├── tests
    │   └── validators
    └── validators
        ├── __pycache__
        │   └── check_arin.cpython-39.pyc
        └── check_arin.py
    

    It might be nice to add an example .toml file and other folders to example 4 and update the defaults for validators in the docs https://github.com/networktocode/schema-enforcer/blob/main/docs/configuration.md#default-configuration-settings

  5. chipn commented on Sep 17, 2021

    @chipn
    Contributor

    The default is validators in the current directory which is why the default doc doesn't include the language about being nested in main_directory. You can configure it to be nested by adding this to your pyproject.toml file:

    [tool.schema_enforcer]
    validator_directory = "schema/validators"
    

    I'm open to switching the default to being nested in the main_directory along with the others though.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions