mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-26 09:16:10 -06:00
9608 fix choices
This commit is contained in:
parent
5b941c9809
commit
be79bb74c2
@ -3,7 +3,7 @@ from drf_spectacular.extensions import (
|
||||
)
|
||||
from drf_spectacular.extensions import OpenApiViewExtension
|
||||
from drf_spectacular.utils import extend_schema
|
||||
from drf_spectacular.plumbing import build_basic_type
|
||||
from drf_spectacular.plumbing import build_basic_type, build_object_type
|
||||
from drf_spectacular.types import OpenApiTypes
|
||||
|
||||
|
||||
@ -12,3 +12,19 @@ class FixTimeZoneSerializerField(OpenApiSerializerFieldExtension):
|
||||
|
||||
def map_serializer_field(self, auto_schema, direction):
|
||||
return build_basic_type(OpenApiTypes.STR)
|
||||
|
||||
|
||||
class ChoiceFieldFix(OpenApiSerializerFieldExtension):
|
||||
target_class = 'netbox.api.fields.ChoiceField'
|
||||
|
||||
def map_serializer_field(self, auto_schema, direction):
|
||||
if direction == 'request':
|
||||
return build_basic_type(OpenApiTypes.STR)
|
||||
|
||||
elif direction == "response":
|
||||
return build_object_type(
|
||||
properties={
|
||||
"value": build_basic_type(OpenApiTypes.STR),
|
||||
"label": build_basic_type(OpenApiTypes.STR),
|
||||
}
|
||||
)
|
||||
|
@ -14,7 +14,6 @@ __all__ = (
|
||||
)
|
||||
|
||||
|
||||
@extend_schema_field(OpenApiTypes.STR)
|
||||
class ChoiceField(serializers.Field):
|
||||
"""
|
||||
Represent a ChoiceField as {'value': <DB value>, 'label': <string>}. Accepts a single value on write.
|
||||
|
Loading…
Reference in New Issue
Block a user