mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
fixes choice field schema for response #12960
This commit is contained in:
committed by
Jeremy Stretch
parent
7f96c7fee7
commit
49af70a77d
@ -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
|
||||
}
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user