alecthomas / voluptuous

CONTRIBUTIONS ONLY: Voluptuous, despite the name, is a Python data validation library.
https://pypi.org/project/voluptuous
BSD 3-Clause "New" or "Revised" License
1.82k stars 218 forks source link

Suggestion: Add version attribute to schemas #391

Closed rawrgulmuffins closed 5 years ago

rawrgulmuffins commented 5 years ago

I'm currently using Voluptuous to validate JSON objects that are passed between different AWS lambda functions. My expectation is that the data that's passed between the lambda's in question will migrate over time.

Currently I'm appending a version string to each schema object after creation. so

import distutils
lambda_schema = voluptuous.Schema({ ... })
lambda_schema.__version__ = distutils.version.StrictVersion("0.1.0")

I think it would be more convenient to have schema versions using a similar principle to the extend method for the schema class right now. So, for example, you would be able to say something like

lambda_schema = voluptuous.Schema({ ... }, version="0.1.0")
lambda_schema.add_version(voluptuous.Schema({ ... }, version="0.1.1")

lambda_schema(test_record, version="0.1.1") # passes in this example
lambda_schema(test_record, version="0.1.0") # fails

The use case would be a supported method of tracking schema migrations over time built into the library itself.

alecthomas commented 5 years ago

I like the concept but not for core Voluptuous. I’d be happy to link to a separate project implementing this.