feat: add /api/recommend schema validation and structured error responses#1256
Open
divyanshim27 wants to merge 8 commits into
Open
feat: add /api/recommend schema validation and structured error responses#1256divyanshim27 wants to merge 8 commits into
divyanshim27 wants to merge 8 commits into
Conversation
- Add BookmarkManager (localStorage) with 10-item cap and duplicate prevention - Add bookmark toggle button on project detail page - Add /bookmarks route and template - Track last 5 recently viewed projects via Flask session - Add /api/recently-viewed endpoint - Add homepage recently-viewed section - Add 4 backend tests; bookmark JS logic covered by manual QA (no JS test runner in repo) Closes komalharshita#1230
…nses
- Add utils/schemas.py: RecommendRequest dataclass with validate() method
- Validates skills (non-empty list), level (Beginner/Intermediate/Advanced),
interest (non-empty), time (Low/Medium/High)
- Update routes/main_routes.py: /api/recommend now returns:
- HTTP 400 for non-JSON body (code: INVALID_CONTENT_TYPE)
- HTTP 422 for validation errors (code: VALIDATION_ERROR, errors: [...])
- HTTP 200 success: {success: true, count: N, results: [...]}
- Add scripts/validate_projects.py: validates all entries in data/projects.json
for required fields and valid field values; exits 1 on failure for CI
- Add .github/workflows/validate_projects.yml: CI step runs validator on PRs
- Add 5 new tests in tests/test_basic.py (32 total, 0 failures):
- empty skills → 422
- invalid level → 422
- valid input → 200 with structured response
- non-JSON body → 400
- validator catches missing project fields
Closes komalharshita#1231
|
@divyanshim27 is attempting to deploy a commit to the komalsony234-1530's projects Team on Vercel. A member of the Team first needs to authorize it. |
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.
Summary
Implements all acceptance criteria from issue #1231.
Changes Made
utils/schemas.py(new file)RecommendRequestdataclass withvalidate()methodskills(non-empty list),level(Beginner/Intermediate/Advanced),interest(non-empty string),time(Low/Medium/High)routes/main_routes.py(modified)/api/recommendnow returns HTTP 400 for non-JSON body (INVALID_CONTENT_TYPE)/api/recommendnow returns HTTP 422 for validation errors (VALIDATION_ERROR){"success": true, "count": N, "results": [...]}scripts/validate_projects.py(new file)data/projects.jsonfor required fieldslevelandtime.github/workflows/validate_projects.yml(new file)validate_projects.pyon every PR that touchesdata/projects.jsontests/test_basic.py(modified — 5 new tests added)test_empty_skills_returns_422test_invalid_level_returns_422test_valid_request_returns_200_with_structured_responsetest_non_json_body_returns_400test_validate_projects_script_catches_missing_fieldTest Results
32 passed, 0 failed (27 original + 5 new)
Checklist
/api/recommendresponse schema validation and structured error responses — current endpoint returns untyped dict, breaking any frontend that expects consistent JSON shape #1231 are implementedpython scripts/validate_projects.pypasses on current datasetfeat/conventionCloses #1231