Skip to content

Add wrap parameter to JsonResponse - #55

Merged
DerManoMann merged 1 commit into
mainfrom
feature/json-response-wrap
Jun 14, 2026
Merged

Add wrap parameter to JsonResponse#55
DerManoMann merged 1 commit into
mainfrom
feature/json-response-wrap

Conversation

@DerManoMann

@DerManoMann DerManoMann commented Jun 13, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add wrap parameter to JsonResponse (Attributes + Annotations), default 'data'
  • Processor generates an inline wrapper schema with the wrap key as a required property containing the $ref
  • Remove DataSchema — wrapping is a transport concern, not a data shape concern (see ADR-004)
  • Move $_blacklist from JsonContentTrait to each consuming class

Usage

// Wrapped (default): {"data": {$ref: UserResource}}
#[OAX\JsonResponse(response: 200, ref: UserResource::class)]

// Custom wrap key: {"result": {$ref: UserResource}}
#[OAX\JsonResponse(response: 200, ref: UserResource::class, wrap: 'result')]

// Unwrapped — use the regular response annotation
#[OAT\Response(response: 200, content: new OAT\JsonContent(ref: UserResource::class))]

Breaking changes

  • DataSchema removed — use OA\Schema on resources, wrapping now lives on the response attribute
  • JsonResponse now wraps by default — existing bare-ref responses will gain an envelope

Test plan

  • Existing tests updated and passing (70 tests)
  • New tests for default wrap and custom wrap key
  • composer test (PHPUnit + CS Fixer + Rector) green

🤖 Generated with Claude Code

@DerManoMann
DerManoMann force-pushed the feature/json-response-wrap branch 11 times, most recently from c2c420d to 0ca4d59 Compare June 14, 2026 07:30
Wrapping is a transport concern, not a data shape concern (ADR-004).
JsonResponse now wraps resolved content via a late WrapJsonResponseContent
processor that runs after MergeJsonContent.

Changes:
- Add `wrap` parameter to JsonResponse (default 'data')
- Add WrapJsonResponseContent processor (after MergeJsonContent)
- Remove DataSchema (superseded by wrap)
- Remove JsonContentTrait (inlined source into each class)
- Remove `type` parameter from JsonResponse and JsonRequestBody
- Bump swagger-php minimum to ^6.2.0 (for removeAnnotation)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@DerManoMann
DerManoMann force-pushed the feature/json-response-wrap branch from 0ca4d59 to 0bcf001 Compare June 14, 2026 07:39
@DerManoMann
DerManoMann merged commit f569b3b into main Jun 14, 2026
7 checks passed
@DerManoMann
DerManoMann deleted the feature/json-response-wrap branch June 14, 2026 07:41
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.

1 participant