|
|
@@ -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
|
|
|
}
|
|
|
)
|
|
|
|