forked from ruby-grape/grape
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix unknown validator exception when using requires/optional with Ent…
…ity (ruby-grape#2338) * Fix crash when using requires/optional with Entity when that entity specifies keywords that grape interprets as custom validators, ie: is_array, param_type, etc. This PR changes it so that it skips looking for a custom validator for those special documentation keywords. This allows you to do something like: ```rb desc 'Create some entity', entity: SomeEntity, params: SomeEntity.documentation params do requires :none, except: %i[field1 field2], using: SomeEntity.documentation end post do ... end ``` and SomeEntity can specify documentation like: ```rb class SomeEntity < Grape::Entity expose :id, documentation: { type: Integer, format: 'int64', desc: 'ID' } expose :name, documentation: { type: String, desc: 'Name', require: true, param_type: 'body' } expose :array_field, documentation: { type: String, desc: 'Array Field', require: true, param_type: 'bold' } end ``` and it won't crash on startup and give you correct documentation and param validation to boot. Open questions: 1. Is this an exhaustive list of keywords? 2. Is there a better way to maintain/get the list of keywords? 3. Is there a better approach altogeher? * Cleanup code and add to existing tests that fail without these changes. * Update after merge with master * PR feedback
- Loading branch information
Showing
4 changed files
with
16 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters