feat(Endpoint): Add title and description attributes to Endpoint attribute
Summary
This PR adds support for title and description parameters to the Endpoint attribute, allowing developers to set custom OpenAPI operation summaries and descriptions directly via the attribute.
Changes Made
1. Enhanced Endpoint Attribute
-
File:
src/Attributes/Endpoint.php - Added
titleanddescriptionproperties to theEndpointattribute - Updated constructor to accept these new parameters
-
titlemaps to OpenAPIsummaryfield -
descriptionmaps to OpenAPIdescriptionfield
2. Updated RequestEssentialsExtension
-
File:
src/Support/OperationExtensions/RequestEssentialsExtension.php - Added
setTitleAndDescriptionFromEndpointAttribute()method - Extracts title and description from
Endpointattribute and sets them on the operation - Integrated into the main extension flow
3. Fixed RequestBodyExtension Override Issue
-
File:
src/Support/OperationExtensions/RequestBodyExtension.php - Modified to conditionally set summary and description from PHPDoc comments
- Only sets these values if they haven't already been set by other extensions (e.g.,
Endpointattribute) - This prevents the
Endpointattribute values from being overridden
Usage Examples
Basic Title
#[Endpoint(title: 'Get User Profile')]
public function show(User $user) {
return $user;
}
Title and Description
#[Endpoint(
title: 'Create New User',
description: 'Creates a new user account with the provided information'
)]
public function store(CreateUserRequest $request) {
// ...
}
Combined with Operation ID
#[Endpoint(
operationId: 'users.update',
title: 'Update User',
description: 'Updates an existing user with new information'
)]
public function update(UpdateUserRequest $request, User $user) {
// ...
}
Testing
All existing tests continue to pass, and new tests have been added to verify:
- ✅ Title setting via
Endpointattribute - ✅ Description setting via
Endpointattribute - ✅ Combined title and description usage
- ✅ Integration with existing
operationIdfunctionality - ✅ Proper precedence where
Endpointattribute values take priority over PHPDoc comments
Technical Details
Extension Execution Order
The fix addresses an issue where RequestBodyExtension was running after RequestEssentialsExtension and unconditionally overriding the operation's summary and description with PHPDoc values. The solution ensures that:
-
RequestEssentialsExtensionsets title/description fromEndpointattribute -
RequestBodyExtensiononly sets values from PHPDoc if not already set -
Endpointattribute values take precedence over PHPDoc comments
OpenAPI Mapping
-
Endpoint::$title→ OpenAPIsummary -
Endpoint::$description→ OpenAPIdescription
This follows OpenAPI 3.0 specification where:
-
summaryis a short summary of what the operation does -
descriptionis a verbose explanation of the operation behavior
Backward Compatibility
This change is fully backward compatible:
- Existing
Endpointattributes continue to work unchanged - PHPDoc-based documentation continues to work when
Endpointattributes don't specify title/description - No breaking changes to existing APIs or functionality
Related Issues
This enhancement improves the developer experience by allowing more granular control over OpenAPI documentation directly through attributes, reducing the need for PHPDoc comments for basic operation metadata.