Skip to content

Commit

Permalink
Amend init
Browse files Browse the repository at this point in the history
  • Loading branch information
TawneeOwl committed Dec 18, 2024
1 parent ccd1985 commit 8cf534a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 40 deletions.
19 changes: 3 additions & 16 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
from fastapi import FastAPI, APIRouter
from .routers.v1 import case_information as case_information_v1, security as security_v1
from fastapi import FastAPI
from .config.docs import config as docs_config


def v1_router():
router = APIRouter(prefix="/v1")
router.include_router(case_information_v1.router)
router.include_router(security_v1.router)
return router


def v2_router():
router = APIRouter(prefix="/v2")
router.include_router(case_information_v1.router)
return router
from .routers.v1 import router as v1_router


def create_app() -> FastAPI:
app = FastAPI(**docs_config)
app.include_router(v1_router())
app.include_router(v1_router)

return app
6 changes: 6 additions & 0 deletions app/routers/v1/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from fastapi import APIRouter
from . import case_information, security

router = APIRouter(prefix="/v1")
router.include_router(case_information.router)
router.include_router(security.router)
36 changes: 13 additions & 23 deletions docs/source/documentation/version_control.html.md.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: Version Control
title: API Versioning
---

# Version Control
# API Versioning
Version control helps manage changes to an API without breaking existing integrations or disrupting users relying on older versions.
Version control in our API is done using URL versioning.

Expand All @@ -13,39 +13,29 @@ For example:
/v1/cases/{case_id}
```

Changes in version should be recorded in a version folder in app/routers with all the required routers.
Changes in version should be recorded in a version directory in app/routers with all the required routers.

New router versions should be defined in the `main.py` file.
New router versions should be defined in the init file of that version.
You will need to include each router in your version directory.

```
from .routers.v1 import case_information as case_information_v1, security as security_v1
from fastapi import APIRouter
from . import case_information, security

def v1_router():
router = APIRouter(prefix="/v1")
router.include_router(case_information_v1.router)
router.include_router(security_v1.router)
return router
router = APIRouter(prefix="/v1")
router.include_router(case_information.router)
router.include_router(security.router)
```
In the `main.py` file you will also need to include your new version router:

```
from .routers.v1 import router as v1_router

def create_app() -> FastAPI:
app = FastAPI(**docs_config)
app.include_router(v1_router())
app.include_router(v1_router)

return app
```

This will establish a version route for your endpoint.

## Including previous version routers
If you require a previous version of a router in your new version;
include the previous version router:

```
def v2_router():
router = APIRouter(prefix="/v2")
router.include_router(case_information_v1.router)
return router
```
This will establish a version route for your endpoint.
2 changes: 1 addition & 1 deletion tests/v1/cases/test_case_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from fastapi.testclient import TestClient
from sqlmodel import Session
from app.models.cases import Case
from tests.cases.utils import (
from tests.v1.cases.utils import (
assert_dicts_equal,
get_case_test_data,
create_test_case,
Expand Down

0 comments on commit 8cf534a

Please sign in to comment.