Skip to content

feat(annotations): add allowEmpty parameter to #[RequestParam] attribute#149

Merged
usernane merged 2 commits into
mainfrom
dev
Jun 25, 2026
Merged

feat(annotations): add allowEmpty parameter to #[RequestParam] attribute#149
usernane merged 2 commits into
mainfrom
dev

Conversation

@usernane

@usernane usernane commented Jun 25, 2026

Copy link
Copy Markdown
Member

Summary

Add allowEmpty parameter to the #[RequestParam] attribute, allowing annotation-driven services to accept empty strings.

Motivation

Users could not allow empty strings via annotations — they had to fall back to the imperative addParameters() approach with ParamOption::EMPTY => true. Fixes #148.

Changes

  • Added public readonly bool $allowEmpty = false to RequestParam attribute constructor
  • Added mapping in configureParametersFromMethod() to set ParamOption::EMPTY => true when allowEmpty is true
  • Added AllowEmptyParamService test service and AllowEmptyParamTest with 3 test cases
  • Updated README with allowEmpty attribute usage example

How to Test / Verify

Unit tests: composer test -- --filter AllowEmptyParamTest

All 628 existing tests pass with no regressions.

Breaking Changes and Migration Steps

None. The new parameter defaults to false, preserving existing behavior.

Checklist

  • I reviewed my own diff before requesting review
  • My commits follow Conventional Commits
  • I added/updated tests (or explained why not)
  • I updated docs (if needed) Docs Repo
  • I ran lint/cs-fixer (if applicable) (composer fix-cs)
  • I considered backward compatibility
  • I considered security

Related issues

Closes #148

Add allowEmpty parameter to the RequestParam attribute constructor,
allowing annotation-driven services to accept empty strings without
falling back to the array-based addParameters() approach.

The parameter maps to ParamOption::EMPTY in configureParametersFromMethod().

Closes #148
@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 93.84%. Comparing base (4b3efd3) to head (178b522).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
WebFiori/Http/WebService.php 75.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #149      +/-   ##
============================================
- Coverage     93.86%   93.84%   -0.03%     
- Complexity     1361     1363       +2     
============================================
  Files            39       39              
  Lines          3310     3314       +4     
============================================
+ Hits           3107     3110       +3     
- Misses          203      204       +1     
Flag Coverage Δ
php-8.1 93.84% <75.00%> (-0.03%) ⬇️
php-8.2 93.72% <75.00%> (-0.03%) ⬇️
php-8.3 93.72% <75.00%> (-0.03%) ⬇️
php-8.4 93.72% <75.00%> (-0.03%) ⬇️
php-8.5 93.72% <75.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…ass-level AllowAnonymous

- Update single-service examples to use RequestProcessor instead of WebServicesManager
- Remove unnecessary isAuthorized()/processRequest() boilerplate from annotation examples
- Add examples/05-testing with ServiceTestCase usage
- Add examples/03-annotations/02-allow-empty demonstrating allowEmpty
- Fix checkMethodAuthorization() to respect class-level #[AllowAnonymous]
- Update README testing section to use ServiceTestCase
@sonarqubecloud

Copy link
Copy Markdown

@usernane usernane merged commit 01e4204 into main Jun 25, 2026
16 of 18 checks passed
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(annotations): Add allowEmpty parameter to #[RequestParam] attribute

1 participant