Skip to content

Conversation

@kaxil
Copy link
Collaborator

@kaxil kaxil commented Jan 31, 2026

Summary

Refactors the af api command to use subcommands instead of flags for listing endpoints and fetching the OpenAPI spec:

  • af api --endpointsaf api ls
  • af api --endpoints --filter varaf api ls --filter var
  • af api --specaf api spec

Design rationale

Why subcommands instead of flags?
Aligns with CLI conventions where distinct operations are subcommands (like git remote add vs git remote -a). The ls and spec operations are semantically different from making API calls.

Why not use Typer's native subcommand feature?
Typer processes positional arguments before checking subcommands. With formal subcommands registered, af api dags -F limit=10 would fail with "No such command 'dags'". Instead, we detect reserved names (ls, spec) in the main handler and dispatch to internal functions.

Why move OpenAPI fetching to adapters?
The original CLI code had AF2/AF3 fallback logic (try /openapi.json, fall back to /api/v1/openapi.yaml). This version-specific behavior belongs in adapters, following the existing pattern for all other Airflow operations.

Usage

# List all endpoints
af api ls

# Filter endpoints
af api ls --filter variable

# Get OpenAPI spec
af api spec
af api spec -i  # include headers

# Existing functionality unchanged
af api dags
af api dags -F limit=5
af api variables -X POST -F key=test -f value=hello

Gotchas

  • ls and spec are reserved endpoint names. If Airflow ever adds actual /ls or /spec endpoints, users would need af api /ls --raw to access them directly.

kaxil added 4 commits January 31, 2026 14:45
Replace `--endpoints` and `--spec` flags with `ls` and `spec` subcommands
for a cleaner CLI UX:

- `af api --endpoints` → `af api ls`
- `af api --endpoints --filter var` → `af api ls --filter var`
- `af api --spec` → `af api spec`

Add `get_openapi_spec()` method to adapters to encapsulate AF2/AF3
differences (YAML at /api/v1/openapi.yaml vs JSON at /openapi.json).

Existing functionality unchanged: `af api dags`, `af api dags -F limit=5`,
etc. continue to work as before.
@kaxil kaxil merged commit 54871d9 into main Jan 31, 2026
10 checks passed
@kaxil kaxil deleted the refactor/api-subcommands branch January 31, 2026 14:55
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