Skip to content

feat: add swagger ui for interactive api documentation#358

Open
Sai-Adithya-M wants to merge 1 commit intoAOSSIE-Org:mainfrom
Sai-Adithya-M:feature/flask-swagger-ui
Open

feat: add swagger ui for interactive api documentation#358
Sai-Adithya-M wants to merge 1 commit intoAOSSIE-Org:mainfrom
Sai-Adithya-M:feature/flask-swagger-ui

Conversation

@Sai-Adithya-M
Copy link

@Sai-Adithya-M Sai-Adithya-M commented Jan 9, 2026

Summary

This PR integrates Flasgger to provide interactive Swagger UI documentation for the backend API. Ideally, this improves the developer experience by allowing easy testing of endpoints directly from the browser.

Changes

  • Dependency: Added flasgger==0.9.7.1 to requirements.txt.
  • Backend: Initialized Swagger in backend/server.py (conditional on FLASK_ENV=development for security).
  • Documentation: Added OpenAPI/Swagger docstrings to the following endpoints:
    • /get_mcq
    • /get_boolq
    • /get_shortq
    • /get_problems

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update

How Has This Been Tested?

  • Manual Verification:
    1. Installed dependencies: pip install -r requirements.txt
    2. Set environment: export FLASK_ENV=development
    3. Started server: python backend/server.py
    4. Navigated to http://localhost:5000/apidocs and verified the UI loads.
    5. Tested /get_mcq via the "Try it out" button in Swagger.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings

Summary by CodeRabbit

  • New Features

    • Interactive API documentation (Swagger/OpenAPI) enabled in development, with endpoint-level docs for all question-generation routes.
  • Chores

    • Relaxed version constraints for PyTorch and SciPy to allow newer releases.
    • Added a documentation library dependency for the API docs.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 9, 2026

📝 Walkthrough

Walkthrough

Adds conditional Swagger/OpenAPI integration to the Flask server (enabled in development) and inserts OpenAPI-style docstrings for several routes; updates dependency pins and relaxes version constraints while adding flasgger.

Changes

Cohort / File(s) Summary
API Documentation Setup
backend/server.py
Conditionally initializes Swagger when FLASK_ENV == "development" and adds inline OpenAPI/Swagger docstrings to /get_mcq, /get_boolq, /get_shortq, and /get_problems routes describing inputs (e.g., input_text, max_questions, use_mediawiki) and response schemas.
Dependency Management
requirements.txt
Adds flasgger==0.9.7.1; relaxes torch to >=2.6.0, updates transformers to ==4.57.3, and relaxes scipy to >=1.13.0 (other deps unchanged).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 I hopped through code at break of day,

Swagger banners led the way,
Docs now bloom where routes once stood,
Versions loosened — all is good,
A tiny rabbit cheers: hooray! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding Swagger UI for interactive API documentation, which directly aligns with the PR's primary objective of integrating Flasgger.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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

@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: 2

🤖 Fix all issues with AI agents
In @requirements.txt:
- Line 2: Update the pinned transformers version in requirements.txt from
"transformers==4.46.1" to a fixed version that contains the security fixes (at
least "transformers==4.53.0" or preferably the latest stable like
"transformers==4.57.3"); ensure the requirements entry for "transformers" is
replaced accordingly and run dependency installation/tests to verify
compatibility.
- Line 1: The requirements entry for PyTorch currently allows vulnerable
releases; update the torch version spec in requirements.txt by replacing the
loose "torch>=2.0.0" constraint with a stronger minimum—use "torch>=2.6.0" to
address CVE-2025-32434 (or "torch>=2.7.1" if you also want to cover
CVE-2025-2953); ensure the single line that defines the torch dependency is
changed accordingly so installers cannot pick vulnerable versions.
🧹 Nitpick comments (3)
requirements.txt (2)

8-8: Clarify the rationale for relaxing scipy version constraint.

The version constraint was changed from scipy==1.14.1 to scipy>=1.13.0, allowing older versions. While no security issues are flagged, relaxing version constraints can introduce compatibility or behavior differences.

What's the reason for this change? If there's no specific need for backward compatibility, consider maintaining the exact pin or using a minimum bound closer to the tested version (e.g., scipy>=1.14.0).


34-34: Consider pinning textblob to a specific version for reproducibility.

The dependency textblob is unpinned, which can lead to reproducibility issues if different versions are installed in different environments. However, this file contains multiple unpinned dependencies (numpy, pandas, spacy, flask, flask_cors, nltk, tokenizers, google-auth, and PyMuPDF), suggesting a mixed pinning strategy. If version flexibility is intentional for these packages, that's acceptable; otherwise, consider standardizing by pinning all or establishing clear criteria for which dependencies should be flexible.

