Skip to content

Conversation

@piyush-jaiswal
Copy link
Owner

@piyush-jaiswal piyush-jaiswal commented Sep 27, 2025

Summary by CodeRabbit

  • New Features
    • Standardized categories API with OpenAPI documentation via Flask-Smorest.
    • JWT required for creating, updating, and deleting categories.
    • Paginated products-by-category endpoint; clearer 200 (update) and 204 (delete) responses.
  • Refactor
    • All category endpoints moved from /category/... to /categories/... (paths updated across list, detail, subcategories, products, create, update, delete).
  • Documentation
    • README updated to reflect new pluralized endpoints and behaviors.
  • Bug Fixes
    • Stricter input validation and improved handling of duplicate category creation.
  • Chores
    • Added Flask-Smorest and Marshmallow-SQLAlchemy dependencies.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 27, 2025

Walkthrough

Pluralizes category API paths from /category to /categories, migrates category endpoints to a new Flask-Smorest blueprint with Marshmallow schemas, wires Api(app) and OpenAPI config, removes legacy category routes, adds new dependencies, and updates tests and README accordingly.

Changes

Cohort / File(s) Summary
API docs update
README.md
Updated all category-related REST paths from singular to plural; adjusted HTTP methods and status codes accordingly.
App wiring & OpenAPI
app/__init__.py
Integrated Flask-Smorest Api, added OpenAPI config, introduced register_blueprints() to register the category blueprint under /categories.
Category routes (Smorest)
app/migrated_routes/category.py
Added blueprint with endpoints: list/create categories, get/update/delete by id, get subcategories, get paginated products; JWT-protected mutations; input validation and DB interactions.
Legacy route removal
app/routes.py
Removed prior category CRUD and related endpoints; trimmed unused relationship imports.
Marshmallow schemas
app/schemas.py
Introduced SQLAlchemy-based input/output schemas for Category/Subcategory/Product, list wrappers, and pagination args; includes validation.
Dependencies
requirements.txt
Added flask-smorest==0.46.2 and marshmallow-sqlalchemy==1.4.2.
Test fixtures
tests/conftest.py
Updated helper to post categories to /categories.
Category tests
tests/test_category.py
Switched endpoints to plural; adjusted expected status codes; added duplicate-creation IntegrityError expectation; incorporated auth headers.
Relationship tests
tests/test_relationships.py
Updated endpoints to plural and status expectations; preserved pagination and 404 cases.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Client
  participant App as Flask App
  participant API as Smorest Api
  participant BP as Category Blueprint
  participant JWT as JWT Ext
  participant DB as SQLAlchemy/DB

  rect rgb(240,248,255)
  note over Client,DB: List categories (GET /categories)
  Client->>App: GET /categories
  App->>API: dispatch request
  API->>BP: CategoryCollection.get
  BP->>DB: Category.query.all()
  DB-->>BP: categories
  BP-->>Client: 200 JSON
  end

  rect rgb(245,255,240)
  note over Client,DB: Create category (POST /categories) [protected]
  Client->>App: POST /categories (JSON)
  App->>API: dispatch
  API->>JWT: verify access token
  JWT-->>API: ok / error
  alt token valid
    API->>BP: CategoryCollection.post
    BP->>DB: validate subcategory IDs
    DB-->>BP: ok / missing
    alt valid
      BP->>DB: insert Category, commit
      DB-->>BP: created
      BP-->>Client: 201 JSON
    else invalid
      BP-->>Client: 422 error
    end
  else invalid token
    API-->>Client: 401 error
  end
  end

  rect rgb(255,250,240)
  note over Client,DB: Paginated products (GET /categories/{id}/products?page=n)
  Client->>App: GET /categories/123/products?page=2
  App->>API: dispatch
  API->>BP: CategoryProducts.get
  BP->>DB: exists(Category.id==123)?
  alt exists
    BP->>DB: query products, paginate (10/page)
    DB-->>BP: items + meta
    BP-->>Client: 200 JSON
  else not found
    BP-->>Client: 404
  end
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • Add subcategory tests #10 — Adjusts auth fixture and usage in tests, overlapping with updated authenticated category endpoints.
  • Add relationship tests #13 — Extends relationship tests targeting category endpoints, aligning with this PR’s route pluralization and blueprint migration.

