mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 23:55:58 -05:00
Keep behaviour of deserializing unknown keys
Keep the marshmallow 2 behaviour of dropping unknown keys https://marshmallow.readthedocs.io/en/stable/upgrading.html#schemas-raise-validationerror-when-deserializing-data-with-unknown-keys The new default is to raise an error for unknown keys. This also adds the optional fields that the `EmailDataSchema` can have to the schema - `next` and `admin_base_url`.
This commit is contained in:
@@ -3,6 +3,7 @@ from uuid import UUID
|
|||||||
|
|
||||||
from flask_marshmallow.fields import fields
|
from flask_marshmallow.fields import fields
|
||||||
from marshmallow import (
|
from marshmallow import (
|
||||||
|
EXCLUDE,
|
||||||
ValidationError,
|
ValidationError,
|
||||||
post_dump,
|
post_dump,
|
||||||
post_load,
|
post_load,
|
||||||
@@ -65,6 +66,7 @@ class BaseSchema(ma.SQLAlchemyAutoSchema):
|
|||||||
class Meta:
|
class Meta:
|
||||||
load_instance = True
|
load_instance = True
|
||||||
include_relationships = True
|
include_relationships = True
|
||||||
|
unknown = EXCLUDE
|
||||||
|
|
||||||
def __init__(self, load_json=False, *args, **kwargs):
|
def __init__(self, load_json=False, *args, **kwargs):
|
||||||
self.load_json = load_json
|
self.load_json = load_json
|
||||||
@@ -449,6 +451,9 @@ class JobSchema(BaseSchema):
|
|||||||
|
|
||||||
|
|
||||||
class NotificationSchema(ma.Schema):
|
class NotificationSchema(ma.Schema):
|
||||||
|
class Meta:
|
||||||
|
unknown = EXCLUDE
|
||||||
|
|
||||||
status = fields.String(required=False)
|
status = fields.String(required=False)
|
||||||
personalisation = fields.Dict(required=False)
|
personalisation = fields.Dict(required=False)
|
||||||
|
|
||||||
@@ -593,7 +598,12 @@ class InvitedUserSchema(BaseSchema):
|
|||||||
|
|
||||||
|
|
||||||
class EmailDataSchema(ma.Schema):
|
class EmailDataSchema(ma.Schema):
|
||||||
|
class Meta:
|
||||||
|
unknown = EXCLUDE
|
||||||
|
|
||||||
email = fields.Str(required=True)
|
email = fields.Str(required=True)
|
||||||
|
next = fields.Str(required=False)
|
||||||
|
admin_base_url = fields.Str(required=False)
|
||||||
|
|
||||||
def __init__(self, partial_email=False):
|
def __init__(self, partial_email=False):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
@@ -610,6 +620,9 @@ class EmailDataSchema(ma.Schema):
|
|||||||
|
|
||||||
|
|
||||||
class NotificationsFilterSchema(ma.Schema):
|
class NotificationsFilterSchema(ma.Schema):
|
||||||
|
class Meta:
|
||||||
|
unknown = EXCLUDE
|
||||||
|
|
||||||
template_type = fields.Nested(BaseTemplateSchema, only=['template_type'], many=True)
|
template_type = fields.Nested(BaseTemplateSchema, only=['template_type'], many=True)
|
||||||
status = fields.Nested(NotificationModelSchema, only=['status'], many=True)
|
status = fields.Nested(NotificationModelSchema, only=['status'], many=True)
|
||||||
page = fields.Int(required=False)
|
page = fields.Int(required=False)
|
||||||
@@ -652,6 +665,9 @@ class NotificationsFilterSchema(ma.Schema):
|
|||||||
|
|
||||||
|
|
||||||
class ServiceHistorySchema(ma.Schema):
|
class ServiceHistorySchema(ma.Schema):
|
||||||
|
class Meta:
|
||||||
|
unknown = EXCLUDE
|
||||||
|
|
||||||
id = fields.UUID()
|
id = fields.UUID()
|
||||||
name = fields.String()
|
name = fields.String()
|
||||||
created_at = fields.DateTime()
|
created_at = fields.DateTime()
|
||||||
@@ -665,6 +681,9 @@ class ServiceHistorySchema(ma.Schema):
|
|||||||
|
|
||||||
|
|
||||||
class ApiKeyHistorySchema(ma.Schema):
|
class ApiKeyHistorySchema(ma.Schema):
|
||||||
|
class Meta:
|
||||||
|
unknown = EXCLUDE
|
||||||
|
|
||||||
id = fields.UUID()
|
id = fields.UUID()
|
||||||
name = fields.String()
|
name = fields.String()
|
||||||
service_id = fields.UUID()
|
service_id = fields.UUID()
|
||||||
|
|||||||
Reference in New Issue
Block a user