Skip to content

feat(api): add OpenAPI documentation with security schemes#4896

Closed
vietlinhh02 wants to merge 1 commit into
ClankerNation:mainfrom
vietlinhh02:feat/openapi-docs
Closed

feat(api): add OpenAPI documentation with security schemes#4896
vietlinhh02 wants to merge 1 commit into
ClankerNation:mainfrom
vietlinhh02:feat/openapi-docs

Conversation

@vietlinhh02
Copy link
Copy Markdown

Summary

Implements OpenAPI documentation improvements as requested in #185.

Changes

api/main.py — Enhanced OpenAPI schema:

  • Security schemes: BearerAuth (JWT) and ApiKeyAuth (API key)
  • Global security requirements on all endpoints
  • Example values for AgentResponse, TaskResponse, LeaderboardEntry
  • Error response schemas (400, 401, 403, 404, 429) on all endpoints
  • Endpoint summaries and descriptions
  • Custom openapi() function to generate complete schema

api/routes/agents.py — Added summaries to all endpoints

api/tests/test_openapi.py — 11 tests:

  • Security scheme presence and configuration
  • Global security requirements
  • Error response schema existence
  • Model examples
  • Endpoint documentation
  • Swagger UI and ReDoc availability

Acceptance Criteria

  • Swagger UI displays lock icon on protected endpoints
  • Both auth methods visible in security schemes
  • Error responses have documented schemas
  • Models include example values

Closes #185

Improves API documentation:
- JWT Bearer and API Key security schemes in OpenAPI spec
- Global security requirements for all endpoints
- Example values for all response models
- Error response schemas (400, 401, 403, 404, 429)
- Endpoint summaries and descriptions
- Swagger UI and ReDoc available at /docs and /redoc
- 11 passing tests

Closes ClankerNation#185
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds richer OpenAPI documentation (auth schemes, standardized error responses, examples/summaries) and introduces tests that assert the generated OpenAPI schema contains these elements.

Changes:

  • Added OpenAPI schema tests validating security schemes, error response schemas, examples, and docs endpoints.
  • Enhanced FastAPI app metadata and endpoint docs (tags/summaries/descriptions) and added response models/examples.
  • Implemented a custom OpenAPI generator to inject global security schemes and default error responses.

Reviewed changes

Copilot reviewed 2 out of 6 changed files in this pull request and generated 3 comments.

File Description
api/tests/test_openapi.py Adds tests to validate OpenAPI schema contents and docs endpoints availability.
api/main.py Expands OpenAPI metadata/models and injects security + error responses via custom_openapi().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread api/main.py
Comment on lines +274 to +287
openapi_schema["components"]["securitySchemes"] = {
"BearerAuth": {
"type": "http",
"scheme": "bearer",
"bearerFormat": "JWT",
"description": "JWT token obtained from the login endpoint",
},
"ApiKeyAuth": {
"type": "apiKey",
"in": "header",
"name": "X-API-Key",
"description": "API key for programmatic access",
},
}
Comment thread api/main.py
Comment on lines +291 to +297
error_responses = {
"400": {"description": "Bad request", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ErrorResponse"}}}},
"401": {"description": "Authentication required", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ErrorResponse"}}}},
"403": {"description": "Forbidden", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ErrorResponse"}}}},
"404": {"description": "Not found", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ErrorResponse"}}}},
"429": {"description": "Rate limited", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ErrorResponse"}}}},
}
Comment thread api/tests/test_openapi.py
Comment on lines +4 to +7
import sys
import os

sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", ".."))
@github-actions
Copy link
Copy Markdown

Unfortunately the changes in this PR didn't fully resolve the issue. Please rework your solution and submit a new pull request within 2 hours.

Make sure to review the acceptance criteria in the linked issue and verify all conditions are met before resubmitting.

@github-actions github-actions Bot closed this May 29, 2026
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.

[ Bounty $7k ] [ API ] Add OpenAPI schema generation with authentication documentation — testnet finding

2 participants