Skip to content

Commit 2069662

Browse files
Bugfix/query parameters not serialized (#106)
* Regenerate types and fix query parameters serialization * Remove unused imports * Improve test by checking all passed params * Black formatting Co-authored-by: David Weterings <d.weterings@labdigital.nl>
1 parent 04d9c0a commit 2069662

39 files changed

+231
-205
lines changed

codegen/generate_services.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -631,20 +631,20 @@ def make_serialize_query_params(
631631
schema_name = bases[0].id
632632

633633
# params = self._serialize_params({}, schema)
634-
input_params = {}
634+
input_params = []
635635
for key, param in query_params.items():
636636
if key.startswith("/"):
637637
key = snakeit(param.extra_data["(placeholderParam)"]["paramName"])
638-
input_params[key] = snakeit(key)
638+
input_params.append(snakeit(key))
639639

640640
line = ast.Assign(
641641
targets=[ast.Name(id="params")],
642642
value=ast.Call(
643643
func=ast.Attribute(value=ast.Name(id="self"), attr="_serialize_params"),
644644
args=[
645645
ast.Dict(
646-
keys=[ast.Str(s=val, kind="") for val in input_params.keys()],
647-
values=[ast.Name(id=val) for val in input_params.values()],
646+
keys=[ast.Str(s=val, kind="") for val in input_params],
647+
values=[ast.Name(id=val) for val in input_params],
648648
),
649649
ast.Name(id=schema_name),
650650
],

src/commercetools/_schemas/_cart.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@ class CartDraftSchema(marshmallow.Schema):
215215
missing=None,
216216
data_key="itemShippingAddresses",
217217
)
218+
discount_codes = marshmallow.fields.List(
219+
marshmallow.fields.String(allow_none=True),
220+
missing=None,
221+
data_key="discountCodes",
222+
)
218223

219224
class Meta:
220225
unknown = marshmallow.EXCLUDE
@@ -896,6 +901,9 @@ class LineItemDraftSchema(marshmallow.Schema):
896901
)
897902
sku = marshmallow.fields.String(allow_none=True, missing=None)
898903
quantity = marshmallow.fields.Integer(allow_none=True, missing=None)
904+
added_at = marshmallow.fields.DateTime(
905+
allow_none=True, missing=None, data_key="addedAt"
906+
)
899907
supply_channel = helpers.LazyNestedField(
900908
nested="commercetools._schemas._channel.ChannelResourceIdentifierSchema",
901909
unknown=marshmallow.EXCLUDE,
@@ -996,6 +1004,9 @@ class LineItemSchema(marshmallow.Schema):
9961004
data_key="totalPrice",
9971005
)
9981006
quantity = marshmallow.fields.Integer(allow_none=True)
1007+
added_at = marshmallow.fields.DateTime(
1008+
allow_none=True, missing=None, data_key="addedAt"
1009+
)
9991010
state = helpers.LazyNestedField(
10001011
nested="commercetools._schemas._order.ItemStateSchema",
10011012
unknown=marshmallow.EXCLUDE,

src/commercetools/_schemas/_me.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,9 @@ class MyLineItemDraftSchema(marshmallow.Schema):
540540
product_id = marshmallow.fields.String(allow_none=True, data_key="productId")
541541
variant_id = marshmallow.fields.Integer(allow_none=True, data_key="variantId")
542542
quantity = marshmallow.fields.Integer(allow_none=True)
543+
added_at = marshmallow.fields.DateTime(
544+
allow_none=True, missing=None, data_key="addedAt"
545+
)
543546
supply_channel = helpers.LazyNestedField(
544547
nested="commercetools._schemas._channel.ChannelResourceIdentifierSchema",
545548
unknown=marshmallow.EXCLUDE,
@@ -1168,6 +1171,9 @@ class MyCartAddLineItemActionSchema(MyCartUpdateActionSchema):
11681171
missing=None,
11691172
data_key="shippingDetails",
11701173
)
1174+
added_at = marshmallow.fields.DateTime(
1175+
allow_none=True, missing=None, data_key="addedAt"
1176+
)
11711177

11721178
class Meta:
11731179
unknown = marshmallow.EXCLUDE

src/commercetools/_schemas/_order_edit.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,9 @@ class StagedOrderAddLineItemActionSchema(StagedOrderUpdateActionSchema):
640640
)
641641
sku = marshmallow.fields.String(allow_none=True, missing=None)
642642
quantity = marshmallow.fields.Integer(allow_none=True, missing=None)
643+
added_at = marshmallow.fields.DateTime(
644+
allow_none=True, missing=None, data_key="addedAt"
645+
)
643646
supply_channel = helpers.LazyNestedField(
644647
nested="commercetools._schemas._channel.ChannelResourceIdentifierSchema",
645648
unknown=marshmallow.EXCLUDE,

src/commercetools/services/api_clients.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def query(
5959
"sort": sort,
6060
"limit": limit,
6161
"offset": offset,
62-
"withTotal": with_total,
62+
"with_total": with_total,
6363
"where": where,
6464
"predicate_var": predicate_var,
6565
},

src/commercetools/services/cart_discounts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def query(
7777
"sort": sort,
7878
"limit": limit,
7979
"offset": offset,
80-
"withTotal": with_total,
80+
"with_total": with_total,
8181
"where": where,
8282
"predicate_var": predicate_var,
8383
},

src/commercetools/services/carts.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ def query(
9595
"sort": sort,
9696
"limit": limit,
9797
"offset": offset,
98-
"withTotal": with_total,
98+
"with_total": with_total,
9999
"where": where,
100100
"predicate_var": predicate_var,
101-
"customerId": customer_id,
101+
"customer_id": customer_id,
102102
},
103103
_CartQuerySchema,
104104
)
@@ -152,7 +152,7 @@ def delete_by_id(
152152
force_delete: bool = False,
153153
) -> Cart:
154154
params = self._serialize_params(
155-
{"version": version, "expand": expand, "dataErasure": data_erasure},
155+
{"version": version, "expand": expand, "data_erasure": data_erasure},
156156
_CartDeleteSchema,
157157
)
158158
return self._client._delete(

src/commercetools/services/categories.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def query(
7171
"sort": sort,
7272
"limit": limit,
7373
"offset": offset,
74-
"withTotal": with_total,
74+
"with_total": with_total,
7575
"where": where,
7676
"predicate_var": predicate_var,
7777
},

src/commercetools/services/channels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def query(
6969
"sort": sort,
7070
"limit": limit,
7171
"offset": offset,
72-
"withTotal": with_total,
72+
"with_total": with_total,
7373
"where": where,
7474
"predicate_var": predicate_var,
7575
},

src/commercetools/services/custom_objects.py

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,31 @@ class _CustomObjectQuerySchema(
2929

3030

3131
class _CustomObjectDeleteSchema(
32-
traits.VersionedSchema, traits.ExpandableSchema, traits.DataErasureSchema
32+
traits.DataErasureSchema, traits.VersionedSchema, traits.ExpandableSchema
3333
):
3434
version = OptionalList(fields.String(), required=False)
3535

3636

3737
class CustomObjectService(abstract.AbstractService):
3838
"""Store custom JSON values."""
3939

40-
def get_by_container_and_key(
41-
self, container, key, *, expand: OptionalListStr = None
40+
def get_by_container(
41+
self, container: str, *, expand: OptionalListStr = None
4242
) -> CustomObject:
43-
"""Get CustomObject by container and key"""
4443
params = self._serialize_params({"expand": expand}, traits.ExpandableSchema)
4544
return self._client._get(
46-
endpoint=f"custom-objects/{container}/{key}",
45+
endpoint=f"custom-objects/{container}",
4746
params=params,
4847
schema_cls=CustomObjectSchema,
4948
)
5049

51-
def get_by_id(self, id: str, *, expand: OptionalListStr = None) -> CustomObject:
50+
def get_by_container_and_key(
51+
self, container, key, *, expand: OptionalListStr = None
52+
) -> CustomObject:
53+
"""Get CustomObject by container and key"""
5254
params = self._serialize_params({"expand": expand}, traits.ExpandableSchema)
5355
return self._client._get(
54-
endpoint=f"custom-objects/{id}",
56+
endpoint=f"custom-objects/{container}/{key}",
5557
params=params,
5658
schema_cls=CustomObjectSchema,
5759
)
@@ -80,7 +82,7 @@ def query(
8082
"sort": sort,
8183
"limit": limit,
8284
"offset": offset,
83-
"withTotal": with_total,
85+
"with_total": with_total,
8486
"where": where,
8587
"predicate_var": predicate_var,
8688
},
@@ -148,7 +150,7 @@ def delete_by_container_and_key(
148150
) -> CustomObject:
149151
"""Delete CustomObject by container and key"""
150152
params = self._serialize_params(
151-
{"dataErasure": data_erasure, "version": version, "expand": expand},
153+
{"data_erasure": data_erasure, "version": version, "expand": expand},
152154
_CustomObjectDeleteSchema,
153155
)
154156
return self._client._delete(
@@ -157,28 +159,3 @@ def delete_by_container_and_key(
157159
response_schema_cls=CustomObjectSchema,
158160
force_delete=force_delete,
159161
)
160-
161-
def delete_by_id(
162-
self,
163-
id: str,
164-
*,
165-
version: str = None,
166-
expand: OptionalListStr = None,
167-
data_erasure: bool = None,
168-
force_delete: bool = False,
169-
) -> CustomObject:
170-
"""The version control is optional.
171-
172-
If the query contains a version, then it must match the version of the
173-
object.
174-
"""
175-
params = self._serialize_params(
176-
{"version": version, "expand": expand, "dataErasure": data_erasure},
177-
_CustomObjectDeleteSchema,
178-
)
179-
return self._client._delete(
180-
endpoint=f"custom-objects/{id}",
181-
params=params,
182-
response_schema_cls=CustomObjectSchema,
183-
force_delete=force_delete,
184-
)

0 commit comments

Comments
 (0)