https://github.com/yeongseon/azure-functions-openapi
OpenAPI (Swagger) documentation and Swagger UI for Azure Functions Python v2 — Part of the Azure Functions Python DX Toolkit
https://github.com/yeongseon/azure-functions-openapi
azure azure-functions dx-toolkit openapi python serverless swagger
Last synced: 4 days ago
JSON representation
OpenAPI (Swagger) documentation and Swagger UI for Azure Functions Python v2 — Part of the Azure Functions Python DX Toolkit
- Host: GitHub
- URL: https://github.com/yeongseon/azure-functions-openapi
- Owner: yeongseon
- License: mit
- Created: 2025-05-03T04:31:45.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2026-04-04T12:22:39.000Z (8 days ago)
- Last Synced: 2026-04-04T13:23:41.963Z (8 days ago)
- Topics: azure, azure-functions, dx-toolkit, openapi, python, serverless, swagger
- Language: Python
- Homepage: https://yeongseon.github.io/azure-functions-openapi/
- Size: 7.04 MB
- Stars: 20
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.ja.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
- Support: SUPPORT.md
- Agents: AGENTS.md
Awesome Lists containing this project
README
# Azure Functions OpenAPI
[](https://pypi.org/project/azure-functions-openapi/)
[](https://pypi.org/project/azure-functions-openapi/)
[](https://github.com/yeongseon/azure-functions-openapi/actions/workflows/ci-test.yml)
[](https://github.com/yeongseon/azure-functions-openapi/actions/workflows/release.yml)
[](https://github.com/yeongseon/azure-functions-openapi/actions/workflows/security.yml)
[](https://codecov.io/gh/yeongseon/azure-functions-openapi)
[](https://pre-commit.com/)
[](https://yeongseon.github.io/azure-functions-openapi/)
[](LICENSE)
他の言語: [English](README.md) | [한국어](README.ko.md) | [简体中文](README.zh-CN.md)
**Azure Functions Python v2 プログラミング モデル**向けの OpenAPI(Swagger)ドキュメント生成と Swagger UI を提供します。
## Why Use It
Azure Functions の HTTP API をドキュメント化するには、通常、別途 OpenAPI スペックを手作業で管理する必要があります。`azure-functions-openapi` はデコレータ付きハンドラーからスペックを自動生成し、ドキュメントとコードの同期を維持します。
## Scope
- Azure Functions Python **v2 プログラミング モデル**
- decorator ベースの `func.FunctionApp()` アプリケーション
- `@openapi` で文書化された HTTP トリガー関数
- オプションの Pydantic スキーマ生成(Pydantic v1 と v2 の両方をサポート)
このパッケージは従来の `function.json` ベースの v1 プログラミング モデルには対応していません。
## Features
- operation メタデータ用の `@openapi` decorator
- `/openapi.json`, `/openapi.yaml`, `/docs` エンドポイント
- query, path, header, body, response スキーマのサポート
- セキュアなデフォルトを備えた Swagger UI helper
- 生成および検証ワークフローのための CLI ツール
## Installation
```bash
pip install azure-functions-openapi
```
Function App の依存関係には次を含めてください。
```text
azure-functions
azure-functions-openapi
```
## Quick Start
```python
import json
import azure.functions as func
from azure_functions_openapi.decorator import openapi
from azure_functions_openapi.openapi import get_openapi_json, get_openapi_yaml
from azure_functions_openapi.swagger_ui import render_swagger_ui
app = func.FunctionApp()
@app.function_name(name="http_trigger")
@app.route(route="http_trigger", auth_level=func.AuthLevel.ANONYMOUS, methods=["POST"])
@openapi(
summary="Greet user",
route="/api/http_trigger",
method="post",
request_body={
"type": "object",
"properties": {"name": {"type": "string"}},
"required": ["name"],
},
response={
200: {
"description": "Successful greeting",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {"message": {"type": "string"}},
}
}
},
}
},
tags=["Example"],
)
def http_trigger(req: func.HttpRequest) -> func.HttpResponse:
data = req.get_json()
name = data.get("name", "world")
return func.HttpResponse(
json.dumps({"message": f"Hello, {name}!"}),
mimetype="application/json",
)
@app.function_name(name="openapi_json")
@app.route(route="openapi.json", auth_level=func.AuthLevel.ANONYMOUS, methods=["GET"])
def openapi_json(req: func.HttpRequest) -> func.HttpResponse:
return func.HttpResponse(
get_openapi_json(
title="Sample API",
description="OpenAPI document for the Sample API.",
),
mimetype="application/json",
)
@app.function_name(name="openapi_yaml")
@app.route(route="openapi.yaml", auth_level=func.AuthLevel.ANONYMOUS, methods=["GET"])
def openapi_yaml(req: func.HttpRequest) -> func.HttpResponse:
return func.HttpResponse(
get_openapi_yaml(
title="Sample API",
description="OpenAPI document for the Sample API.",
),
mimetype="application/x-yaml",
)
@app.function_name(name="swagger_ui")
@app.route(route="docs", auth_level=func.AuthLevel.ANONYMOUS, methods=["GET"])
def swagger_ui(req: func.HttpRequest) -> func.HttpResponse:
return render_swagger_ui()
```
ローカルでは Azure Functions Core Tools で実行できます。
```bash
func start
```
## Demo
代表的な `hello` サンプルは、このライブラリを導入したときの結果全体を示します。
- Azure Functions v2 の HTTP ハンドラーに `@openapi` を付与します。
- パッケージがそのルートに対する実際の OpenAPI ドキュメントを生成します。
- 同じルートがブラウザ確認用に Swagger UI でレンダリングされます。
### Generated Spec Result
生成された OpenAPI ファイルは、同じサンプル実行から静的プレビューとして取得されています。そのため、この README には代表的な関数が実際に生成したドキュメントが表示されます。

### Swagger UI Result
以下の Web プレビューも同じ代表サンプルから生成されており、そのフローで作られた Swagger UI ページを自動的にレンダリングして取得したものです。

## Documentation
- 全ドキュメント: [yeongseon.github.io/azure-functions-openapi](https://yeongseon.github.io/azure-functions-openapi/)
- スモークテスト済みサンプル: `examples/`
- [Installation Guide](docs/installation.md)
- [Usage Guide](docs/usage.md)
- [API Reference](docs/api.md)
- [CLI Guide](docs/cli.md)
## Ecosystem
- [azure-functions-langgraph](https://github.com/yeongseon/azure-functions-langgraph) — LangGraph デプロイアダプター
- [azure-functions-validation](https://github.com/yeongseon/azure-functions-validation) — リクエストとレスポンスのバリデーション
- [azure-functions-logging](https://github.com/yeongseon/azure-functions-logging) — 構造化ロギング
- [azure-functions-doctor](https://github.com/yeongseon/azure-functions-doctor) — 診断 CLI
- [azure-functions-scaffold](https://github.com/yeongseon/azure-functions-scaffold) — プロジェクトスキャフォールディング
- [azure-functions-durable-graph](https://github.com/yeongseon/azure-functions-durable-graph) — Durable Functions ベースのグラフランタイム
- [azure-functions-python-cookbook](https://github.com/yeongseon/azure-functions-python-cookbook) — レシピとサンプル
## Disclaimer
このプロジェクトは独立したコミュニティプロジェクトであり、Microsoft と提携・承認・保守関係にはありません。
Azure および Azure Functions は Microsoft Corporation の商標です。
## License
MIT