Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Pydantic Models for Validation #165

Conversation

FragmentedPacket
Copy link
Contributor

@FragmentedPacket FragmentedPacket commented Feb 26, 2024

  • Provide a PydanticManager for loading Pydantic models from libraries.
  • Add PydanticValidation to run the specific Pydantic model validation against data.
  • Allow Pydantic models to be loaded under the validator_directory as well.
  • Error messaging changes - Trying to make it more uniform to PASS, but not entirely sold on the [ERROR] line.

docs/custom_validators.md Outdated Show resolved Hide resolved
Co-authored-by: Christian Adell <[email protected]>
Copy link
Collaborator

@chadell chadell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suggestion looks reasonable to me. I would defer to @glennmatthews to add his review.

Copy link
Contributor

@glennmatthews glennmatthews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on a quick review it looks reasonable to me.

docs/custom_validators.md Show resolved Hide resolved
@@ -97,7 +97,24 @@ def top_level_properties(self):
"""
if not self._top_level_properties:
content = self._get_content()
self._top_level_properties = set(content.keys())
# TODO: Investigate and see if we should be checking this on initialization if the file doesn't exists or is empty.
if not content:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be something like if content is None? Or is it intentional that if content is an empty dict, empty str, or empty list then _top_level_properties is unchanged?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is intentional. We can exit early if there is not content aka no data in the variable it found.

I was thinking we should handle this in the find_files function. If the variable file is empty, no reason to worry about the file any longer (it won't have top level properties since it doesn't have content).

schema_enforcer/schemas/validator.py Show resolved Hide resolved
schema_enforcer/schemas/validator.py Outdated Show resolved Hide resolved
schema_enforcer/schemas/validator.py Outdated Show resolved Hide resolved
tests/test_ansible_inventory.py Outdated Show resolved Hide resolved
…dPacket/schema-enforcer into feat/pydantic-model-validation
…en encountering invalid package/module when loading Pydantic models from an external package. Minor changes to address feedback.
Copy link
Contributor

@glennmatthews glennmatthews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still looks solid. Thanks for the updates!

@glennmatthews glennmatthews merged commit e5d737b into networktocode:develop Mar 7, 2024
16 checks passed
@FragmentedPacket FragmentedPacket deleted the feat/pydantic-model-validation branch March 8, 2024 02:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants