File tree 2 files changed +32
-1
lines changed
2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ class Config:
16
16
bulk_size : int = 20
17
17
18
18
19
- Config .Schema = class_schema (Config )
19
+ Config .Schema = class_schema (Config ) # <--------------
20
20
21
21
json_data = {
22
22
'file_path' : '/validators-example/file' ,
Original file line number Diff line number Diff line change
1
+ from dataclasses import dataclass , field
2
+ from enum import Enum
3
+
4
+ from marshmallow_dataclass import add_schema
5
+
6
+
7
+ class Command (Enum ):
8
+ CREATE = 'create'
9
+ DELETE = 'delete'
10
+
11
+
12
+ @add_schema # <--------------
13
+ @dataclass
14
+ class Config :
15
+ file_path : str
16
+ command : Command = field (metadata = dict (by_value = True ))
17
+ bulk_size : int = 20
18
+
19
+
20
+ json_data = {
21
+ 'file_path' : '/validators-example/file' ,
22
+ 'command' : 'create' ,
23
+ }
24
+
25
+ config = Config .Schema ().load (json_data )
26
+ print (config )
27
+ print (Config .Schema ().dump (config ))
28
+
29
+ assert config .file_path == '/validators-example/file'
30
+ assert config .command is Command .CREATE
31
+ assert config .bulk_size == 20
You can’t perform that action at this time.
0 commit comments