Repository navigation
v1.2.0
Release Notes - v1.2.0
🎉 New Features
FormRequest User Context Support
The package now successfully extracts request bodies from Laravel FormRequest classes even when the rules() method depends on authenticated user context. This was a common issue when validation rules used $this->user() or $this->user()->id.
Example FormRequest that now works:
class StoreTransactionRequest extends FormRequest
{
public function rules(): array
{
return [
'receiver_id' => [
'required',
'exists:users,id',
Rule::notIn([$this->user()->id]), // ✅ Now works!
],
'amount' => [
'required',
'numeric',
'min:0.01',
function (string $attribute, mixed $value, Closure $fail) {
$sender = $this->user(); // ✅ Now works!
// ... validation logic
},
],
];
}
}Enhanced Closure-Based Validation Rule Handling
- Type Inference: The package now analyzes closure source code to infer field types (numeric, string, array, boolean, date, email)
- Closure Preservation: Closures are preserved during rule filtering and properly analyzed
- Better Detection: Improved detection of user context usage, numeric validation, and other patterns in closures
Config Override Request Body Creation
The applyEndpointOverrides() method now creates request bodies from config overrides when automatic extraction fails. Previously, it only added examples to existing request bodies.
Usage in config/docs-generate.php:
'endpoint_overrides' => [
'store' => [
'body' => [
'receiver_id' => 1,
'amount' => 100.50,
],
],
],The package will automatically:
- Create the request body schema if it doesn't exist
- Infer field types from example values
- Mark all fields as required
🔧 Improvements
Mock User Creation
The package now intelligently creates mock user objects by trying common User model classes:
App\Models\UserApp\UserIlluminate\Foundation\Auth\User
Falls back to a stdClass with id = 1 if none are available.
Better Source Code Parsing
- Handles
$this->user()calls in source code - Extracts
Rule::facade methods from validation arrays - Improved regex patterns for closure detection
- Better handling of nested validation rule arrays
Error Handling
- More robust fallback mechanisms when FormRequest instantiation fails
- Better error handling for user context dependencies
- Graceful degradation to source code parsing when needed
🐛 Bug Fixes
- Fixed issue where FormRequest classes with
$this->user()->idcalls would fail during docs generation - Fixed closure-based validation rules being filtered out incorrectly
- Fixed request body not being created from config overrides when FormRequest extraction failed
📝 Technical Details
New Helper Methods
createMockUser(): Creates a mock user object for FormRequest validationfilterValidationRules(): Filters validation rules while preserving closuresinferTypeFromClosureSource(): Infers field types from closure source code patterns
Enhanced Methods
extractSchemaFromFormRequest(): Now handles user context dependenciesapplyEndpointOverrides(): Can now create request bodies from configparseRulesArrayFromString(): Better closure and Rule:: method detectionparseClosureValidation(): Improved type inference from closure source
🔄 Migration Guide
No breaking changes! This release is fully backward compatible.
If you have FormRequest classes that previously failed to generate request bodies, they should now work automatically. If you were using config overrides as a workaround, those will continue to work and may now be used to create request bodies when extraction fails.
📦 Installation
Update to the latest version:
composer update provydon/docs-generate🙏 Credits
This release addresses a common issue reported by users working with authenticated FormRequest validation rules. Special thanks to the community for feedback and bug reports.
Full Changelog: v1.1.3...v1.2.0