Hello OpenAPI Example¶
The hello_openapi example demonstrates the most minimal usage of the @openapi decorator.
Files¶
examples/hello_openapi/function_app.pyexamples/hello_openapi/host.jsonexamples/hello_openapi/requirements.txt
Requirements¶
- Python 3.10+
- Azure Functions Core Tools
Key Concepts¶
- One route
- No request model
- Returns a simple greeting response
Sample¶
@app.route(route="hello", ...)
@openapi(summary="Hello", description="Returns a greeting.", response_model=HelloResponse)
def hello(req: HttpRequest) -> HttpResponse:
...
Local Setup¶
Create a local.settings.json (not committed) to configure the Python worker runtime:
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "python"
}
}
Install dependencies:
python3.10 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
Run locally:
func start
Endpoints¶
GET /api/http_trigger?name=AzureGET /api/openapi.jsonGET /api/openapi.yamlGET /api/docs