Skip to content

Commit e4046d6

Browse files
committed
Convert fields in API response to camelCase
1 parent 7037aa1 commit e4046d6

File tree

15 files changed

+415
-25
lines changed

15 files changed

+415
-25
lines changed

Pipfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ url = "https://pypi.org/simple"
44
verify_ssl = true
55

66
[dev-packages]
7-
7+
pytest = "*"
88

99
[packages]
1010
flask = "*"

Pipfile.lock

Lines changed: 97 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

snowflake/app.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import json
22

3-
from dotenv import load_dotenv
43
from flask import Flask, url_for
54

65
from . import filters, settings, logger
@@ -11,7 +10,6 @@
1110
from .services import login_manager
1211
from .services.session_interface import CustomSessionInterface
1312

14-
load_dotenv()
1513
logger.setup()
1614

1715
app = Flask(__name__)

snowflake/schemas/base.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from ..marshmallow import marshmallow
2+
3+
4+
def camelcase(s):
5+
parts = iter(s.split("_"))
6+
return next(parts) + "".join(i.title() for i in parts)
7+
8+
9+
class BaseSchema(marshmallow.Schema):
10+
# noinspection PyMethodMayBeStatic
11+
def on_bind_field(self, field_name, field_obj):
12+
field_obj.data_key = camelcase(field_obj.data_key or field_name)
13+
14+
15+
class BaseSQLAlchemySchema(marshmallow.SQLAlchemySchema, BaseSchema):
16+
pass
17+
18+
19+
class BaseSQLAlchemyAutoSchema(marshmallow.SQLAlchemyAutoSchema, BaseSchema):
20+
pass

snowflake/schemas/login.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
from marshmallow.fields import String, DateTime, Nested
22

3+
from .base import BaseSchema
34
from .user import UserSchema
4-
from ..marshmallow import marshmallow
55

66

7-
class LoginSchema(marshmallow.Schema):
7+
class LoginSchema(BaseSchema):
88
token = String()
99

1010

11-
class LoginResponseSchema(marshmallow.Schema):
11+
class LoginResponseSchema(BaseSchema):
1212
token = String()
1313
expiry = DateTime()
1414
refresh_token = String()

snowflake/schemas/notification.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
from marshmallow_sqlalchemy.fields import Nested
2-
3-
from .user import UserSchema
4-
from ..marshmallow import marshmallow
1+
from .base import BaseSQLAlchemyAutoSchema
52
from ..models import Notification
63

74

8-
class NotificationSchema(marshmallow.SQLAlchemyAutoSchema):
5+
class NotificationSchema(BaseSQLAlchemyAutoSchema):
96
class Meta:
107
model = Notification
11-
12-
user = Nested(UserSchema)

snowflake/schemas/one_on_one.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
from marshmallow.fields import List
22
from marshmallow_sqlalchemy.fields import Nested
33

4+
from .base import BaseSQLAlchemySchema
45
from .fields import UserByUsername
56
from .user import UserSchema
67
from ..marshmallow import marshmallow
78
from ..models import OneOnOne, OneOnOneActionItem
89

910

10-
class OneOnOneActionItemSchema(marshmallow.SQLAlchemySchema):
11+
class OneOnOneActionItemSchema(BaseSQLAlchemySchema):
1112
class Meta:
1213
model = OneOnOneActionItem
1314

@@ -18,7 +19,7 @@ class Meta:
1819
created_by = Nested(UserSchema)
1920

2021

21-
class CreateOrEditOneOnOneActionItemSchema(marshmallow.SQLAlchemySchema):
22+
class CreateOrEditOneOnOneActionItemSchema(BaseSQLAlchemySchema):
2223
class Meta:
2324
model = OneOnOneActionItem
2425
load_instance = True
@@ -27,7 +28,7 @@ class Meta:
2728
content = marshmallow.auto_field()
2829

2930

30-
class OneOnOneSchema(marshmallow.SQLAlchemySchema):
31+
class OneOnOneSchema(BaseSQLAlchemySchema):
3132
class Meta:
3233
model = OneOnOne
3334

@@ -41,7 +42,7 @@ class GetOneOnOneSchema(OneOnOneSchema):
4142
action_items = List(Nested(OneOnOneActionItemSchema))
4243

4344

44-
class CreateOneOnOneSchema(marshmallow.SQLAlchemySchema):
45+
class CreateOneOnOneSchema(BaseSQLAlchemySchema):
4546
class Meta:
4647
model = OneOnOne
4748
load_instance = True

snowflake/schemas/user.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from ..marshmallow import marshmallow
1+
from .base import BaseSQLAlchemyAutoSchema
22
from ..models import User
33

44

5-
class UserSchema(marshmallow.SQLAlchemyAutoSchema):
5+
class UserSchema(BaseSQLAlchemyAutoSchema):
66
class Meta:
77
model = User
88
exclude = ("id",)

snowflake/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import os
22

33
import requests
4+
from dotenv import load_dotenv
45
from flask import Flask
56

7+
load_dotenv()
8+
69
GOOGLE_DISCOVERY_URL = "https://accounts.google.com/.well-known/openid-configuration"
710
REDIS_URL = os.getenv('REDIS_URL')
811
TOKEN_VALIDITY_SECS = int(os.getenv('TOKEN_VALIDITY_SECS'))

tests/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)