backend/server.py (1)

30-32: Add error handling for Swagger initialization.

The conditional Swagger initialization lacks error handling. If flasgger fails to import (e.g., dependency not installed), the application will crash. Consider wrapping in a try-except block for graceful degradation and adding logging.

🛡️ Proposed improvement
 if os.environ.get("FLASK_ENV") == "development":
-    from flasgger import Swagger
-    Swagger(app)
+    try:
+        from flasgger import Swagger
+        Swagger(app)
+        print("Swagger UI enabled at /apidocs")
+    except ImportError:
+        print("Warning: flasgger not installed. Swagger UI disabled.")
+    except Exception as e:
+        print(f"Warning: Failed to initialize Swagger: {e}")
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5d6e4ad and 2c68c65.

📒 Files selected for processing (2)
  • backend/server.py
  • requirements.txt
🧰 Additional context used
🪛 OSV Scanner (2.3.1)
requirements.txt

[CRITICAL] 1-1: torch 2.0.0: undefined

(PYSEC-2024-250)


[CRITICAL] 1-1: torch 2.0.0: undefined

(PYSEC-2024-251)


[CRITICAL] 1-1: torch 2.0.0: undefined

(PYSEC-2024-252)


[CRITICAL] 1-1: torch 2.0.0: undefined

(PYSEC-2024-259)


[CRITICAL] 1-1: torch 2.0.0: undefined

(PYSEC-2025-41)


[CRITICAL] 1-1: torch 2.0.0: PyTorch susceptible to local Denial of Service

(GHSA-3749-ghw9-m3mg)


[CRITICAL] 1-1: torch 2.0.0: PyTorch: torch.load with weights_only=True leads to remote code execution

(GHSA-53q9-r3pm-6pq6)


[CRITICAL] 1-1: torch 2.0.0: PyTorch heap buffer overflow vulnerability

(GHSA-5pcm-hx3q-hm94)


[CRITICAL] 1-1: torch 2.0.0: PyTorch Improper Resource Shutdown or Release vulnerability

(GHSA-887c-mr87-cxwp)


[CRITICAL] 1-1: torch 2.0.0: Pytorch use-after-free vulnerability

(GHSA-pg7h-5qx3-wjr3)


[HIGH] 2-2: transformers 4.46.1: undefined

(PYSEC-2024-227)


[HIGH] 2-2: transformers 4.46.1: undefined

(PYSEC-2024-228)


[HIGH] 2-2: transformers 4.46.1: undefined

(PYSEC-2024-229)


[HIGH] 2-2: transformers 4.46.1: undefined

(PYSEC-2025-40)


[HIGH] 2-2: transformers 4.46.1: Transformers is vulnerable to ReDoS attack through its DonutProcessor class

(GHSA-37mw-44qp-f5jm)


[HIGH] 2-2: transformers 4.46.1: Hugging Face Transformers vulnerable to Regular Expression Denial of Service (ReDoS) in the AdamWeightDecay optimizer

(GHSA-4w7r-h757-3r74)


[HIGH] 2-2: transformers 4.46.1: Hugging Face Transformers is vulnerable to ReDoS through its MarianTokenizer

(GHSA-59p9-h35m-wg4g)


[HIGH] 2-2: transformers 4.46.1: Transformers Regular Expression Denial of Service (ReDoS) vulnerability

(GHSA-6rvg-6v2m-4j46)


[HIGH] 2-2: transformers 4.46.1: Hugging Face Transformers Regular Expression Denial of Service (ReDoS) vulnerability

(GHSA-9356-575x-2w9m)


[HIGH] 2-2: transformers 4.46.1: Transformers Regular Expression Denial of Service (ReDoS) vulnerability

(GHSA-fpwr-67px-3qhx)


[HIGH] 2-2: transformers 4.46.1: Deserialization of Untrusted Data in Hugging Face Transformers

(GHSA-hxxf-235m-72v3)


[HIGH] 2-2: transformers 4.46.1: Transformers vulnerable to ReDoS attack through its get_imports() function

(GHSA-jjph-296x-mrcr)


[HIGH] 2-2: transformers 4.46.1: Transformers's Improper Input Validation vulnerability can be exploited through username injection

(GHSA-phhr-52qp-3mj4)


[HIGH] 2-2: transformers 4.46.1: Transformers's ReDoS vulnerability in get_configuration_file can lead to catastrophic backtracking

