Repository: netbox-community/netbox

Issue:
[OpenAPI] _occupied is type of string, instead boolean
### NetBox version

v2.11.1

### Python version

3.9

### Steps to Reproduce
Currently the field `_occupied` is implemented as type of `string` instead of `boolean`. This applies for all models with the field `_occupied`.

See `CircuitTermination`:
[...]
```json
"_occupied": {
   "title": "occupied",
   "type": "string",
   "readOnly": true
}
```

### Expected Behavior

I expect `_occupied` to by type of boolean.

### Observed Behavior

Unable to Parse API Response


Discussion:

Resolving patch:
diff --git a/netbox/dcim/api/serializers.py b/netbox/dcim/api/serializers.py
--- a/netbox/dcim/api/serializers.py
+++ b/netbox/dcim/api/serializers.py
@@ -25,6 +25,7 @@
 class CableTerminationSerializer(serializers.ModelSerializer):
     cable_peer_type = serializers.SerializerMethodField(read_only=True)
     cable_peer = serializers.SerializerMethodField(read_only=True)
+    _occupied = serializers.SerializerMethodField(read_only=True)
 
     def get_cable_peer_type(self, obj):
         if obj._cable_peer is not None:
@@ -42,6 +43,10 @@ def get_cable_peer(self, obj):
             return serializer(obj._cable_peer, context=context).data
         return None
 
+    @swagger_serializer_method(serializer_or_field=serializers.BooleanField)
+    def get__occupied(self, obj):
+        return obj._occupied
+
 
 class ConnectedEndpointSerializer(serializers.ModelSerializer):
     connected_endpoint_type = serializers.SerializerMethodField(read_only=True)
diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py
--- a/netbox/netbox/settings.py
+++ b/netbox/netbox/settings.py
@@ -16,7 +16,7 @@
 # Environment setup
 #
 
-VERSION = '2.11.8'
+VERSION = '2.11.9'
 
 # Hostname
 HOSTNAME = platform.node()
diff --git a/netbox/virtualization/api/nested_serializers.py b/netbox/virtualization/api/nested_serializers.py
--- a/netbox/virtualization/api/nested_serializers.py
+++ b/netbox/virtualization/api/nested_serializers.py
@@ -1,8 +1,7 @@
 from rest_framework import serializers
 
-from dcim.models import Interface
 from netbox.api import WritableNestedSerializer
-from virtualization.models import Cluster, ClusterGroup, ClusterType, VirtualMachine
+from virtualization.models import Cluster, ClusterGroup, ClusterType, VirtualMachine, VMInterface
 
 __all__ = [
     'NestedClusterGroupSerializer',
@@ -61,5 +60,5 @@ class NestedVMInterfaceSerializer(WritableNestedSerializer):
     virtual_machine = NestedVirtualMachineSerializer(read_only=True)
 
     class Meta:
-        model = Interface
+        model = VMInterface
         fields = ['id', 'url', 'display', 'virtual_machine', 'name']


Test patch:
diff --git a/netbox/dcim/tests/test_api.py b/netbox/dcim/tests/test_api.py
--- a/netbox/dcim/tests/test_api.py
+++ b/netbox/dcim/tests/test_api.py
@@ -1211,8 +1211,9 @@ def setUpTestData(cls):
             {
                 'device': device.pk,
                 'name': 'Interface 6',
-                'type': '1000base-t',
+                'type': 'virtual',
                 'mode': InterfaceModeChoices.MODE_TAGGED,
+                'parent': interfaces[0].pk,
                 'tagged_vlans': [vlans[0].pk, vlans[1].pk],
                 'untagged_vlan': vlans[2].pk,
             },
diff --git a/netbox/virtualization/tests/test_api.py b/netbox/virtualization/tests/test_api.py
--- a/netbox/virtualization/tests/test_api.py
+++ b/netbox/virtualization/tests/test_api.py
@@ -251,6 +251,7 @@ def setUpTestData(cls):
             {
                 'virtual_machine': virtualmachine.pk,
                 'name': 'Interface 6',
+                'parent': interfaces[0].pk,
                 'mode': InterfaceModeChoices.MODE_TAGGED,
                 'tagged_vlans': [vlans[0].pk, vlans[1].pk],
                 'untagged_vlan': vlans[2].pk,