[#520] Fix OpenAPI generated routes response contract#521
Conversation
📝 WalkthroughWalkthroughThe OpenAPI installer command's route generator is updated to emit compliant route closures. The ChangesOpenAPI Route Generator Response Contract Fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #521 +/- ##
=========================================
Coverage 90.87% 90.87%
Complexity 3070 3070
=========================================
Files 263 263
Lines 8100 8100
=========================================
Hits 7361 7361
Misses 739 739 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/Console/Commands/OpenApiCommand.php (1)
199-202: ⚡ Quick winConsider error handling for missing or invalid spec.json.
The generated
specendpoint calls$fs->getJson(...)which may throw or return unexpected data if the spec file doesn't exist or contains invalid JSON. While the spec.json is generated during installation, consider whether the route should handle potential read failures gracefully (e.g., after manual file deletion or permissions issues).🛡️ Suggested enhancement with error handling
$route->get("spec", function (): Quantum\Http\Response { $fs = Quantum\Storage\Factories\FileSystemFactory::get(); - return response()->json($fs->getJson(modules_dir() . "' . DS . $module . DS . 'resources' . DS . 'openapi' . DS . 'spec.json")); + $specPath = modules_dir() . "' . DS . $module . DS . 'resources' . DS . 'openapi' . DS . 'spec.json"; + if (!$fs->exists($specPath)) { + return response()->json(["error" => "OpenAPI specification not found"], 404); + } + return response()->json($fs->getJson($specPath)); });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/Console/Commands/OpenApiCommand.php` around lines 199 - 202, The spec route closure currently calls $fs->getJson(...) and returns response()->json(...) without handling missing files or JSON errors; update the Route (the anonymous function registered for "spec") to wrap the $fs->getJson call in a try/catch (or check file existence/valid JSON beforehand), return an appropriate JSON error response with a 404 or 500 status when the file is missing/unreadable/invalid, and ensure the success path still returns the parsed spec via response()->json; reference the route closure, $fs->getJson, modules_dir() and response()->json when making the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/Console/Commands/OpenApiCommand.php`:
- Around line 199-202: The spec route closure currently calls $fs->getJson(...)
and returns response()->json(...) without handling missing files or JSON errors;
update the Route (the anonymous function registered for "spec") to wrap the
$fs->getJson call in a try/catch (or check file existence/valid JSON
beforehand), return an appropriate JSON error response with a 404 or 500 status
when the file is missing/unreadable/invalid, and ensure the success path still
returns the parsed spec via response()->json; reference the route closure,
$fs->getJson, modules_dir() and response()->json when making the change.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d82fcb72-ab4e-4b40-ace4-9854ea8e67d7
📒 Files selected for processing (2)
CHANGELOG.mdsrc/Console/Commands/OpenApiCommand.php
Closes #520
Summary by CodeRabbit