jpmckinney / validictory

🎓 deprecated general purpose python data validator
Other
240 stars 57 forks source link

Added a new option 'remove_unknown_properties' #86

Closed rkrzr closed 9 years ago

rkrzr commented 9 years ago

, which simply removes fields that are not in the schema (and does so recursively). Also a new test for this feature.

If both disallow_unknown_properties and remove_unknown_properties are given the former takes precedence and a SchemaError is thrown if unknown properties are present.

jamesturk commented 9 years ago

thanks for this, will be taking a closer look at it soon but it sounds reasonable to me.

out of curiosity mind sharing your use case?

rkrzr commented 9 years ago

Sure, the use case is the following:

I don't want to have to deal with unknown properties internally. I want to know for sure that I have all the data that is required but nothing more. But I don't want to reject requests that have all the required data, but also some additional data (what disallow_unknown_properties would do). Instead I'd like to accept these requests and filter out the stuff that's not in the schema. This is convenient in our case where the front-end tends to PUT back some data where some temporary data was added, that is only needed client-side.

In general it seems like a sensible default to me to filter out everything you don't need/know about. How do you deal with this?

jamesturk commented 9 years ago

This makes a lot of sense, definitely can see a lot of use.

I don't think I've ever used it in a place where unknown properties are a real concern like via a PUT, typically the data I've proceed w/ validictory is coming from a known source but we just want to make sure it is clean.