Repository: netbox-community/netbox

Issue:
Some NullBooleanFields Are Documented as Integers
<!--
    NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED.

    Please indicate the nature of the change by placing an X in one of the
    boxes below.
-->
### Change Type
[ ] Addition
[X] Correction
[ ] Deprecation
[ ] Cleanup (formatting, typos, etc.)

### Area
[ ] Installation instructions
[ ] Configuration parameters
[ ] Functionality/features
[X] REST API
[ ] Administration/development
[ ] Other

<!-- Describe the proposed change(s). -->
### Proposed Changes
Im not sure if this is a NetBox or lower issue, maybe in [drf-yasg](https://github.com/axnsan12/drf-yasg/), but the Swagger documentation is listing certain `NullBooleanField`s as integers. This is causing issues when it comes to generation swagger clients because then it tries to marshal a boolean into an `int` variable, which inevitably explodes. These should be listed as a nullable boolean.

<img width="667" alt="Screen Shot 2020-03-12 at 1 23 16 PM" src="https://user-images.githubusercontent.com/10478871/76548397-082f1800-6465-11ea-88f2-e5c93495f64c.png">

Some NullBooleanFields Are Documented as Integers
<!--
    NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED.

    Please indicate the nature of the change by placing an X in one of the
    boxes below.
-->
### Change Type
[ ] Addition
[X] Correction
[ ] Deprecation
[ ] Cleanup (formatting, typos, etc.)

### Area
[ ] Installation instructions
[ ] Configuration parameters
[ ] Functionality/features
[X] REST API
[ ] Administration/development
[ ] Other

<!-- Describe the proposed change(s). -->
### Proposed Changes
Im not sure if this is a NetBox or lower issue, maybe in [drf-yasg](https://github.com/axnsan12/drf-yasg/), but the Swagger documentation is listing certain `NullBooleanField`s as integers. This is causing issues when it comes to generation swagger clients because then it tries to marshal a boolean into an `int` variable, which inevitably explodes. These should be listed as a nullable boolean.

<img width="667" alt="Screen Shot 2020-03-12 at 1 23 16 PM" src="https://user-images.githubusercontent.com/10478871/76548397-082f1800-6465-11ea-88f2-e5c93495f64c.png">



Discussion:
Could you let us know which exact fields should be `NullBooleanFields`?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).

Sorry @kobayashi I didn't see your comment. It appears to be anything that extends from [`ConnectedEndpointSerializer`](https://github.com/netbox-community/netbox/blob/62efe0621f710310f9bceb46fd6d27b0d57bfb3c/netbox/dcim/api/serializers.py#L29)
Also I should mention that I notice this on the associated `connection_status` field
Thanks to let us know.
I found this is set in the if statement.

https://github.com/netbox-community/netbox/blob/e04a5dc81fc41769069609e992699dffe4a3d79f/netbox/utilities/custom_inspectors.py#L95-L97

`isinstance(bool, int)` handles bool as int because `bool` is subclass of `int`.

```
>>> isinstance(False, int)
True
>>> isinstance(True, int)
True
```

Is there much better way than this? :thinking: 

```
if  not isinstance(choice_value[0], bool) and isinstance(choice_value[0], int):
    # Change value_schema for IPAddressFamilyChoices, RackWidthChoices
    value_schema = openapi.Schema(type=openapi.TYPE_INTEGER, enum=choice_value)
```
Could you let us know which exact fields should be `NullBooleanFields`?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).

Sorry @kobayashi I didn't see your comment. It appears to be anything that extends from [`ConnectedEndpointSerializer`](https://github.com/netbox-community/netbox/blob/62efe0621f710310f9bceb46fd6d27b0d57bfb3c/netbox/dcim/api/serializers.py#L29)
Also I should mention that I notice this on the associated `connection_status` field
Thanks to let us know.
I found this is set in the if statement.

https://github.com/netbox-community/netbox/blob/e04a5dc81fc41769069609e992699dffe4a3d79f/netbox/utilities/custom_inspectors.py#L95-L97

`isinstance(bool, int)` handles bool as int because `bool` is subclass of `int`.

```
>>> isinstance(False, int)
True
>>> isinstance(True, int)
True
```

Is there much better way than this? :thinking: 

```
if  not isinstance(choice_value[0], bool) and isinstance(choice_value[0], int):
    # Change value_schema for IPAddressFamilyChoices, RackWidthChoices
    value_schema = openapi.Schema(type=openapi.TYPE_INTEGER, enum=choice_value)
```

Resolving patch:
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
@@ -92,7 +92,7 @@ def field_to_swagger_object(self, field, swagger_object_type, use_references, **
                 value_schema = openapi.Schema(type=schema_type, enum=choice_value)
                 value_schema['x-nullable'] = True
 
-            if isinstance(choice_value[0], int):
+            if all(type(x) == int for x in [c for c in choice_value if c is not None]):
                 # Change value_schema for IPAddressFamilyChoices, RackWidthChoices
                 value_schema = openapi.Schema(type=openapi.TYPE_INTEGER, enum=choice_value)
 


Test patch: