فهرست منبع

fixes choice field schema for response #12960

Abhimanyu Saharan 2 سال پیش
والد
کامیت
49af70a77d
1فایلهای تغییر یافته به همراه9 افزوده شده و 3 حذف شده
  1. 9 3
      netbox/core/api/schema.py

+ 9 - 3
netbox/core/api/schema.py

@@ -1,5 +1,6 @@
 import re
 import typing
+from collections import OrderedDict
 
 from drf_spectacular.extensions import OpenApiSerializerFieldExtension
 from drf_spectacular.openapi import AutoSchema
@@ -28,14 +29,19 @@ class ChoiceFieldFix(OpenApiSerializerFieldExtension):
     target_class = 'netbox.api.fields.ChoiceField'
 
     def map_serializer_field(self, auto_schema, direction):
+        build_cf = build_choice_field(self.target)
+
         if direction == 'request':
-            return build_choice_field(self.target)
+            return build_cf
 
         elif direction == "response":
+            value = build_cf
+            label = {**build_basic_type(OpenApiTypes.STR), "enum": list(OrderedDict.fromkeys(self.target.choices.values()))}
+
             return build_object_type(
                 properties={
-                    "value": build_basic_type(OpenApiTypes.STR),
-                    "label": build_basic_type(OpenApiTypes.STR),
+                    "value": value,
+                    "label": label
                 }
             )