Metadata-Version: 2.4
Name: fastapi_swagger2
Version: 0.3.5
Summary: Swagger2 support for FastAPI framework
Author: Viraj Kanwade
Author-email: Viraj Kanwade <virajk.oib@gmail.com>
License-Expression: MIT
License-File: LICENSE
Classifier: Intended Audience :: Information Technology
Classifier: Intended Audience :: System Administrators
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python
Classifier: Topic :: Internet
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development
Classifier: Typing :: Typed
Classifier: Environment :: Web Environment
Classifier: Framework :: AsyncIO
Classifier: Framework :: FastAPI
Classifier: Framework :: Pydantic
Classifier: Framework :: Pydantic :: 1
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
Classifier: Topic :: Internet :: WWW/HTTP
Requires-Dist: fastapi>=0.129.0,<0.137.0
Requires-Dist: httpx>=0.28.1 ; extra == 'all'
Requires-Dist: ruff==0.15.17 ; extra == 'dev'
Requires-Dist: pytest>=9.0.0 ; extra == 'test'
Requires-Dist: coverage[toml]>=6.0,<8.0 ; extra == 'test'
Requires-Dist: ty ; extra == 'test'
Requires-Dist: ruff==0.15.17 ; extra == 'test'
Requires-Dist: httpx>=0.28.1 ; extra == 'test'
Requires-Python: >=3.10
Project-URL: Homepage, https://github.com/virajkanwade/fastapi_swagger2
Project-URL: Documentation, https://github.com/virajkanwade/fastapi_swagger2
Provides-Extra: all
Provides-Extra: dev
Provides-Extra: test
Description-Content-Type: text/markdown

# fastapi_swagger2
<p align="center">
Swagger2 support for FastAPI
</p>
<p align="center">
<a href="https://pypi.org/project/fastapi_swagger2" target="_blank">
    <img src="https://img.shields.io/pypi/v/fastapi_swagger2?color=%2334D058&label=pypi%20package" alt="Package version">
</a>
<a href="https://pypi.org/project/fastapi_swagger2" target="_blank">
    <img src="https://img.shields.io/pypi/pyversions/fastapi_swagger2.svg?color=%2334D058" alt="Supported Python versions">
</a>
</p>

---

_Reason behind this library:_

Few API GW services like Google Cloud API GW still support only Swagger 2.0 spec. Since FastAPI only supports OAS3, it is a challenge. Converting from OAS3 to Swagger 2.0 requires some manual steps which would hinder CI/CD.

---

## Requirements

Python 3.9+

* 0.0.3 - FastAPI >= 0.79.0, <= 0.98.0
* 0.1.1 - FastAPI >= 0.99.0, <= 0.99.1
* 0.2.4 - FastAPI >= 0.100.0
* 0.2.7 - FastAPI >= 0.100.0, < 0.119.0 + Pydantic v1/v2
* 0.3.0 - FastAPI >= 0.119.0, <= 0.123.8 + Pydantic v1/v2
* 0.3.1 - FastAPI >= 0.123.9, <= 0.127.1 + Pydantic v1/v2 (Since FastAPI 0.126.1, Pydantic v1 is deprecated)
* 0.3.2 - FastAPI >= 0.128.0, <= 0.128.3
* 0.3.3 - FastAPI >= 0.128.4, <= 0.128.8 (FastAPI has dropped Python 3.9 support since 0.129.1)
* 0.3.4 - FastAPI >= 0.129.0             (last tested against 0.133.1)
* 0.3.5 - FastAPI >= 0.129.0, < 0.137.0

## Installation

<div class="termy">

```console
$ pip install fastapi_swagger2
```

</div>

## Development

```console
$ uv sync --extra dev --extra test --extra all
```

## Example

```Python
from typing import Union

from fastapi import FastAPI
from fastapi_swagger2 import FastAPISwagger2

app = FastAPI()
FastAPISwagger2(app)


@app.get("/")
def read_root():
    return {"Hello": "World"}


@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
    return {"item_id": item_id, "q": q}
```

This adds following endpoints:
* http://localhost:8000/swagger2.json
* http://localhost:8000/swagger2/docs
* http://localhost:8000/swagger2/redoc

## Generate spec for CI/CD

```Python
import os

import yaml

from app.main import app

URL = os.environ["CLOUD_RUN_URL"]

app.servers.append(URL)

spec = app.swagger2()
spec['x-google-backend'] = {'address': URL}

print(yaml.dump(spec))
```

## Development

```console
$ uv sync --extra dev --extra test --extra all
```
