CLI Guide¶
azure-functions-openapi ships with a CLI entry point for generating OpenAPI output from decorated handlers.
Install¶
Then verify:
Command overview¶
Current command set:
generate: build OpenAPI spec in JSON or YAML
generate command¶
Basic usage¶
By default this prints JSON to stdout using:
- title:
API - version:
1.0.0 - OpenAPI version:
3.0.0
Common examples¶
Generate JSON to stdout:
Generate YAML to stdout:
Write JSON to file:
Write YAML to file:
Generate OpenAPI 3.1 output:
Import your function app so routes are registered:
Pretty-print JSON output:
Options reference¶
| Option | Alias | Values | Default | Description |
|---|---|---|---|---|
--app |
- | module or module:var |
- | Import module before generating so @openapi decorators register routes |
--title |
- | any string | API |
OpenAPI info.title |
--version |
- | any string | 1.0.0 |
OpenAPI info.version |
--output |
-o |
file path | stdout | Write generated content to file |
--format |
-f |
json, yaml |
json |
Output serialization format |
--openapi-version |
- | 3.0, 3.1 |
3.0 |
OpenAPI schema version |
--pretty |
-p |
flag | false |
Pretty-print JSON output (adds indentation); no effect on YAML |
Exit codes¶
| Code | Meaning |
|---|---|
0 |
Success |
1 |
Runtime or generation error |
2 |
Invalid CLI arguments (argparse parse error) |
Validate generated output¶
Use a validator in local checks and CI:
For YAML:
CI example¶
name: OpenAPI Validation
on: [push, pull_request]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install tools
run: pip install azure-functions-openapi openapi-spec-validator
- name: Generate spec
run: azure-functions-openapi generate --openapi-version 3.1 --output openapi.json
- name: Validate spec
run: openapi-spec-validator openapi.json
Troubleshooting¶
command not found¶
- Confirm package installed in active environment
- Use
python -m azure_functions_openapi.cli --helpas fallback
Empty paths in output¶
- Ensure app handlers are decorated with
@openapi - Pass
--app <module>so decorated routes are registered before generation:
- Use
module:variablesyntax when theFunctionAppinstance is not namedapp:
Unsupported version error¶
- Use only
--openapi-version 3.0or--openapi-version 3.1