Skip to content

Fail on keys not specified in the rules #29

@rakesh-voiger

Description

@rakesh-voiger

@ozziexsh

Would be nice to have an option to fail the validation when extra keys/data present than in the rules. It will be useful in the test case assertions to ensure API does not return any unwanted/protected data. Same for incoming requests also, it would be nice to inform the client when unsupported keys are given than ignoring them.

Without option

{ok, data} = Validate.validate(%{name: "joe", age: 30}, %{name: [type: string]})

data == %{name: "joe"}

With option, something like

{:error, _} = Validate.validate(%{name: "joe", age: 30}, %{name: [type: string]}, %{unknown: :reject})
# age not allowed

Your thoughts ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions