We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
IP Prefix Family returned doesn't match swagger definition
### Environment
* Python version:   3.7.6
* NetBox version:  v2.7.7

Swagger definition for Prefix.Family does not match the swagger definition.

### Steps to Reproduce
1. Get a prefix object `wget http://netbox/api/ipam/prefixes/210/`
2. Notice object is like
```
  "family": {
    "value": 4,
    "label": "IPv4"
  },
```
3. Notice definition is
```
  "family": {
    "label": "string",
    "value": "string"
  },
```


<!-- What did you expect to happen? -->
### Expected Behavior
Object returned matches definition. I'm not sure if the definition needs to be fixed or the returned value type needs to be changed.

<!-- What happened instead? -->
### Observed Behavior
Object doesn't match definition

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `netbox/utilities/custom_inspectors.py`
Content:
```
1 from drf_yasg import openapi
2 from drf_yasg.inspectors import FieldInspector, NotHandled, PaginatorInspector, FilterInspector, SwaggerAutoSchema
3 from drf_yasg.utils import get_serializer_ref_name
4 from rest_framework.fields import ChoiceField
5 from rest_framework.relations import ManyRelatedField
6 from taggit_serializer.serializers import TagListSerializerField
7 
8 from dcim.api.serializers import InterfaceSerializer as DeviceInterfaceSerializer
9 from extras.api.customfields import CustomFieldsSerializer
10 from utilities.api import ChoiceField, SerializedPKRelatedField, WritableNestedSerializer
11 from virtualization.api.serializers import InterfaceSerializer as VirtualMachineInterfaceSerializer
12 
13 # this might be ugly, but it limits drf_yasg-specific code to this file
14 DeviceInterfaceSerializer.Meta.ref_name = 'DeviceInterface'
15 VirtualMachineInterfaceSerializer.Meta.ref_name = 'VirtualMachineInterface'
16 
17 
18 class NetBoxSwaggerAutoSchema(SwaggerAutoSchema):
19     writable_serializers = {}
20 
21     def get_request_serializer(self):
22         serializer = super().get_request_serializer()
23 
24         if serializer is not None and self.method in self.implicit_body_methods:
25             properties = {}
26             for child_name, child in serializer.fields.items():
27                 if isinstance(child, (ChoiceField, WritableNestedSerializer)):
28                     properties[child_name] = None
29                 elif isinstance(child, ManyRelatedField) and isinstance(child.child_relation, SerializedPKRelatedField):
30                     properties[child_name] = None
31 
32             if properties:
33                 if type(serializer) not in self.writable_serializers:
34                     writable_name = 'Writable' + type(serializer).__name__
35                     meta_class = getattr(type(serializer), 'Meta', None)
36                     if meta_class:
37                         ref_name = 'Writable' + get_serializer_ref_name(serializer)
38                         writable_meta = type('Meta', (meta_class,), {'ref_name': ref_name})
39                         properties['Meta'] = writable_meta
40 
41                     self.writable_serializers[type(serializer)] = type(writable_name, (type(serializer),), properties)
42 
43                 writable_class = self.writable_serializers[type(serializer)]
44                 serializer = writable_class()
45 
46         return serializer
47 
48 
49 class SerializedPKRelatedFieldInspector(FieldInspector):
50     def field_to_swagger_object(self, field, swagger_object_type, use_references, **kwargs):
51         SwaggerType, ChildSwaggerType = self._get_partial_types(field, swagger_object_type, use_references, **kwargs)
52         if isinstance(field, SerializedPKRelatedField):
53             return self.probe_field_inspectors(field.serializer(), ChildSwaggerType, use_references)
54 
55         return NotHandled
56 
57 
58 class TagListFieldInspector(FieldInspector):
59     def field_to_swagger_object(self, field, swagger_object_type, use_references, **kwargs):
60         SwaggerType, ChildSwaggerType = self._get_partial_types(field, swagger_object_type, use_references, **kwargs)
61         if isinstance(field, TagListSerializerField):
62             child_schema = self.probe_field_inspectors(field.child, ChildSwaggerType, use_references)
63             return SwaggerType(
64                 type=openapi.TYPE_ARRAY,
65                 items=child_schema,
66             )
67 
68         return NotHandled
69 
70 
71 class CustomChoiceFieldInspector(FieldInspector):
72     def field_to_swagger_object(self, field, swagger_object_type, use_references, **kwargs):
73         # this returns a callable which extracts title, description and other stuff
74         # https://drf-yasg.readthedocs.io/en/stable/_modules/drf_yasg/inspectors/base.html#FieldInspector._get_partial_types
75         SwaggerType, _ = self._get_partial_types(field, swagger_object_type, use_references, **kwargs)
76 
77         if isinstance(field, ChoiceField):
78             value_schema = openapi.Schema(type=openapi.TYPE_STRING)
79 
80             choices = list(field._choices.keys())
81             if set([None] + choices) == {None, True, False}:
82                 # DeviceType.subdevice_role, Device.face and InterfaceConnection.connection_status all need to be
83                 # differentiated since they each have subtly different values in their choice keys.
84                 # - subdevice_role and connection_status are booleans, although subdevice_role includes None
85                 # - face is an integer set {0, 1} which is easily confused with {False, True}
86                 schema_type = openapi.TYPE_STRING
87                 if all(type(x) == bool for x in [c for c in choices if c is not None]):
88                     schema_type = openapi.TYPE_BOOLEAN
89                 value_schema = openapi.Schema(type=schema_type)
90                 value_schema['x-nullable'] = True
91 
92             schema = SwaggerType(type=openapi.TYPE_OBJECT, required=["label", "value"], properties={
93                 "label": openapi.Schema(type=openapi.TYPE_STRING),
94                 "value": value_schema
95             })
96 
97             return schema
98 
99         elif isinstance(field, CustomFieldsSerializer):
100             schema = SwaggerType(type=openapi.TYPE_OBJECT)
101             return schema
102 
103         return NotHandled
104 
105 
106 class NullableBooleanFieldInspector(FieldInspector):
107     def process_result(self, result, method_name, obj, **kwargs):
108 
109         if isinstance(result, openapi.Schema) and isinstance(obj, ChoiceField) and result.type == 'boolean':
110             keys = obj.choices.keys()
111             if set(keys) == {None, True, False}:
112                 result['x-nullable'] = True
113                 result.type = 'boolean'
114 
115         return result
116 
117 
118 class IdInFilterInspector(FilterInspector):
119     def process_result(self, result, method_name, obj, **kwargs):
120         if isinstance(result, list):
121             params = [p for p in result if isinstance(p, openapi.Parameter) and p.name == 'id__in']
122             for p in params:
123                 p.type = 'string'
124 
125         return result
126 
127 
128 class NullablePaginatorInspector(PaginatorInspector):
129     def process_result(self, result, method_name, obj, **kwargs):
130         if method_name == 'get_paginated_response' and isinstance(result, openapi.Schema):
131             next = result.properties['next']
132             if isinstance(next, openapi.Schema):
133                 next['x-nullable'] = True
134             previous = result.properties['previous']
135             if isinstance(previous, openapi.Schema):
136                 previous['x-nullable'] = True
137 
138         return result
139
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/netbox/utilities/custom_inspectors.py b/netbox/utilities/custom_inspectors.py
--- a/netbox/utilities/custom_inspectors.py
+++ b/netbox/utilities/custom_inspectors.py
@@ -89,6 +89,10 @@
                 value_schema = openapi.Schema(type=schema_type)
                 value_schema['x-nullable'] = True
 
+            if isinstance(choices[0], int):
+                # Change value_schema for IPAddressFamilyChoices, RackWidthChoices
+                value_schema = openapi.Schema(type=openapi.TYPE_INTEGER)
+
             schema = SwaggerType(type=openapi.TYPE_OBJECT, required=["label", "value"], properties={
                 "label": openapi.Schema(type=openapi.TYPE_STRING),
                 "value": value_schema

{"golden_diff": "diff --git a/netbox/utilities/custom_inspectors.py b/netbox/utilities/custom_inspectors.py\n--- a/netbox/utilities/custom_inspectors.py\n+++ b/netbox/utilities/custom_inspectors.py\n@@ -89,6 +89,10 @@\n                 value_schema = openapi.Schema(type=schema_type)\n                 value_schema['x-nullable'] = True\n \n+            if isinstance(choices[0], int):\n+                # Change value_schema for IPAddressFamilyChoices, RackWidthChoices\n+                value_schema = openapi.Schema(type=openapi.TYPE_INTEGER)\n+\n             schema = SwaggerType(type=openapi.TYPE_OBJECT, required=[\"label\", \"value\"], properties={\n                 \"label\": openapi.Schema(type=openapi.TYPE_STRING),\n                 \"value\": value_schema\n", "issue": "IP Prefix Family returned doesn't match swagger definition\n### Environment\r\n* Python version:   3.7.6\r\n* NetBox version:  v2.7.7\r\n\r\nSwagger definition for Prefix.Family does not match the swagger definition.\r\n\r\n### Steps to Reproduce\r\n1. Get a prefix object `wget http://netbox/api/ipam/prefixes/210/`\r\n2. Notice object is like\r\n```\r\n  \"family\": {\r\n    \"value\": 4,\r\n    \"label\": \"IPv4\"\r\n  },\r\n```\r\n3. Notice definition is\r\n```\r\n  \"family\": {\r\n    \"label\": \"string\",\r\n    \"value\": \"string\"\r\n  },\r\n```\r\n\r\n\r\n<!-- What did you expect to happen? -->\r\n### Expected Behavior\r\nObject returned matches definition. I'm not sure if the definition needs to be fixed or the returned value type needs to be changed.\r\n\r\n<!-- What happened instead? -->\r\n### Observed Behavior\r\nObject doesn't match definition\n", "before_files": [{"content": "from drf_yasg import openapi\nfrom drf_yasg.inspectors import FieldInspector, NotHandled, PaginatorInspector, FilterInspector, SwaggerAutoSchema\nfrom drf_yasg.utils import get_serializer_ref_name\nfrom rest_framework.fields import ChoiceField\nfrom rest_framework.relations import ManyRelatedField\nfrom taggit_serializer.serializers import TagListSerializerField\n\nfrom dcim.api.serializers import InterfaceSerializer as DeviceInterfaceSerializer\nfrom extras.api.customfields import CustomFieldsSerializer\nfrom utilities.api import ChoiceField, SerializedPKRelatedField, WritableNestedSerializer\nfrom virtualization.api.serializers import InterfaceSerializer as VirtualMachineInterfaceSerializer\n\n# this might be ugly, but it limits drf_yasg-specific code to this file\nDeviceInterfaceSerializer.Meta.ref_name = 'DeviceInterface'\nVirtualMachineInterfaceSerializer.Meta.ref_name = 'VirtualMachineInterface'\n\n\nclass NetBoxSwaggerAutoSchema(SwaggerAutoSchema):\n    writable_serializers = {}\n\n    def get_request_serializer(self):\n        serializer = super().get_request_serializer()\n\n        if serializer is not None and self.method in self.implicit_body_methods:\n            properties = {}\n            for child_name, child in serializer.fields.items():\n                if isinstance(child, (ChoiceField, WritableNestedSerializer)):\n                    properties[child_name] = None\n                elif isinstance(child, ManyRelatedField) and isinstance(child.child_relation, SerializedPKRelatedField):\n                    properties[child_name] = None\n\n            if properties:\n                if type(serializer) not in self.writable_serializers:\n                    writable_name = 'Writable' + type(serializer).__name__\n                    meta_class = getattr(type(serializer), 'Meta', None)\n                    if meta_class:\n                        ref_name = 'Writable' + get_serializer_ref_name(serializer)\n                        writable_meta = type('Meta', (meta_class,), {'ref_name': ref_name})\n                        properties['Meta'] = writable_meta\n\n                    self.writable_serializers[type(serializer)] = type(writable_name, (type(serializer),), properties)\n\n                writable_class = self.writable_serializers[type(serializer)]\n                serializer = writable_class()\n\n        return serializer\n\n\nclass SerializedPKRelatedFieldInspector(FieldInspector):\n    def field_to_swagger_object(self, field, swagger_object_type, use_references, **kwargs):\n        SwaggerType, ChildSwaggerType = self._get_partial_types(field, swagger_object_type, use_references, **kwargs)\n        if isinstance(field, SerializedPKRelatedField):\n            return self.probe_field_inspectors(field.serializer(), ChildSwaggerType, use_references)\n\n        return NotHandled\n\n\nclass TagListFieldInspector(FieldInspector):\n    def field_to_swagger_object(self, field, swagger_object_type, use_references, **kwargs):\n        SwaggerType, ChildSwaggerType = self._get_partial_types(field, swagger_object_type, use_references, **kwargs)\n        if isinstance(field, TagListSerializerField):\n            child_schema = self.probe_field_inspectors(field.child, ChildSwaggerType, use_references)\n            return SwaggerType(\n                type=openapi.TYPE_ARRAY,\n                items=child_schema,\n            )\n\n        return NotHandled\n\n\nclass CustomChoiceFieldInspector(FieldInspector):\n    def field_to_swagger_object(self, field, swagger_object_type, use_references, **kwargs):\n        # this returns a callable which extracts title, description and other stuff\n        # https://drf-yasg.readthedocs.io/en/stable/_modules/drf_yasg/inspectors/base.html#FieldInspector._get_partial_types\n        SwaggerType, _ = self._get_partial_types(field, swagger_object_type, use_references, **kwargs)\n\n        if isinstance(field, ChoiceField):\n            value_schema = openapi.Schema(type=openapi.TYPE_STRING)\n\n            choices = list(field._choices.keys())\n            if set([None] + choices) == {None, True, False}:\n                # DeviceType.subdevice_role, Device.face and InterfaceConnection.connection_status all need to be\n                # differentiated since they each have subtly different values in their choice keys.\n                # - subdevice_role and connection_status are booleans, although subdevice_role includes None\n                # - face is an integer set {0, 1} which is easily confused with {False, True}\n                schema_type = openapi.TYPE_STRING\n                if all(type(x) == bool for x in [c for c in choices if c is not None]):\n                    schema_type = openapi.TYPE_BOOLEAN\n                value_schema = openapi.Schema(type=schema_type)\n                value_schema['x-nullable'] = True\n\n            schema = SwaggerType(type=openapi.TYPE_OBJECT, required=[\"label\", \"value\"], properties={\n                \"label\": openapi.Schema(type=openapi.TYPE_STRING),\n                \"value\": value_schema\n            })\n\n            return schema\n\n        elif isinstance(field, CustomFieldsSerializer):\n            schema = SwaggerType(type=openapi.TYPE_OBJECT)\n            return schema\n\n        return NotHandled\n\n\nclass NullableBooleanFieldInspector(FieldInspector):\n    def process_result(self, result, method_name, obj, **kwargs):\n\n        if isinstance(result, openapi.Schema) and isinstance(obj, ChoiceField) and result.type == 'boolean':\n            keys = obj.choices.keys()\n            if set(keys) == {None, True, False}:\n                result['x-nullable'] = True\n                result.type = 'boolean'\n\n        return result\n\n\nclass IdInFilterInspector(FilterInspector):\n    def process_result(self, result, method_name, obj, **kwargs):\n        if isinstance(result, list):\n            params = [p for p in result if isinstance(p, openapi.Parameter) and p.name == 'id__in']\n            for p in params:\n                p.type = 'string'\n\n        return result\n\n\nclass NullablePaginatorInspector(PaginatorInspector):\n    def process_result(self, result, method_name, obj, **kwargs):\n        if method_name == 'get_paginated_response' and isinstance(result, openapi.Schema):\n            next = result.properties['next']\n            if isinstance(next, openapi.Schema):\n                next['x-nullable'] = True\n            previous = result.properties['previous']\n            if isinstance(previous, openapi.Schema):\n                previous['x-nullable'] = True\n\n        return result\n", "path": "netbox/utilities/custom_inspectors.py"}], "after_files": [{"content": "from drf_yasg import openapi\nfrom drf_yasg.inspectors import FieldInspector, NotHandled, PaginatorInspector, FilterInspector, SwaggerAutoSchema\nfrom drf_yasg.utils import get_serializer_ref_name\nfrom rest_framework.fields import ChoiceField\nfrom rest_framework.relations import ManyRelatedField\nfrom taggit_serializer.serializers import TagListSerializerField\n\nfrom dcim.api.serializers import InterfaceSerializer as DeviceInterfaceSerializer\nfrom extras.api.customfields import CustomFieldsSerializer\nfrom utilities.api import ChoiceField, SerializedPKRelatedField, WritableNestedSerializer\nfrom virtualization.api.serializers import InterfaceSerializer as VirtualMachineInterfaceSerializer\n\n# this might be ugly, but it limits drf_yasg-specific code to this file\nDeviceInterfaceSerializer.Meta.ref_name = 'DeviceInterface'\nVirtualMachineInterfaceSerializer.Meta.ref_name = 'VirtualMachineInterface'\n\n\nclass NetBoxSwaggerAutoSchema(SwaggerAutoSchema):\n    writable_serializers = {}\n\n    def get_request_serializer(self):\n        serializer = super().get_request_serializer()\n\n        if serializer is not None and self.method in self.implicit_body_methods:\n            properties = {}\n            for child_name, child in serializer.fields.items():\n                if isinstance(child, (ChoiceField, WritableNestedSerializer)):\n                    properties[child_name] = None\n                elif isinstance(child, ManyRelatedField) and isinstance(child.child_relation, SerializedPKRelatedField):\n                    properties[child_name] = None\n\n            if properties:\n                if type(serializer) not in self.writable_serializers:\n                    writable_name = 'Writable' + type(serializer).__name__\n                    meta_class = getattr(type(serializer), 'Meta', None)\n                    if meta_class:\n                        ref_name = 'Writable' + get_serializer_ref_name(serializer)\n                        writable_meta = type('Meta', (meta_class,), {'ref_name': ref_name})\n                        properties['Meta'] = writable_meta\n\n                    self.writable_serializers[type(serializer)] = type(writable_name, (type(serializer),), properties)\n\n                writable_class = self.writable_serializers[type(serializer)]\n                serializer = writable_class()\n\n        return serializer\n\n\nclass SerializedPKRelatedFieldInspector(FieldInspector):\n    def field_to_swagger_object(self, field, swagger_object_type, use_references, **kwargs):\n        SwaggerType, ChildSwaggerType = self._get_partial_types(field, swagger_object_type, use_references, **kwargs)\n        if isinstance(field, SerializedPKRelatedField):\n            return self.probe_field_inspectors(field.serializer(), ChildSwaggerType, use_references)\n\n        return NotHandled\n\n\nclass TagListFieldInspector(FieldInspector):\n    def field_to_swagger_object(self, field, swagger_object_type, use_references, **kwargs):\n        SwaggerType, ChildSwaggerType = self._get_partial_types(field, swagger_object_type, use_references, **kwargs)\n        if isinstance(field, TagListSerializerField):\n            child_schema = self.probe_field_inspectors(field.child, ChildSwaggerType, use_references)\n            return SwaggerType(\n                type=openapi.TYPE_ARRAY,\n                items=child_schema,\n            )\n\n        return NotHandled\n\n\nclass CustomChoiceFieldInspector(FieldInspector):\n    def field_to_swagger_object(self, field, swagger_object_type, use_references, **kwargs):\n        # this returns a callable which extracts title, description and other stuff\n        # https://drf-yasg.readthedocs.io/en/stable/_modules/drf_yasg/inspectors/base.html#FieldInspector._get_partial_types\n        SwaggerType, _ = self._get_partial_types(field, swagger_object_type, use_references, **kwargs)\n\n        if isinstance(field, ChoiceField):\n            value_schema = openapi.Schema(type=openapi.TYPE_STRING)\n\n            choices = list(field._choices.keys())\n            if set([None] + choices) == {None, True, False}:\n                # DeviceType.subdevice_role, Device.face and InterfaceConnection.connection_status all need to be\n                # differentiated since they each have subtly different values in their choice keys.\n                # - subdevice_role and connection_status are booleans, although subdevice_role includes None\n                # - face is an integer set {0, 1} which is easily confused with {False, True}\n                schema_type = openapi.TYPE_STRING\n                if all(type(x) == bool for x in [c for c in choices if c is not None]):\n                    schema_type = openapi.TYPE_BOOLEAN\n                value_schema = openapi.Schema(type=schema_type)\n                value_schema['x-nullable'] = True\n\n            if isinstance(choices[0], int):\n                # Change value_schema for IPAddressFamilyChoices, RackWidthChoices\n                value_schema = openapi.Schema(type=openapi.TYPE_INTEGER)\n\n            schema = SwaggerType(type=openapi.TYPE_OBJECT, required=[\"label\", \"value\"], properties={\n                \"label\": openapi.Schema(type=openapi.TYPE_STRING),\n                \"value\": value_schema\n            })\n\n            return schema\n\n        elif isinstance(field, CustomFieldsSerializer):\n            schema = SwaggerType(type=openapi.TYPE_OBJECT)\n            return schema\n\n        return NotHandled\n\n\nclass NullableBooleanFieldInspector(FieldInspector):\n    def process_result(self, result, method_name, obj, **kwargs):\n\n        if isinstance(result, openapi.Schema) and isinstance(obj, ChoiceField) and result.type == 'boolean':\n            keys = obj.choices.keys()\n            if set(keys) == {None, True, False}:\n                result['x-nullable'] = True\n                result.type = 'boolean'\n\n        return result\n\n\nclass IdInFilterInspector(FilterInspector):\n    def process_result(self, result, method_name, obj, **kwargs):\n        if isinstance(result, list):\n            params = [p for p in result if isinstance(p, openapi.Parameter) and p.name == 'id__in']\n            for p in params:\n                p.type = 'string'\n\n        return result\n\n\nclass NullablePaginatorInspector(PaginatorInspector):\n    def process_result(self, result, method_name, obj, **kwargs):\n        if method_name == 'get_paginated_response' and isinstance(result, openapi.Schema):\n            next = result.properties['next']\n            if isinstance(next, openapi.Schema):\n                next['x-nullable'] = True\n            previous = result.properties['previous']\n            if isinstance(previous, openapi.Schema):\n                previous['x-nullable'] = True\n\n        return result\n", "path": "netbox/utilities/custom_inspectors.py"}]}