isShape validator and better documentation generation#183
Open
isShape validator and better documentation generation#183
Conversation
Added extra arguments to the wrapper function to be able to describe what is required and can't be empty along with a helper for formatting that information.
This makes processResult work better with isShape.
PAkerstrand
reviewed
Jun 21, 2017
| */ | ||
| export default function writeInfoInline(type, canBeEmpty, required) { | ||
| const empty = canBeEmpty ? '?' : ''; | ||
| return type && `${required ? `<${empty}${type}>` : `[${empty}${type}]`}`; |
There was a problem hiding this comment.
Do we want to force this to always return a string? Right now it'll return a falsy value or a string
Member
Author
There was a problem hiding this comment.
The idea is that type will only ever be the empty string, and because of that we will return the empty string. Could be discussed if it would be better to not have such implicit assumptions.
PAkerstrand
reviewed
Jun 21, 2017
| key: `${key}`, | ||
| value: input[key], | ||
| message: result, | ||
| }; |
There was a problem hiding this comment.
Would there be any way to create a composed validation error of all properties that failed to validate?
Member
Author
There was a problem hiding this comment.
The idea is to both fail early and to not overwhelm the user with error messages.
PAkerstrand
approved these changes
Jun 21, 2017
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a new validator that can be used most specifically for Hook validation.
This PR also improves the information in the documentation generation for
isArray,isObjectandoneOfvalidators giving information about the types that they wrap.This through a new syntax for the documentation generation when describing wrapped validators.
[TYPE]means that the type is optional,<TYPE>means that it is required. A question mark in front of the type,?TYPEmeans that it can be empty.Array(<String>)means thatnullandundefinedare allowed as values but not empty strings as an example.