Skip to content

Add apidocs with pages and health#925

Open
audreyfeldroy wants to merge 11 commits intofeldroy:mainfrom
audreyfeldroy:add-apidocs-with-pages-and-health
Open

Add apidocs with pages and health#925
audreyfeldroy wants to merge 11 commits intofeldroy:mainfrom
audreyfeldroy:add-apidocs-with-pages-and-health

Conversation

@audreyfeldroy
Copy link
Member

This PR adds a built-in /health endpoint and enables FastAPI's built-in API docs, providing foundational API infrastructure to Air applications.

Summary

  • Built-in /health endpoint - Returns {"status": "ok"} JSON for load balancers, Kubernetes probes, and uptime monitors
  • API docs enabled by default - Swagger UI at /_swagger, ReDoc at /_redoc (underscore prefix keeps /docs free for user content)
  • Air branding in API docs - Shows "Air" title with version, description links to docs
  • Default tags=["pages"] - Air routes tagged "pages" to distinguish from other routes in API docs
  • CLI banner shows API docs URLs - Startup banner now displays both doc endpoints

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • New feature
    • Core Air (Air Tags, Request/Response cycle, etc)
    • Optional (Authentication, CSRF, etc)
    • Third-Party Integrated (Cookbook documentation on using Air databases or a task manager, etc)
    • Out-of-Scope (Formal integration with databases, external task managers, or commercial services etc - won't be accepted, please create a separate project)
  • Refactoring (no functional changes, no api changes)
  • Chore: Dependency updates, Python version changes, etc.
  • Build related changes
  • Documentation content changes
  • Other (please describe):

Pull request tasks

The following have been completed for this task:

  • Code changes
  • Documentation changes for new or changed features
  • Alterations of behavior come with a working implementation in the examples folder
  • Tests on new or altered behaviors

Checklist

  • I have run just test and just qa, ensuring my code changes passes all existing tests
  • I have performed a self-review of my own code
  • I have ensured that there are tests to cover my changes

Demo or screenshot

CLI banner showing new API docs URLs:
Screenshot 2025-12-27 at 02 29 45

Other information

Behavior change: API docs and /health are now enabled by default. Users can disable with docs_url=None, redoc_url=None, or override the health endpoint.

@codecov
Copy link

codecov bot commented Dec 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

from .routing import AirRoute, RouteCallable, RouterMixin
from .types import MaybeAwaitable

AIR_VERSION = get_version("air")
Copy link

Choose a reason for hiding this comment

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

Can you please put these new constants in src/air/constants.py?

"""
),
] = None,
] = "/_swagger",
Copy link

Choose a reason for hiding this comment

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

Should be a constant too!

"""
),
] = None,
] = "/_redoc",
Copy link

Choose a reason for hiding this comment

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

Should be a constant too!

"""
),
] = None,
] = "/openapi.json",
Copy link

Choose a reason for hiding this comment

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

Should be a constant too!

@audreyfeldroy
Copy link
Member Author

Added named constants for the URLs — good call on improving readability:

DEFAULT_SWAGGER_URL = "/_swagger"
DEFAULT_REDOC_URL = "/_redoc"
DEFAULT_OPENAPI_URL = "/openapi.json"

Keeping them in applications.py since they're only used here. Python convention is to co-locate constants with their consumers.

@audreyfeldroy
Copy link
Member Author

@pygarap After considering it more, I've moved the shared constants to constants.py. Module-specific constants will remain for locality until they become shared, then moved.

@audreyfeldroy audreyfeldroy force-pushed the add-apidocs-with-pages-and-health branch from 4ac68d1 to 06eb76c Compare December 28, 2025 22:53
Introduces a default /health endpoint returning status 'ok' as JSON in Air applications. Updates default OpenAPI metadata and tags, and adds a test to verify the health endpoint.
Changed the default API documentation URL from /docs to /_docs in both the application and CLI. Updated the default description to reference FastAPI and link to the Air documentation site.
Revised the docstring to clarify the purpose of shared constants and note that module-specific constants are kept with their respective consumers.
Moved default title and attribution strings to constants.py for reuse. Updated application and CLI to use these constants, and improved the default API description for clarity and branding consistency.
@audreyfeldroy audreyfeldroy force-pushed the add-apidocs-with-pages-and-health branch from 06eb76c to 2a96fb2 Compare December 28, 2025 22:53
We need this in order to test the Air CLI
Eliminated the internal _load_app and _add_healthcheck_route functions from the CLI. The run command now passes the app path directly to uvicorn, simplifying the startup process and removing custom FastAPI healthcheck injection.
@audreyfeldroy audreyfeldroy removed the request for review from pydanny February 2, 2026 19:41
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