{"id":27904797,"url":"https://github.com/straydragon/flask-x-openapi-schema","last_synced_at":"2026-02-28T10:02:16.290Z","repository":{"id":291237941,"uuid":"964467473","full_name":"StrayDragon/flask-x-openapi-schema","owner":"StrayDragon","description":"A powerful utility for automatically generating OpenAPI schemas support Flask(MethodView) and Flask-RESTful(Resource) applications and Pydantic models to simplify API documentation with minimal effort.","archived":false,"fork":false,"pushed_at":"2025-05-06T08:18:36.000Z","size":24817,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-19T18:54:08.266Z","etag":null,"topics":["flask","openapi","swagger"],"latest_commit_sha":null,"homepage":"https://straydragon.github.io/flask-x-openapi-schema/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/StrayDragon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-11T09:01:47.000Z","updated_at":"2025-07-23T03:55:11.000Z","dependencies_parsed_at":"2025-05-03T10:22:39.324Z","dependency_job_id":"8a3fb8b6-0a39-4b3b-b34d-07bbfb89b0f0","html_url":"https://github.com/StrayDragon/flask-x-openapi-schema","commit_stats":null,"previous_names":["straydragon/flask-x-openapi-schema"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/StrayDragon/flask-x-openapi-schema","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StrayDragon%2Fflask-x-openapi-schema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StrayDragon%2Fflask-x-openapi-schema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StrayDragon%2Fflask-x-openapi-schema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StrayDragon%2Fflask-x-openapi-schema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StrayDragon","download_url":"https://codeload.github.com/StrayDragon/flask-x-openapi-schema/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StrayDragon%2Fflask-x-openapi-schema/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29929587,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-28T09:58:13.507Z","status":"ssl_error","status_checked_at":"2026-02-28T09:57:57.047Z","response_time":90,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["flask","openapi","swagger"],"created_at":"2025-05-05T23:32:59.158Z","updated_at":"2026-02-28T10:02:16.236Z","avatar_url":"https://github.com/StrayDragon.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Flask-X-OpenAPI-Schema\n\n[![GitHub](https://img.shields.io/badge/github-flask--x--openapi--schema-lightgrey.svg)](https://github.com/StrayDragon/flask-x-openapi-schema)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/flask-x-openapi-schema)](https://pypi.org/project/flask-x-openapi-schema/)\n[![PyPI - Version](https://img.shields.io/pypi/v/flask-x-openapi-schema)](https://pypi.org/project/flask-x-openapi-schema/)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)\n\n[![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)\n[![Code style: ruff](https://img.shields.io/badge/code%20style-ruff-000000.svg)](https://github.com/astral-sh/ruff)\n[![CI](https://github.com/StrayDragon/flask-x-openapi-schema/actions/workflows/ci.yaml/badge.svg?branch=main)](https://github.com/StrayDragon/flask-x-openapi-schema/actions/workflows/ci.yaml)\n[![Codecov](https://codecov.io/gh/straydragon/flask-x-openapi-schema/branch/main/graph/badge.svg)](https://codecov.io/gh/straydragon/flask-x-openapi-schema)\n\nA powerful utility for automatically generating OpenAPI schemas support Flask(MethodView) and Flask-RESTful(Resource) applications and Pydantic models to simplify API documentation with minimal effort.\n\n## 📚 Documentation\n\nFull documentation is available in the [docs](./docs) directory and online at [https://straydragon.github.io/flask-x-openapi-schema/](https://straydragon.github.io/flask-x-openapi-schema/).\n\n## 📝 Examples\n\nComplete examples are available in the [examples/](https://github.com/StrayDragon/flask-x-openapi-schema/tree/main/examples) directory. These examples demonstrate all the features of the library, including:\n\n- Parameter binding (path, query, body)\n- File uploads (images, documents, audio, video)\n- Internationalization\n- Response models\n- OpenAPI schema generation\n\n## 🚀 Quick Start\n\n```bash\n# Install the package\nuv pip install flask-x-openapi-schema\n\n# With Flask-RESTful support\nuv pip install flask-x-openapi-schema[flask-restful]\n```\n\n## ✨ Features\n\n- **Framework Support**: Works with both Flask and Flask-RESTful applications\n- **Auto-Generation**: Generate OpenAPI schemas from Flask-RESTful resources and Flask.MethodView classes\n- **Pydantic Integration**: Seamlessly convert Pydantic models to OpenAPI schemas\n- **Smart Parameter Handling**: Inject request parameters from Pydantic models with configurable prefixes\n- **Type Safety**: Preserve type annotations for better IDE support and validation\n- **Multiple Formats**: Output schemas in YAML or JSON format\n- **Internationalization**: Built-in i18n support for API documentation with thread-safe language switching\n- **File Upload Support**: Simplified handling of file uploads with validation\n- **Flexible Architecture**: Modular design with framework-specific implementations\n- **Performance Optimized**: Caching of static information for improved performance\n\n## 🚀 Performance\n\nFlask-X-OpenAPI-Schema is designed with performance in mind. Our benchmarks show minimal overhead when using the library compared to standard Flask and Flask-RESTful applications.\n\n### Benchmark Results\n\n![](./benchmarks/results/performance_charts.png)\n\n| Framework     | Endpoint | Requests | Success Rate | Median (ms) | 95%ile (ms) | Avg (ms) | RPS    | Overhead |\n|---------------|----------|----------|--------------|-------------|-------------|----------|--------|----------|\n| Flask         | Standard | 7930     | 100.00%      | 270.00      | 270.00      | 306.01   | 132.18 | baseline |\n| Flask         | OpenAPI  | 7797     | 100.00%      | 280.00      | 280.00      | 312.85   | 129.96 | +2.23%   |\n| Flask-RESTful | Standard | 7654     | 100.00%      | 310.00      | 310.00      | 348.35   | 127.30 | baseline |\n| Flask-RESTful | OpenAPI  | 7603     | 99.68%       | 310.00      | 310.00      | 358.92   | 126.45 | +3.03%   |\n\nThese benchmarks were conducted using Locust with 200 concurrent users and a ramp-up rate of 20 users per second over a 60-second test period. The tests measured the performance of identical endpoints implemented with and without Flask-X-OpenAPI-Schema.\n\nFor more detailed benchmarks and to run your own performance tests, see the [benchmarks](./benchmarks) directory.\n\n## 📦 Installation\n\n### Development Setup\n\nThis project uses `uv` for package management and `ruff` for linting and formatting and need `just` for project management:\n\n```bash\n# Install all dependencies including development ones\njust sync-all-deps\n\n# Format and lint code\njust format-and-lintfix\n```\n\n## 🛠️ Basic Usage\n\nSee the [Usage Guide](./docs/usage_guide.md) for more detailed examples.\n\n### Flask.MethodView Example\n\n(diy) see and run [example](./examples/flask/app.py)\n\n### Flask-RESTful Example\n\n(diy) see and run [example](./examples/flask_restful/app.py)\n\n## 📋 Key Features\n\n### Framework-Specific Implementations\n\nThe library provides separate implementations for Flask and Flask-RESTful:\n\n```python\n# For Flask.MethodView\nfrom flask_x_openapi_schema.x.flask import openapi_metadata\n\n# For Flask-RESTful\nfrom flask_x_openapi_schema.x.flask_restful import openapi_metadata\n```\n\n### Parameter Binding with Special Prefixes\n\nThe library binds parameters with special prefixes default, and can custom by yourself:\n\n- `_x_body`: Request body from JSON\n- `_x_query`: Query parameters\n- `_x_path_\u003cparam_name\u003e`: Path parameters\n- `_x_file`: File uploads\n\n#### Custom Parameter Prefixes\n\n```python\nfrom flask_x_openapi_schema import ConventionalPrefixConfig, configure_prefixes\n\n# Create a custom configuration\ncustom_config = ConventionalPrefixConfig(\n    request_body_prefix=\"req_body\",\n    request_query_prefix=\"req_query\",\n    request_path_prefix=\"req_path\",\n    request_file_prefix=\"req_file\"\n)\n\n# Configure globally\nconfigure_prefixes(custom_config)\n\n# Or per-function\n@openapi_metadata(\n    summary=\"Test endpoint\",\n    prefix_config=custom_config\n)\ndef my_function(req_body: MyModel, req_query: QueryModel):\n    # Use custom prefixes\n    return {\"message\": \"Success\"}\n```\n\n### I18n Support\n\n```python\nfrom flask_x_openapi_schema import I18nStr, set_current_language\n\n# Set the current language\nset_current_language(\"zh-Hans\")\n\n@openapi_metadata(\n    summary=I18nStr({\n        \"en-US\": \"Get an item\",\n        \"zh-Hans\": \"获取一个项目\",\n        \"ja-JP\": \"アイテムを取得する\"\n    }),\n    ...\n)\ndef get(self, item_id):\n    # ...\n```\n\n### File Upload Support\n\n```python\nfrom flask_x_openapi_schema import ImageUploadModel\n\n@openapi_metadata(\n    summary=\"Upload an image\"\n)\ndef post(self, _x_file: ImageUploadModel):\n    # File is automatically injected and validated\n    return {\"filename\": _x_file.file.filename}\n```\n\n### Response Models\n\n```python\nfrom flask_x_openapi_schema import BaseRespModel\nfrom pydantic import Field\n\nclass ItemResponse(BaseRespModel):\n    id: str = Field(..., description=\"Item ID\")\n    name: str = Field(..., description=\"Item name\")\n    price: float = Field(..., description=\"Item price\")\n\n    # Will be automatically converted to a Flask response\n    # return ItemResponse(id=\"123\", name=\"Example\", price=10.99), 200\n```\n\n## 🧪 Testing and Coverage\n\nThis project uses `pytest` for testing and `pytest-cov` for coverage reporting:\n\n```bash\n# Run tests with coverage report\njust test\n\n# Run tests in parallel for faster execution\njust test-parallel\n\n# Run tests in parallel with specific number of workers\njust test-parallel '' 4\n\n# View HTML coverage report\n# Open htmlcov/index.html in your browser\n```\nSee [Testing Guide](./docs/testing.md) for more details on testing.\n\n## 📊 Benchmarking\n\nThe project includes benchmarking tools to measure performance:\n\n```bash\n# Run benchmarks and generate report\njust benchmark\n```\n\n## 📖 More Docs\n\n- [Core Components](./docs/core_components.md)\n- [Internationalization](./docs/internationalization.md)\n- [File Uploads](./docs/file_uploads.md)\n- [...](./docs/)\n\n## 🧩 Components\n\n- **Core**: Base functionality shared across all implementations\n  - **Schema Generator**: Converts resources to OpenAPI schemas\n  - **Configuration**: Configurable parameter prefixes and settings\n  - **Cache**: Performance optimization for schema generation\n- **Framework-Specific**:\n  - **Flask**: Support for Flask.MethodView classes\n  - **Flask-RESTful**: Support for Flask-RESTful resources\n- **Models**:\n  - **Base Models**: Type-safe response handling\n  - **File Models**: Simplified file upload handling\n- **Internationalization**:\n  - **I18nStr**: Multilingual string support\n  - **Language Management**: Thread-safe language switching\n- **Utilities**: Helper functions for schema creation and manipulation\n\n## 📝 License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstraydragon%2Fflask-x-openapi-schema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstraydragon%2Fflask-x-openapi-schema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstraydragon%2Fflask-x-openapi-schema/lists"}