File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change 11import re
22import typing
3+ from collections import OrderedDict
34
45from drf_spectacular .extensions import OpenApiSerializerFieldExtension
56from drf_spectacular .openapi import AutoSchema
@@ -28,14 +29,19 @@ class ChoiceFieldFix(OpenApiSerializerFieldExtension):
2829 target_class = 'netbox.api.fields.ChoiceField'
2930
3031 def map_serializer_field (self , auto_schema , direction ):
32+ build_cf = build_choice_field (self .target )
33+
3134 if direction == 'request' :
32- return build_choice_field ( self . target )
35+ return build_cf
3336
3437 elif direction == "response" :
38+ value = build_cf
39+ label = {** build_basic_type (OpenApiTypes .STR ), "enum" : list (OrderedDict .fromkeys (self .target .choices .values ()))}
40+
3541 return build_object_type (
3642 properties = {
37- "value" : build_basic_type ( OpenApiTypes . STR ) ,
38- "label" : build_basic_type ( OpenApiTypes . STR ),
43+ "value" : value ,
44+ "label" : label
3945 }
4046 )
4147
You can’t perform that action at this time.
0 commit comments