-
-
Notifications
You must be signed in to change notification settings - Fork 21
API self-documentation #17
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
Labels
enhancement
New feature or request
Comments
Part of this is attribute types. Perhaps this could be done with alias methods that define a type description, validator, ± a transformer: $type->attribute('firstName')
->required()
->string();
// behind the scenes, equivalent to:
$type->attribute('firstName')
->validate(function ($fail, $value) {
if (empty($value)) {
$fail('This field is required');
}
})
->type('string')
->validate(function ($fail, $value) {
if (! is_string($value)) {
$fail('This field must be a string');
}
}); $type->attribute('updatedAt')
->datetime();
// behind the scenes, equivalent to:
$type->attribute('updatedAt')
->type('datetime')
->validate(function ($fail, $value) {
if (! DateTime::createFromFormat(DateTime::ISO8601, $value)) {
$fail('This field must be a date in ISO8601 format');
}
})
->transform(function ($value) {
return DateTime::createFromFormat(DateTime::ISO8601, $value);
}); $type->attribute('status')
->enum(['draft', 'active', 'archived']);
// behind the scenes, equivalent to:
$type->attribute('updatedAt')
->type("'draft' | 'active' | 'archived'")
->validate(function ($fail, $value) {
if (! in_array($value, ['draft', 'active', 'archived'])) {
$fail('Must be one of: draft, active, archived');
}
}); |
Some changes will also be necessary to allow endpoint documentation: $type->listable()
->description('blah')
->meta('foo', 'bar'); |
Closing in favour of #62 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The text was updated successfully, but these errors were encountered: