Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions smart_tests/commands/get/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from ... import args4p
from ...app import Application
from .api_schema import api_schema
from .docs import docs


Expand All @@ -8,4 +9,5 @@ def get(app: Application):
return app


get.add_command(api_schema)
get.add_command(docs)
44 changes: 44 additions & 0 deletions smart_tests/commands/get/api_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import json
import sys
from http import HTTPStatus
from typing import Annotated

import click

from smart_tests import args4p
from smart_tests.app import Application
from smart_tests.args4p import typer
from smart_tests.utils.http_client import _HttpClient, get_base_url


@args4p.command()
def api_schema(
app: Application,
output_file: Annotated[str, typer.Option(
'--output', '-o',
help="Output file path"
)] = "openapi-schema.json"):
"""Download the OpenAPI schema for the Smart Tests API"""
# Use HttpClient directly since /v3/api-docs is not under /organizations/{org}/workspaces/{ws}
http_client = _HttpClient(base_url=get_base_url(), app=app)

try:
# Fetch schema from /intake/v3/api-docs endpoint
res = http_client.request("get", "/intake/v3/api-docs")

if res.status_code == HTTPStatus.NOT_FOUND:
click.echo(click.style("API schema not available on this server", 'yellow'), err=True)
sys.exit(1)

res.raise_for_status()
schema = res.json()

# Save to file with proper formatting
with open(output_file, 'w') as f:
json.dump(schema, f, indent=2)

click.echo(f"OpenAPI schema saved to {output_file}")

except Exception as e:
click.echo(click.style(f"Failed to fetch API schema: {e}", 'red'), err=True)
sys.exit(1)
Loading