Skip to content

feat(annotations): add #[Consumes] for per-method content type control - #152

Merged
usernane merged 3 commits into
mainfrom
dev
Aug 2, 2026
Merged

feat(annotations): add #[Consumes] for per-method content type control#152
usernane merged 3 commits into
mainfrom
dev

Conversation

@usernane

@usernane usernane commented Aug 2, 2026

Copy link
Copy Markdown
Member

Summary

Add a new #[Consumes] attribute that allows service methods to declare which content types they accept in the request body, overriding the default allowed types.

Motivation

WebServicesManager::POST_CONTENT_TYPES is hardcoded to only allow form-urlencoded, multipart, and JSON. This blocks developers from using proper WebService classes for endpoints that accept raw binary uploads, XML, CSV, or other content types. Fixes #151.

Changes

  • Added Annotations/Consumes.php attribute class (mirrors #[Produces] structure)
  • Refactored WebServicesManager::process() to defer content type validation until after service resolution, enabling #[Consumes] awareness
  • Added getConsumesTypes() and isParseableContentType() helper methods
  • Skip parameter filtering for non-parseable content types allowed by #[Consumes]
  • Integrated #[Consumes] and #[Produces] into OpenAPI spec generation (toPathItemObj())
  • Added buildRawRequestBody() for binary upload endpoints in OpenAPI output
  • Added 12 tests in ConsumesAnnotationTest
  • Added example in examples/03-annotations/03-consumes/

How to Test / Verify

Unit tests cover all behaviors:

composer test -- --filter ConsumesAnnotationTest

Full suite passes (640 tests, 1883 assertions):

composer test

Breaking Changes and Migration Steps

None. Fully backward compatible:

  • Without #[Consumes], behavior is identical to before (default 3 types apply)
  • isContentTypeSupported() signature adds an optional nullable parameter (no BC break for callers)

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 #151

Add a new #[Consumes] attribute that allows service methods to declare
which content types they accept in the request body, overriding the
default allowed types (form-urlencoded, multipart, JSON).

- Create Annotations/Consumes.php attribute class
- Refactor WebServicesManager::process() to defer content type check
  until after service resolution for #[Consumes] awareness
- Skip parameter filtering for non-parseable content types (e.g.
  application/octet-stream) allowed by #[Consumes]
- Integrate #[Consumes] and #[Produces] into OpenAPI spec generation
- Add buildRawRequestBody() for binary upload endpoints in OpenAPI
- Add 12 tests in ConsumesAnnotationTest covering all behaviors
- Add example in examples/03-annotations/03-consumes/

Closes #151
Comment thread examples/03-annotations/03-consumes/FileUploadService.php Dismissed
Ibrahim BinAlshikh added 2 commits August 2, 2026 23:47
Add .gitattributes with eol=lf and renormalize all files.
This silences CRLF warnings and standardizes the repo.
@codecov

codecov Bot commented Aug 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.02564% with 28 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.37%. Comparing base (178b522) to head (d93ff10).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
WebFiori/Http/WebService.php 90.62% 21 Missing ⚠️
WebFiori/Http/WebServicesManager.php 91.37% 5 Missing ⚠️
WebFiori/Http/OpenAPI/OperationObj.php 71.42% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #152      +/-   ##
============================================
- Coverage     93.84%   93.37%   -0.48%     
- Complexity     1363     1396      +33     
============================================
  Files            39       39              
  Lines          3314     3410      +96     
============================================
+ Hits           3110     3184      +74     
- Misses          204      226      +22     
Flag Coverage Δ
php-8.1 93.37% <91.02%> (-0.48%) ⬇️
php-8.2 93.25% <91.02%> (-0.47%) ⬇️
php-8.3 93.25% <91.02%> (-0.47%) ⬇️
php-8.4 93.25% <91.02%> (-0.47%) ⬇️
php-8.5 93.25% <91.02%> (-0.47%) ⬇️

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.

@sonarqubecloud

sonarqubecloud Bot commented Aug 2, 2026

Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed

Issues
3 New issues
1 Accepted issue

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

@usernane usernane self-assigned this Aug 2, 2026
@sonarqubecloud

sonarqubecloud Bot commented Aug 2, 2026

Copy link
Copy Markdown

@usernane
usernane merged commit 48e4234 into main Aug 2, 2026
16 of 18 checks passed
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(content-type): Add #[Consumes] annotation for per-service content type control

2 participants