Skip to content

Commit 91a79e5

Browse files
committed
Use oneofschema instead of union library because union waits for an error to throw to pick a schema, and wasn't sending all the properties for subclass
1 parent 33fecba commit 91a79e5

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

api_server/models.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
from itertools import groupby
66
from typing import List, Optional, Union
77

8-
import marshmallow_union
98
from marshmallow import Schema, fields
109
from marshmallow_enum import EnumField
10+
from marshmallow_oneofschema import OneOfSchema
1111

1212

1313
def full_icon_path(path):
@@ -183,7 +183,7 @@ class SocketResponseSchema(JSONSchema):
183183
icon_path = fields.Str()
184184
plug_set_hash = fields.Str()
185185
socket_item_type_hash = fields.Str()
186-
current_plug = marshmallow_union.Union([fields.Nested(PlugResponseSchema), None])
186+
current_plug = fields.Nested(PlugResponseSchema)
187187

188188

189189
class SocketedItem(ABC):
@@ -617,9 +617,7 @@ class AspectSubclassAspectSocket:
617617
class AspectSubclassAspectSocketSchema(JSONSchema):
618618
display_name = fields.Str()
619619
icon_path = fields.Str()
620-
current_aspect: marshmallow_union.Union(
621-
[fields.Nested(AspectSubclassAspectSchema), None]
622-
)
620+
current_aspect: fields.Nested(AspectSubclassAspectSchema)
623621

624622

625623
@dataclass
@@ -645,9 +643,7 @@ class AspectSubclassFragmentSocket:
645643
class AspectSubclassFragmentSocketSchema(JSONSchema):
646644
display_name = fields.Str()
647645
icon_path = fields.Str()
648-
current_fragment: marshmallow_union.Union(
649-
[fields.Nested(AspectSubclassFragmentSchema), None]
650-
)
646+
current_fragment: fields.Nested(AspectSubclassFragmentSchema)
651647

652648

653649
@dataclass
@@ -767,6 +763,13 @@ class AspectSubclassSchema(JSONSchema):
767763
fragments = fields.List(fields.Nested(AspectSubclassFragmentSocketSchema))
768764

769765

766+
class SubclassSchema(OneOfSchema):
767+
type_schemas = {
768+
"TreeStyleSubclass": TreeStyleSubclassSchema,
769+
"AspectSubclass": AspectSubclassSchema,
770+
}
771+
772+
770773
@dataclass
771774
class FullCharacterData:
772775
character: Character
@@ -777,6 +780,4 @@ class FullCharacterData:
777780
class FullCharacterDataSchema(JSONSchema):
778781
character = fields.Nested(CharacterSchema)
779782
armor = fields.List(fields.Nested(ArmorPieceSchema))
780-
subclass = marshmallow_union.Union(
781-
[fields.Nested(TreeStyleSubclassSchema), fields.Nested(AspectSubclassSchema)]
782-
)
783+
subclass = fields.Nested(SubclassSchema)

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Jinja2==3.0.3
1818
MarkupSafe==2.0.1
1919
marshmallow==3.14.1
2020
marshmallow-enum==1.5.1
21-
marshmallow-union==0.1.15.post1
21+
marshmallow-oneofschema==3.0.1
2222
mypy-extensions==0.4.3
2323
oauthlib==3.1.1
2424
pathspec==0.9.0

0 commit comments

Comments
 (0)