-
Notifications
You must be signed in to change notification settings - Fork 154
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
Adding Type and Nullability Validation to exposed fields #386
Comments
Does And yes, validation would be definitely very useful if the above doesn’t work. When used with grape I’d want to rely on its type checking mechanisms for consistency. |
mmh, grape-entity is a presenting layer, so the data should be valid before it will be presented, |
@LeFnord i think the idea is that you can use entities to receive data in the same format as presented |
While I tend to agree. In the case of |
Ah I see there is some confusion. I agree the parameters can indeed be modeled with |
could you elaborate how this would work 🤔 |
Hello 👋
I am creating this ticket to ask if it would be possible to introduce type validation to exposed fields.
Currently there is not checking if the exposed fields are of a specified type. We can add documentation to specify a type (that is then exposed as part of the swagger docs) but if there is a mismatch there is no way for the server to validate this break in contract.
I am thinking we can add type validation (using dry-types or dry-validation) to the exposed fields (maybe after formatting). This would of course be opt-in with the expose DSL method accepting two new options
type (this is the type the field should be or be coercible to) a dry type or standard ruby type like Numeric.
nullable a boolean field to validate if the value can be nil or not.
These options then can be used to populate the swagger documentation automatically without specifying them in the documents hash.
I am happy to start contribute this feature but first want to check if the maintainers @dblock & @LeFnord are okay with it 😅
The text was updated successfully, but these errors were encountered: