dreamteamprod / dreamteamprod/DigiScript

Add OpenAPI/Swagger API Documentation

Open
#775 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

claude
Dominant language
Vue
Stars
19
Forks
4
Avg merge
2d 12h
Merged PRs (30d)
37

Description

Overview

Add OpenAPI/Swagger documentation to DigiScript's REST API, including an interactive Swagger UI page for exploring and testing endpoints.

Motivation

  • Developer Experience: Interactive API documentation makes it easier for contributors to understand available endpoints
  • Client Development: Auto-generated API specs can be used to generate client SDKs
  • Testing: Swagger UI provides built-in API testing capabilities
  • Maintenance: Auto-generated docs stay in sync with code changes

Research Summary

After researching available options for Python Tornado + Marshmallow stack, there are three viable approaches:

Option 1: apispec + apispec-webframeworks (Recommended)

Pros:

  • Official Marshmallow integration - can auto-generate schemas from our existing SQLAlchemyAutoSchema classes
  • OpenAPI 3.0 support
  • Most flexible and well-maintained (actively developed by marshmallow-code org)
  • Works with our existing Marshmallow schemas in schemas/schemas.py
  • Tornado plugin available via apispec-webframeworks

Cons:

  • Requires more manual setup for path registration
  • Need to write code to generate and serve the spec file

Example Integration:

from apispec import APISpec
from apispec.ext.marshmallow import MarshmallowPlugin
from apispec_webframeworks.tornado import TornadoPlugin

spec = APISpec(
    title="DigiScript API",
    version="1.0.0",
    openapi_version="3.0.0",
    plugins=[MarshmallowPlugin(), TornadoPlugin()],
)

# Auto-generates schema from existing Marshmallow schemas
spec.components.schema("Show", schema=ShowSchema)

References:

Option 2: tornado-swagger

Pros:

  • Simple decorator-based approach
  • Built-in Swagger UI at /api/doc
  • Minimal code changes needed

Cons:

  • Requires embedding YAML specs in docstrings
  • Less integration with existing Marshmallow schemas
  • May require duplicating schema definitions

Example:

@ApiRoute("/show/script", ApiVersion.V1)
class ScriptController(BaseAPIController):
    @requires_show
    def get(self):
        """
        ---
        tags:
          - Script
        summary: Get script page
        parameters:
          - name: page
            in: query
            required: true
            schema:
              type: integer
        responses:
          200:
            description: Script page retrieved
        """

References:

Option 3: tornado-swirl

Pros:

  • OpenAPI 3.0 native support
  • Uses Google-style docstrings (more readable than YAML)
  • Adapted for modern Tornado 5+ and Python 3

Cons:

  • Less maintained than apispec
  • Requires @restapi decorator for route registration (different from our @ApiRoute)
  • May require refactoring our routing system

References:

Implementation Considerations

Integration with Existing Architecture

DigiScript uses:

  • Custom routing: @ApiRoute decorator with automatic /api/v{version}/ prefix
  • Existing Marshmallow schemas: Already defined in schemas/schemas.py using SQLAlchemyAutoSchema
  • Auto-discovery: Controllers in controllers/api/ are auto-loaded via module_discovery.py
Recommended Approach

Option 1 (apispec) appears best because:

  1. ✅ Reuses existing Marshmallow schemas (no duplication)
  2. ✅ Mature, actively maintained project
  3. ✅ OpenAPI 3.0 support
  4. ✅ Can integrate with our custom @ApiRoute decorator
Implementation Steps
  1. Add dependencies:

    pip install apispec apispec-webframeworks swagger-ui-py
    
  2. Create spec generator (utils/api_spec.py):

    • Initialize APISpec with Marshmallow + Tornado plugins
    • Auto-register schemas from schemas/schemas.py
    • Create decorator or helper to register routes from @ApiRoute controllers
  3. Add Swagger UI endpoint:

    • New controller at /api/docs serving Swagger UI
    • Spec JSON endpoint at /api/openapi.json
  4. Document existing endpoints:

    • Add docstrings to controller methods
    • Use spec.path() to register routes with parameters/responses
  5. Update documentation:

    • Add link to API docs in README
    • Document how to add specs for new endpoints

Acceptance Criteria

  • OpenAPI 3.0 spec generated from existing Marshmallow schemas
  • Interactive Swagger UI accessible at /api/docs
  • OpenAPI spec JSON available at /api/openapi.json
  • At least 5-10 key endpoints documented as examples
  • Documentation in README on how to add API docs for new endpoints
  • CI checks pass (linting, tests)

Additional References

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing @ApiRoute controllers in controllers/api/, the schemas in schemas/schemas.py, and module_discovery.py. Then design the spec generation in utils/api_spec.py, the /api/docs and /api/openapi.json endpoints, and README guidance. Done means the listed acceptance criteria pass, including documented example endpoints and CI checks.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, python
Domain
api, documentation
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.