Implement /pet/{petId}/uploadImage persistence and photo URL updates#10
Open
Copilot wants to merge 3 commits into
Open
Implement /pet/{petId}/uploadImage persistence and photo URL updates#10Copilot wants to merge 3 commits into
/pet/{petId}/uploadImage persistence and photo URL updates#10Copilot wants to merge 3 commits into
Conversation
Copilot
AI
changed the title
[WIP] Add uploadImage endpoint for pet images
Implement May 25, 2026
/pet/{petId}/uploadImage persistence and photo URL updates
There was a problem hiding this comment.
Pull request overview
This PR makes the Swagger Petstore simulator’s POST /pet/{petId}/uploadImage endpoint actually persist the uploaded image to disk and update the in-memory pet record’s photoUrls accordingly.
Changes:
- Implemented upload handling in
routes/pet/{petId}/uploadImage.ts(validate pet existence/body, save file underpet-images/{petId}, append/photos/{petId}/{filename}). - Extended the integration test to upload an image and assert both the pet mutation and file persistence, including cleanup of generated artifacts.
- Updated
package-lock.jsonto align with the package name and dependency classification.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| swagger-pet-store/routes/pet/{petId}/uploadImage.ts | Adds image filename resolution, payload extraction, disk persistence, and photoUrls mutation. |
| swagger-pet-store/test/dummy.test.js | Adds integration coverage for upload + persistence and deletes pet-images after the test run. |
| swagger-pet-store/package-lock.json | Syncs lockfile metadata/dependency flags with the package configuration. |
Files not reviewed (1)
- swagger-pet-store/package-lock.json: Language not supported
Comment on lines
+5
to
+28
| const getFilenameFromHeaders = (headers: Record<string, string>): string => { | ||
| const explicitFileName = | ||
| headers["x-image-filename"] ?? headers["x-file-name"]; | ||
| if (explicitFileName) { | ||
| return path.basename(explicitFileName); | ||
| } | ||
|
|
||
| const contentDisposition = headers["content-disposition"]; | ||
| if (!contentDisposition) { | ||
| return "image.bin"; | ||
| } | ||
|
|
||
| const utf8Match = contentDisposition.match(/filename\*=UTF-8''([^;]+)/i); | ||
| if (utf8Match) { | ||
| return path.basename(decodeURIComponent(utf8Match[1])); | ||
| } | ||
|
|
||
| const standardMatch = contentDisposition.match(/filename="?([^";]+)"?/i); | ||
| if (standardMatch) { | ||
| return path.basename(standardMatch[1]); | ||
| } | ||
|
|
||
| return "image.bin"; | ||
| }; |
Comment on lines
+5
to
+28
| const getFilenameFromHeaders = (headers: Record<string, string>): string => { | ||
| const explicitFileName = | ||
| headers["x-image-filename"] ?? headers["x-file-name"]; | ||
| if (explicitFileName) { | ||
| return path.basename(explicitFileName); | ||
| } | ||
|
|
||
| const contentDisposition = headers["content-disposition"]; | ||
| if (!contentDisposition) { | ||
| return "image.bin"; | ||
| } | ||
|
|
||
| const utf8Match = contentDisposition.match(/filename\*=UTF-8''([^;]+)/i); | ||
| if (utf8Match) { | ||
| return path.basename(decodeURIComponent(utf8Match[1])); | ||
| } | ||
|
|
||
| const standardMatch = contentDisposition.match(/filename="?([^";]+)"?/i); | ||
| if (standardMatch) { | ||
| return path.basename(standardMatch[1]); | ||
| } | ||
|
|
||
| return "image.bin"; | ||
| }; |
| return Uint8Array.from(body.data); | ||
| } | ||
|
|
||
| return new Uint8Array(); |
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.
POST /pet/{petId}/uploadImagepreviously returned success without persisting anything or mutating pet data. This change wires the endpoint to store uploaded images underpet-images/{petId}and append the corresponding/photos/{petId}/{imageFileName}entry to the pet’sphotoUrls.Endpoint behavior
routes/pet/{petId}/uploadImage.ts.404) and missing image content (400).pet-images/{petId}/{imageFileName}.Filename resolution
imageFileNamefrom request headers in priority order:x-image-filenamex-file-namecontent-disposition(filename*/filename)image.binpath.basename(...)to avoid path traversal via header values.Pet model mutation
/photos/{petId}/{imageFileName}photoUrlsentries.Coverage updates
test/dummy.test.jsto assert:GET /pet/{petId}pet-imagesartifacts.