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

Fail validation on unexpected input #457

Open
HoneyryderChuck opened this issue May 17, 2018 · 2 comments
Open

Fail validation on unexpected input #457

HoneyryderChuck opened this issue May 17, 2018 · 2 comments

Comments

@HoneyryderChuck
Copy link

HoneyryderChuck commented May 17, 2018

Hi. this might be interpreted as a usability issue with the library, but I don't want to create an account with gitter, as it requests for too much information from my github account, making it difficult to join. If I may be so bold to suggest smth, a mailing list would have a lower barrier of entry.

Complete Description of Issue

I'm using reform contracts in the context of trailblazer for schema validation of a REST API. I've seen that unexpected properties being sent in a JSON payload will just be "cleared out", instead of generating an error. It has been said to me that this mimmicks the behaviour of rails strong parameters, which will also remove unexpected input, so I don't really have an issue with that. But I'd like to opt-in on different behaviour, i.e. fail the validation and generate errors like "Unexpected attribute" for wrong input. An example would be this kind of payload:

{"user": {"firzt_name": "John", "last_name": "Doe"} }

In this case, I'd like to generate an error for the firzt_name key, as the contract only states the first_name and last_name properties.

Is this actually configurable? Or is it completely missing?

@apotonick
Copy link
Member

Hi @HoneyryderChuck - this is missing. The underlying parser, the Representable gem, doesn't support this out-of-the-box. You could probably do that manually in a "virtual" populator, since it receives the parsed fragment.

BTW, the "clearing out" is due to the parsing gem, which existed many years before strong_parameters, any similar behavior is not intended. 😜

@HoneyryderChuck
Copy link
Author

@apotonick thx for the reply.

You could probably do that manually in a "virtual" populator...

Where do I find a tutorial on how to use a virtual populator?

BTW, the "clearing out" is due to the parsing gem..

I guess it makes sense to have this as the "default" behaviour, as this was probably done more to support url-encoded form validation, and JSON schema validation requirement came later. I'd say that one could keep it as the default, and "opt in" to an explicit failure. How hard would this be to implement?

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