Compare commits

..

2 commits
0.6.1 ... main

Author SHA1 Message Date
Brian Wiborg
b5691f3133
🔖 0.6.2 2025-11-05 21:37:34 +01:00
Brian Wiborg
5f80a7a86f
🐛 Fix model-free apps and middleware installer 2025-11-05 21:29:25 +01:00
4 changed files with 18 additions and 13 deletions

View file

@ -1,6 +1,6 @@
[project]
name = "ohmyapi"
version = "0.6.1"
version = "0.6.2"
description = "Django-flavored scaffolding and management layer around FastAPI, Pydantic, TortoiseORM and Aerich migrations"
license = "MIT"
keywords = ["fastapi", "tortoise", "orm", "pydantic", "async", "web-framework"]

View file

@ -1 +1 @@
__VERSION__ = "0.6.1"
__VERSION__ = "0.6.2"

View file

@ -342,9 +342,9 @@ class App:
except ModuleNotFoundError:
return
getter = getattr(mod, "get", None)
if getter is not None:
for middleware in getter():
installer = getattr(mod, "install", None)
if installer is not None:
for middleware in installer():
self._middlewares.append(middleware)
def __serialize_route(self, route):
@ -404,10 +404,15 @@ class App:
"""
Convenience method for serializing the runtime data.
"""
# An app may come without any models
models = []
if f"{self.name}.models" in self._models:
models = [
f"{self.name}.{m.__name__}"
for m in self._models[f"{self.name}.models"]
]
return {
"models": [
f"{self.name}.{m.__name__}" for m in self._models[f"{self.name}.models"]
],
"models": models,
"middlewares": self.__serialize_middleware(),
"routes": self.__serialize_router(),
}

View file

@ -15,12 +15,12 @@ CORS_CONFIG: Dict[str, Any] = getattr(settings, "MIDDLEWARE_CORS", {})
if not isinstance(CORS_CONFIG, dict):
raise ValueError("MIDDLEWARE_CORS must be of type dict")
middleware = [
(CORSMiddleware, {
middleware = (
CORSMiddleware,
{
"allow_origins": CORS_CONFIG.get("ALLOW_ORIGINS", DEFAULT_ORIGINS),
"allow_credentials": CORS_CONFIG.get("ALLOW_CREDENTIALS", DEFAULT_CREDENTIALS),
"allow_methods": CORS_CONFIG.get("ALLOW_METHODS", DEFAULT_METHODS),
"allow_headers": CORS_CONFIG.get("ALLOW_HEADERS", DEFAULT_HEADERS),
}),
]
}
)