Skip to content

Add docs index view and move Swagger to /docs/swagger/#902

Open
TheRealHaoLiu wants to merge 2 commits intoansible:develfrom
TheRealHaoLiu:docs-reorg
Open

Add docs index view and move Swagger to /docs/swagger/#902
TheRealHaoLiu wants to merge 2 commits intoansible:develfrom
TheRealHaoLiu:docs-reorg

Conversation

@TheRealHaoLiu
Copy link
Copy Markdown
Member

@TheRealHaoLiu TheRealHaoLiu commented Dec 10, 2025

Description

  • What is being changed?

    • Reorganized the API documentation URL structure so /docs/ serves as an index page listing available documentation endpoints, rather than directly showing Swagger UI.
    • Swagger UI moved from /docs/ to /docs/swagger/
    • Added a new DocsRootView that returns a DRF-style JSON response with links to swagger, redoc, and schema endpoints.
  • Why is this change needed?

    • The previous URL structure was inconsistent - /docs/ went directly to Swagger UI while /docs/redoc/ and /docs/schema/ were nested under it. This was confusing for API consumers.
  • How does this change address the issue?

    • Now /docs/ serves as a proper index/root endpoint that lists all available documentation options, making the URL hierarchy more intuitive and discoverable.

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Documentation update

Self-Review Checklist

  • I have performed a self-review of my code
  • I have added relevant comments to complex code sections
  • I have updated documentation where needed
  • I have considered the security impact of these changes
  • I have considered performance implications
  • I have thought about error handling and edge cases
  • I have tested the changes in my local environment

Testing Instructions

Prerequisites

  • A running instance of the test app with ansible_base.api_documentation enabled

Steps to Test

  1. Start the development server: python manage.py runserver
  2. Navigate to /api/v1/docs/
  3. Verify it returns a JSON response with links to swagger, redoc, and schema
  4. Navigate to /api/v1/docs/swagger/ and verify Swagger UI loads
  5. Navigate to /api/v1/docs/redoc/ and verify ReDoc loads
  6. Navigate to /api/v1/docs/schema/ and verify the OpenAPI schema is returned

Expected Results

  • /api/v1/docs/ returns JSON: {"swagger": "/api/v1/docs/swagger/", "redoc": "/api/v1/docs/redoc/", "schema": "/api/v1/docs/schema/"}
  • /api/v1/docs/swagger/ displays Swagger UI
  • /api/v1/docs/redoc/ displays ReDoc
  • /api/v1/docs/schema/ returns OpenAPI schema

Additional Context

Required Actions

  • Requires downstream repository changes
    • Any services that hardcode /api/v1/docs/ expecting Swagger UI will need to update to /api/v1/docs/swagger/

Note

Medium Risk
Changes public API documentation routes (notably moving Swagger off /docs/), which may break consumers that hardcode the old URL; logic changes are otherwise small and covered by new tests.

Overview
Reworks API documentation routing so GET /docs/ is now a new unauthenticated JSON index (DocsRootView) linking to Swagger, ReDoc, and the OpenAPI schema.

Moves Swagger UI from /docs/ to /docs/swagger/ while keeping /docs/redoc/ and /docs/schema/ intact, and updates docs plus adds tests asserting the new endpoints and index response.

Written by Cursor Bugbot for commit c180ab7. This will update automatically on new commits. Configure here.

Summary by CodeRabbit

  • New Features

    • Restructured API documentation endpoints for improved accessibility and organization
    • New documentation root endpoint provides an index of available documentation resources
    • Separate dedicated endpoints for Swagger UI, ReDoc, and raw API schema
  • Documentation

    • Updated API documentation guide with new endpoint information

@AlanCoding
Copy link
Copy Markdown
Member

This will be more-affecting of aap-gateway. Looks fine to me, but I think you need that team to review.

@TheRealHaoLiu
Copy link
Copy Markdown
Member Author

@john-westcott-iv

@john-westcott-iv
Copy link
Copy Markdown
Member

I pulled this down and it works as advertised but will require changes to the gateway so we will need a PR for that or a JIRA to track the work. We also need a JIRA for this work effort to get the DVCS check to start working.

Copy link
Copy Markdown
Contributor

@huffmanca huffmanca left a comment

Choose a reason for hiding this comment

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

I don't see a technical issue with this, and am approving it for now (but note that my approval in DAB means nothing). I don't feel comfortable approving the URL endpoint change for the team, and I'll let the Gateway representatives to DAB provide comments from that front.

@AlanCoding
Copy link
Copy Markdown
Member

Also, given that this is a thing, AWX doesn't have its ducks in a row either. I put up ansible/awx#16204

We just need to be more clear on the separations of responsibilities. But 👍 to the plan, just needs paperwork and the full set of cascading changes it implies.

@sonarqubecloud
Copy link
Copy Markdown

Introduces DocsRootView to provide an index of API documentation endpoints at /docs/. Updates URL patterns to include /docs/swagger/, /docs/redoc/, and /docs/schema/. Documentation updated to reflect new endpoints.
Introduces tests to verify accessibility and correctness of API documentation endpoints, including root docs, Swagger UI, and ReDoc. Ensures endpoints are accessible without authentication and return expected data.
@github-actions
Copy link
Copy Markdown

DVCS PR Check Results:

Could not find JIRA key(s) in PR title, branch name, or commit messages

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 24, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 898bb77 and c180ab7.

📒 Files selected for processing (4)
  • ansible_base/api_documentation/urls.py
  • ansible_base/api_documentation/views.py
  • docs/apps/api_documentation.md
  • test_app/tests/api_documentation/test_views.py

📝 Walkthrough

Walkthrough

The changes introduce a new API documentation root view that indexes available documentation endpoints alongside URL configuration reorganization to support dedicated routes for documentation features and raw schema exposure.

Changes

Cohort / File(s) Summary
Documentation URL Configuration
ansible_base/api_documentation/urls.py
Imported DocsRootView and reorganized URL patterns to introduce separate routes for docs root, Swagger UI, and schema endpoint while preserving ReDoc functionality.
Documentation Root View
ansible_base/api_documentation/views.py
New DocsRootView class that returns an ordered dictionary of documentation endpoint URLs (swagger, redoc, schema) with AllowAny permissions for unauthenticated access.
API Documentation
docs/apps/api_documentation.md
Added documentation listing available API documentation endpoints at /docs/, /docs/swagger/, /docs/redoc/, and /docs/schema/.
View Tests
test_app/tests/api_documentation/test_views.py
New test module with four test cases covering docs root view index structure, unauthenticated access, and accessibility of Swagger UI and ReDoc endpoints.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 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 and concisely summarizes the main changes: adding a docs index view and relocating Swagger UI to a new path.
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 (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

data['swagger'] = get_relative_url('swagger-ui')
data['redoc'] = get_relative_url('redoc')
data['schema'] = get_relative_url('schema')
return Response(data)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Docs root bypasses default auth settings

Medium Severity

DocsRootView hard-codes permission_classes = [permissions.AllowAny], which can override a deployment’s default DRF permission policy and make /docs/ publicly accessible even when the rest of the API (and possibly the docs endpoints) are intended to require authentication.

Fix in Cursor Fix in Web

@john-westcott-iv
Copy link
Copy Markdown
Member

@TheRealHaoLiu we need a JIRA ticket to associate this work with to get the last test passing. Once you have that you can alter the title to say "[AAP-XXXXX] ...." and then do a no-op push and the test will go green. Also, are you coordinating with the components to make sure any component PRs are in place to support this?

@sonarqubecloud
Copy link
Copy Markdown

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.

5 participants