(GHSA-q2wp-rjmx-x6x9)


[HIGH] 2-2: transformers 4.46.1: Hugging Face Transformers Regular Expression Denial of Service

(GHSA-qq3j-4f4f-9583)


[HIGH] 2-2: transformers 4.46.1: Deserialization of Untrusted Data in Hugging Face Transformers

(GHSA-qxrp-vhvm-j765)


[HIGH] 2-2: transformers 4.46.1: Hugging Face Transformers library has Regular Expression Denial of Service

(GHSA-rcv9-qm8p-9p6j)


[HIGH] 2-2: transformers 4.46.1: Deserialization of Untrusted Data in Hugging Face Transformers

(GHSA-wrfc-pvp9-mr9g)

🔇 Additional comments (2)
backend/server.py (1)

58-99: LGTM: OpenAPI documentation enhances API discoverability.

The OpenAPI/Swagger docstrings provide clear documentation for the API endpoints, including parameter schemas and response structures. This improves developer experience and API discoverability.

Minor note: Line 142 uses type: map, which is not standard OpenAPI 2.0 syntax. Consider using type: object for better compatibility, though Flasgger may handle this correctly.

Also applies to: 114-144, 159-195, 210-249

requirements.txt (1)

35-35: flasgger==0.9.7.1 is the latest stable release and has no known security vulnerabilities.

However, the project has 286 open issues and the last commit was in June 2024. Consider monitoring upstream for updates or evaluating alternative Swagger integrations if active maintenance becomes critical for your requirements.

@Sai-Adithya-M Sai-Adithya-M force-pushed the feature/flask-swagger-ui branch from 2c68c65 to 4ca1db0 Compare January 13, 2026 17:26
Copy link

@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: 1

🤖 Fix all issues with AI agents
In @backend/server.py:
- Around line 138-143: The OpenAPI schema uses an invalid type "map" for the
"output" property; replace it with a valid type "object" and, if the intent is a
free-form map, add an additionalProperties definition (e.g.,
additionalProperties: true or a schema) so the "output" field accepts arbitrary
key/value pairs; update the schema block that defines the "output" property in
the server.py OpenAPI/YAML section accordingly.
🧹 Nitpick comments (1)
backend/server.py (1)

30-32: Consider adding error handling for missing flasgger dependency.

The conditional import is appropriate for a development-only feature. However, if someone sets FLASK_ENV=development without installing flasgger, the server will crash with an ImportError.

💡 Suggested improvement for robustness
 if os.environ.get("FLASK_ENV") == "development":
-    from flasgger import Swagger
-    Swagger(app)
+    try:
+        from flasgger import Swagger
+        Swagger(app)
+    except ImportError:
+        print("Warning: flasgger not installed. Swagger UI will not be available.")
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2c68c65 and 4ca1db0.

📒 Files selected for processing (2)
  • backend/server.py
  • requirements.txt
🚧 Files skipped from review as they are similar to previous changes (1)
  • requirements.txt
🔇 Additional comments (3)
backend/server.py (3)

58-99: LGTM!

The OpenAPI docstring is well-structured with appropriate parameter definitions, examples, and response schema that accurately reflects the endpoint's behavior.


159-195: LGTM!

The documentation accurately describes the endpoint's parameters and response structure.


210-249: LGTM!

The documentation correctly describes the combined question generation endpoint. The parameter and response structure accurately reflects the implementation.

Comment on lines +138 to +143
schema:
type: object
properties:
output:
type: map
description: Map containing question details (structure may vary)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Invalid OpenAPI type map - use object instead.

map is not a valid OpenAPI/Swagger type. Valid types are: string, number, integer, boolean, array, object. This will cause Swagger UI validation warnings.

🔧 Proposed fix
           properties:
             output:
-              type: map
-              description: Map containing question details (structure may vary)
+              type: object
+              additionalProperties: true
+              description: Object containing question details (structure may vary)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
schema:
type: object
properties:
output:
type: map
description: Map containing question details (structure may vary)
schema:
type: object
properties:
output:
type: object
additionalProperties: true
description: Object containing question details (structure may vary)
🤖 Prompt for AI Agents
In @backend/server.py around lines 138 - 143, The OpenAPI schema uses an invalid
type "map" for the "output" property; replace it with a valid type "object" and,
if the intent is a free-form map, add an additionalProperties definition (e.g.,
additionalProperties: true or a schema) so the "output" field accepts arbitrary
key/value pairs; update the schema block that defines the "output" property in
the server.py OpenAPI/YAML section accordingly.

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.

1 participant