Add FormRequests + a Resource to the leave and attendance APIs (#34) - #5
Merged
Conversation
The API controllers validated with inline Validator::make, which Scramble
cannot read, so the request bodies at /docs/hrm came out empty. Two write
endpoints now take typed FormRequests that extend the app's ApiFormRequest,
so Scramble infers the request schema and the validation-failure envelope is
unchanged:
- StoreLeaveRequest for POST leave-request (no employee_id, files leave for
the authenticated user; attachment typed as a file)
- ClockInOutRequest for POST clock-in-out
LeaveApplicationResource replaces the leave shape that was hand-copied into
both the list and create responses. The two copies had drifted: the list
fell back to avatar.png for a missing attachment, create fell back to an
empty string. Both now use the list's fallback, which is what a client sees
on later reads. Output keys are otherwise identical.
Response schemas at /docs stay opaque because every endpoint answers with the
shared {success, message, data} envelope, which Scramble cannot see through.
Enriching those means either dropping the envelope, which breaks existing
clients, or adding response annotations, a separate follow-up.
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Second half of zerp-pk/zerp#34. Depends on zerp-pk/zerp#81 (the
App\Http\Requests\ApiFormRequestbase); merge that first.What Scramble could and could not see
The controllers validated with inline
Validator::make(...), which Scramble cannot read, so the request bodies at/docs/hrmwere empty. Two write endpoints now take typed FormRequests, which Scramble does read:Api/StoreLeaveRequestforPOST leave-requestApi/ClockInOutRequestforPOST clock-in-outThey extend the app's
ApiFormRequest, so a validation failure keeps the exact{success, message, errors}422 envelope the API already returned. Verified over real HTTP against the running app:The response side, stated plainly
The issue also asks to type controller returns as
: JsonResourceso Scramble infers response shapes. That does not work here, and I did not force it: every endpoint answers with the sharedApiResponseTraitenvelope{success, message, data}viaresponse()->json, which Scramble cannot see through. The only ways to enrich response schemas are to drop the envelope (breaks every existing mobile client) or add Scramble response annotations. Both are out of scope for a non-breaking change; the annotation route is a clean follow-up.The Resource earns its place on correctness, not docs
LeaveApplicationResourcereplaces the leave shape that was hand-copied into both the list and the create response. The two copies had already drifted: the list fell back toavatar.pngfor a missing attachment, create fell back to''. Both now use the list's fallback, since that is what a client sees on every later read. Confirmed the resolved output keeps all 11 original keys and the same attachment URL when one is present:Behavior notes
StoreLeaveRequesttypesattachmentasnullable|file. The endpoint only ever reads it viahasFile(), so a stray string was silently ignored before and is now a clean 422. Slightly stricter, and it is what makes the OpenAPI body show a file upload.create's missing-attachment response changes from''to theavatar.pngURL, matching the list. This is the drift fix, called out so it is not a surprise.Same pattern now applies cleanly to lead / taskly / support-ticket.
🤖 Generated with Claude Code