Skip to content

Commit 330a169

Browse files
fix: schema for update order response
1 parent 01a0682 commit 330a169

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

api/oas_schemas.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22

33
from decouple import config
44
from django.conf import settings
5-
from drf_spectacular.utils import OpenApiExample, OpenApiParameter
5+
from drf_spectacular.utils import (
6+
OpenApiExample,
7+
OpenApiParameter,
8+
PolymorphicProxySerializer,
9+
)
610

711
from api.serializers import (
12+
CancelledOrderResponseSerializer,
813
InfoSerializer,
914
ListOrderSerializer,
1015
OrderDetailSerializer,
@@ -353,7 +358,15 @@ class OrderViewSchema:
353358
),
354359
],
355360
"responses": {
356-
200: OrderDetailSerializer,
361+
200: PolymorphicProxySerializer(
362+
component_name="UpdateOrderResponse",
363+
serializers=[
364+
CancelledOrderResponseSerializer,
365+
OrderDetailSerializer,
366+
],
367+
resource_type_field_name=None,
368+
many=False,
369+
),
357370
400: {
358371
"type": "object",
359372
"properties": {

api/serializers.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,13 @@ class Meta:
500500
)
501501

502502

503+
# Only used in oas_schemas
504+
class CancelledOrderResponseSerializer(serializers.Serializer):
505+
id = serializers.IntegerField(help_text="Order id")
506+
status = serializers.IntegerField(help_text="Order status")
507+
bad_request = serializers.CharField(help_text="Reason for the failure")
508+
509+
503510
class ListNotificationSerializer(serializers.ModelSerializer):
504511
status = serializers.SerializerMethodField(
505512
help_text="The `status` of the order when the notification was trigered",

docs/assets/schemas/api-latest.yaml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ paths:
619619
content:
620620
application/json:
621621
schema:
622-
$ref: '#/components/schemas/OrderDetail'
622+
$ref: '#/components/schemas/UpdateOrderResponse'
623623
description: ''
624624
'400':
625625
content:
@@ -1032,6 +1032,22 @@ components:
10321032
BlankEnum:
10331033
enum:
10341034
- ''
1035+
CancelledOrderResponse:
1036+
type: object
1037+
properties:
1038+
id:
1039+
type: integer
1040+
description: Order id
1041+
status:
1042+
type: integer
1043+
description: Order status
1044+
bad_request:
1045+
type: string
1046+
description: Reason for the failure
1047+
required:
1048+
- bad_request
1049+
- id
1050+
- status
10351051
Chat:
10361052
type: object
10371053
properties:
@@ -2117,6 +2133,10 @@ components:
21172133
- $ref: '#/components/schemas/NullEnum'
21182134
required:
21192135
- action
2136+
UpdateOrderResponse:
2137+
oneOf:
2138+
- $ref: '#/components/schemas/CancelledOrderResponse'
2139+
- $ref: '#/components/schemas/OrderDetail'
21202140
Version:
21212141
type: object
21222142
properties:

0 commit comments

Comments
 (0)