Poem

I hopped from category to categories bright,
Blueprints bloomed under Smorest’s light.
Marshmallow fields, sweet and neat,
JWT carrots guard the treat.
Tests now dance in plural lines,
Ten-per-page—paginated pines.
Thump-thump: docs and code align! 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 32.14% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title highlights the introduction of Flask-Smorest for category functionality, which accurately reflects the main change of the pull request.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/flask-smorest-category

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Ruff (0.13.1)
app/__init__.py

�[1;31mruff failed�[0m
�[1mCause:�[0m Failed to load configuration /ruff.toml
�[1mCause:�[0m Failed to parse /ruff.toml
�[1mCause:�[0m TOML parse error at line 26, column 3
|
26 | "RSE100", # Use of assert detected
| ^^^^^^^^
Unknown rule selector: RSE100

app/migrated_routes/category.py

�[1;31mruff failed�[0m
�[1mCause:�[0m Failed to load configuration /ruff.toml
�[1mCause:�[0m Failed to parse /ruff.toml
�[1mCause:�[0m TOML parse error at line 26, column 3
|
26 | "RSE100", # Use of assert detected
| ^^^^^^^^
Unknown rule selector: RSE100

tests/test_category.py

�[1;31mruff failed�[0m
�[1mCause:�[0m Failed to load configuration /ruff.toml
�[1mCause:�[0m Failed to parse /ruff.toml
�[1mCause:�[0m TOML parse error at line 26, column 3
|
26 | "RSE100", # Use of assert detected
| ^^^^^^^^
Unknown rule selector: RSE100

  • 4 others

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a8638a5 and 5885029.

📒 Files selected for processing (9)
  • README.md (2 hunks)
  • app/__init__.py (2 hunks)
  • app/migrated_routes/category.py (1 hunks)
  • app/routes.py (1 hunks)
  • app/schemas.py (1 hunks)
  • requirements.txt (1 hunks)
  • tests/conftest.py (1 hunks)
  • tests/test_category.py (7 hunks)
  • tests/test_relationships.py (5 hunks)
🧰 Additional context used
🧬 Code graph analysis (6)
app/routes.py (1)
app/models.py (3)
  • Category (77-93)
  • Subcategory (96-113)
  • Product (116-134)
app/schemas.py (1)
app/models.py (3)
  • Category (77-93)
  • Product (116-134)
  • Subcategory (96-113)
app/migrated_routes/category.py (2)
app/models.py (3)
  • Category (77-93)
  • Product (116-134)
  • Subcategory (96-113)
app/schemas.py (6)
  • CategoriesOut (12-13)
  • CategoryIn (16-33)
  • CategoryOut (7-9)
  • PaginationArgs (54-55)
  • ProductsOut (50-51)
  • SubcategoriesOut (41-42)
tests/test_category.py (2)
tests/conftest.py (3)
  • create_category (54-63)
  • create_authenticated_headers (43-50)
  • client (14-21)
app/migrated_routes/category.py (2)
  • put (129-180)
  • delete (184-209)
tests/conftest.py (1)
app/migrated_routes/category.py (1)
  • post (47-94)
tests/test_relationships.py (2)
tests/conftest.py (3)
  • client (14-21)
  • create_category (54-63)
  • create_subcategory (67-78)
app/migrated_routes/category.py (1)
  • put (129-180)
🪛 markdownlint-cli2 (0.18.1)
README.md

108-108: Fenced code blocks should be surrounded by blank lines

(MD031, blanks-around-fences)


108-108: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: deploy-preview

@piyush-jaiswal piyush-jaiswal merged commit e5a815a into master Sep 27, 2025
3 checks passed
@piyush-jaiswal piyush-jaiswal deleted the feature/flask-smorest-category branch September 27, 2025 20:15
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.

2 participants