-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Generic schemas module for abstracting schema lib
- Loading branch information
Showing
15 changed files
with
150 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import importlib.util | ||
import sys | ||
|
||
_SCHEMA_LIBS = ("marshmallow",) | ||
_INSTALLED = [x for x in _SCHEMA_LIBS if x in sys.modules or importlib.util.find_spec(x) is not None] | ||
_LIB = None | ||
|
||
|
||
for lib in _INSTALLED: | ||
try: | ||
_LIB = importlib.import_module(f"flama.schemas.{lib}") | ||
break | ||
except ModuleNotFoundError: | ||
pass | ||
|
||
|
||
# Check that at least one of the schema libs is installed | ||
assert _LIB is not None, f"Any of the schema libraries ({', '.join(_SCHEMA_LIBS)}) must be installed." | ||
|
||
lib = _LIB.lib | ||
fields = _LIB.fields | ||
Schema = _LIB.Schema | ||
core = _LIB.core | ||
|
||
__all__ = ["Schema", "fields", "lib", "core"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import marshmallow | ||
from marshmallow import Schema, fields | ||
|
||
from flama.schemas.marshmallow import core | ||
|
||
lib = marshmallow | ||
|
||
__all__ = ["Schema", "fields", "lib", "core"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import marshmallow | ||
|
||
|
||
class APIError(marshmallow.Schema): | ||
status_code = marshmallow.fields.Integer(title="status_code", description="HTTP status code", required=True) | ||
detail = marshmallow.fields.Raw(title="detail", description="Error detail", required=True) | ||
error = marshmallow.fields.String(title="type", description="Exception or error type") | ||
|
||
|
||
class DropCollection(marshmallow.Schema): | ||
deleted = marshmallow.fields.Integer(title="deleted", description="Number of deleted elements", required=True) | ||
|
||
|
||
class LimitOffsetMeta(marshmallow.Schema): | ||
limit = marshmallow.fields.Integer(title="limit", description="Number of retrieved items") | ||
offset = marshmallow.fields.Integer(title="offset", description="Collection offset") | ||
count = marshmallow.fields.Integer(title="count", description="Total number of items", allow_none=True) | ||
|
||
|
||
class LimitOffsetSchema(marshmallow.Schema): | ||
meta = marshmallow.fields.Nested(LimitOffsetMeta) | ||
data = marshmallow.fields.List(marshmallow.fields.Dict()) | ||
|
||
|
||
class PageNumberMeta(marshmallow.Schema): | ||
page = marshmallow.fields.Integer(title="page", description="Current page number") | ||
page_size = marshmallow.fields.Integer(title="page_size", description="Page size") | ||
count = marshmallow.fields.Integer(title="count", description="Total number of items", allow_none=True) | ||
|
||
|
||
class PageNumberSchema(marshmallow.Schema): | ||
meta = marshmallow.fields.Nested(PageNumberMeta) | ||
data = marshmallow.fields.List(marshmallow.fields.Dict()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import os.path | ||
|
||
PATH = os.path.dirname(os.path.abspath(__file__)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.