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

Union of schemas #163

Closed
christian-oreilly opened this issue Dec 5, 2019 · 4 comments
Closed

Union of schemas #163

christian-oreilly opened this issue Dec 5, 2019 · 4 comments

Comments

@christian-oreilly
Copy link

christian-oreilly commented Dec 5, 2019

Proposed Functionality

I propose to modify the signature of Core.validate(...) to have something like

pykwalify.core.Core.validate(self, raise_exception=True, allow_union=False)

When allow_union == True

core = Core(source_file=source, schema_files=[schema1, schema2])
core.validate(allow_union=True)

would succeed with schema1:

type: map
mapping:
  level1:
    required: True
    type: map
    mapping:
      level2a:
        type: str

schema2:

type: map
mapping:
  level1:
    required: True
    type: map
    mapping:
      level2b:
        type: str

and source:

level1:
  - level2a : "allo:
  - level2b : "hello:

Use Case

I am coding a configuration manager package to use in some of my other projects. The idea is to have a class that manage configuration files specificied at various levels (application, project, user, ...). These different configuration files get merged into one configuration. Configuration files can be validated against schemas (using PyKwalify). I now need to merge schemas defined at these different levels so that a merged schema can be used to validate the merged configuration.

@Grokzen
Copy link
Owner

Grokzen commented Dec 5, 2019

Wait... just so i get this right. Do you want the schema to do a Deep merge between two different schemas into one single schema inside the lib itself and then do the merged validation on the data part? So in your example, the merged schema would be this?

type: map
mapping:
  level1:
    required: True
    type: map
    mapping:
      level2a:
        type: str
      level2b:
        type: str

@christian-oreilly
Copy link
Author

That would be the idea. I could do it upstream in my code and submit only the "merged" schema to PyKwalify, but it seemed like a feature that would sit better in PyKwalify (being reusable by other have a similar use case) than in my package where it would be harder to reuse in other projects.

@Grokzen
Copy link
Owner

Grokzen commented Dec 6, 2019

@christian-oreilly I and strongly leaning towards not supporting this feature mainly due to the reason that if i make some kind of schema union feature, i would have to take a strong stance on several different cases in how the union works with deep and nested data structures. And i am not willing to go down that route and define a certain method or rule set for how it would work inside the pykwalify core. I have in the past been thinking about the same kind of issue and same as then, i passed on it as it would just lead to more code to maintain and probably so many more config and tweak options down the line that i am just not willing to support in the end and would probably casue more harm or issues then what it is worth for me.

Basically what i am saying, is that it is not up to pykwalify to define how a schema union would work out, that Must be solved by the person that uses this tool. You have to provide a fully done schema to pykwalify and i will not change this behaviour.

If you are using this code as a lib inside your own application, then it should not be difficult to merge them before you send them into the Core class here.

@Grokzen Grokzen closed this as completed Dec 6, 2019
@christian-oreilly
Copy link
Author

Sure, no problem. I'll implement it on my side, Thanks for the fast feedback.

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

No branches or pull requests

2 participants