From d5003b1f0a8fa4b481973fb817899ade4abe463c Mon Sep 17 00:00:00 2001 From: Alexander Loechel Date: Thu, 18 Apr 2024 10:08:11 +0200 Subject: [PATCH] Pydantic Config --- src/edutap/wallet_google/modelbase.py | 6 ++++++ src/edutap/wallet_google/models/primitives/enums.py | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/edutap/wallet_google/modelbase.py b/src/edutap/wallet_google/modelbase.py index 64f2c8e..c464e3f 100644 --- a/src/edutap/wallet_google/modelbase.py +++ b/src/edutap/wallet_google/modelbase.py @@ -1,4 +1,5 @@ from pydantic import BaseModel +from pydantic import ConfigDict class GoogleWalletModel(BaseModel): @@ -6,6 +7,11 @@ class GoogleWalletModel(BaseModel): Base model for all Google Wallet models. """ + model_config = ConfigDict( + extra="forbid", + use_enum_values=True, + ) + class GoogleWalletWithIdModel(GoogleWalletModel): """ diff --git a/src/edutap/wallet_google/models/primitives/enums.py b/src/edutap/wallet_google/models/primitives/enums.py index a1d33a2..9815400 100644 --- a/src/edutap/wallet_google/models/primitives/enums.py +++ b/src/edutap/wallet_google/models/primitives/enums.py @@ -22,11 +22,11 @@ def __new__(cls: type["CamelCaseAliasEnum"], value: str) -> "CamelCaseAliasEnum" camel = "".join( [(x.capitalize() if count != 0 else x) for count, x in enumerate(parts)] ) - + # create a second object with the camelcase name # creating an alias only does not work out since # pydantic checks for the value in the enum and not only the name - camel_obj= object.__new__(cls) + camel_obj = object.__new__(cls) camel_obj._value_ = camel cls._value2member_map_[camel] = camel_obj cls._member_map_[camel] = camel_obj