Coverage for apps/core_los/management/commands/export_openapi.py: 0%
7 statements
« prev ^ index » next coverage.py v7.17.0, created at 2026-11-04 17:24 +0000
« prev ^ index » next coverage.py v7.17.0, created at 2026-11-04 17:24 +0000
1"""Export the Django Ninja OpenAPI schema as JSON to stdout.
3Lets `make generate-api` produce the TypeScript client without a running server
4(e.g. in CI): `uv run python manage.py export_openapi > ../frontend/.../openapi.json`.
6Output is indented with 4 spaces and has its keys sorted so the committed
7api-client/openapi.json stays stable: `make generate-api` rewrites it in place
8without reformatting churn, and reordering backend routes or schemas no longer
9reshuffles the file (which previously produced thousand-line diffs for a one-line
10change). Django's BaseCommand stdout appends the trailing newline. The drift guard
11(deploy/scripts/check-openapi-drift.sh) compares via `jq -S`, so this formatting
12does not affect the schema-equivalence check.
13"""
15import json
17from django.core.management.base import BaseCommand
19from config.api import api
22class Command(BaseCommand):
23 help = "Print the Django Ninja OpenAPI schema (JSON) to stdout."
25 def handle(self, *args, **options):
26 self.stdout.write(json.dumps(api.get_openapi_schema(), indent=4, sort_keys=True))