Skip to content

Generating OpenAPI schema triggers multiple warnings and errors #20365

@jeremystretch

Description

@jeremystretch

NetBox Edition

NetBox Community

NetBox Version

v4.4.0

Python Version

3.12

Steps to Reproduce

  1. Generate the OpenAPI schema locally with the following management command:
./manage.py spectacular --format openapi-json > openapi.json

Expected Behavior

The OpenAPI schema should be generated without any warnings or errors.

Observed Behavior

Although the schema is generated, the following warnings and errors are reported:

/home/jstretch/projects/netbox/netbox/core/api/views.py:182: Warning [BackgroundTaskViewSet]: could not derive type of path parameter "id" because it is untyped and obtaining queryset from the viewset failed. Consider adding a type to the path (e.g. <int:id>) or annotating the parameter type with @extend_schema. Defaulting to "string".
/home/jstretch/projects/netbox/netbox/core/api/views.py:182: Error [BackgroundTaskViewSet]: exception raised while getting serializer. Hint: Is get_serializer_class() returning None or is get_queryset() not working without a request? Ignoring the view for now. (Exception: 'BackgroundTaskViewSet' object has no attribute 'get_serializer_class')
/home/jstretch/projects/netbox/netbox/core/api/views.py:156: Error [BackgroundWorkerViewSet]: exception raised while getting serializer. Hint: Is get_serializer_class() returning None or is get_queryset() not working without a request? Ignoring the view for now. (Exception: 'BackgroundWorkerViewSet' object has no attribute 'get_serializer_class')
/home/jstretch/projects/netbox/netbox/core/api/views.py:156: Warning [BackgroundWorkerViewSet]: could not derive type of path parameter "name" because it is untyped and obtaining queryset from the viewset failed. Consider adding a type to the path (e.g. <int:name>) or annotating the parameter type with @extend_schema. Defaulting to "string".
/home/jstretch/projects/netbox/netbox/dcim/filtersets.py:1045: Warning [DeviceViewSet > DeviceFilterSet]: model field "IPAddressField" has no mapping in ModelSerializer. It may be a deprecated field. Defaulting to "string"
/home/jstretch/projects/netbox/netbox/dcim/filtersets.py:1914: Error [InterfaceViewSet > InterfaceFilterSet]: could not resolve model field "dcim.MACAddress.mac_address". Failed to resolve through serializer_field_mapping, get_internal_type(), or any override mechanism. Defaulting to "string"
/home/jstretch/projects/netbox/netbox/dcim/api/serializers_/devices.py:162: Error [InterfaceViewSet > InterfaceSerializer > MACAddressSerializer]: could not resolve model field "dcim.MACAddress.mac_address". Failed to resolve through serializer_field_mapping, get_internal_type(), or any override mechanism. Defaulting to "string"
/home/jstretch/projects/netbox/netbox/dcim/api/serializers_/devices.py:162: Error [InterfaceViewSet > WritableInterfaceSerializer > MACAddressSerializer]: could not resolve model field "dcim.MACAddress.mac_address". Failed to resolve through serializer_field_mapping, get_internal_type(), or any override mechanism. Defaulting to "string"
/home/jstretch/projects/netbox/netbox/dcim/api/serializers_/devices.py:162: Error [MACAddressViewSet > MACAddressSerializer]: could not resolve model field "dcim.MACAddress.mac_address". Failed to resolve through serializer_field_mapping, get_internal_type(), or any override mechanism. Defaulting to "string"
/home/jstretch/projects/netbox/netbox/dcim/filtersets.py:1348: Warning [VirtualDeviceContextViewSet > VirtualDeviceContextFilterSet]: model field "IPAddressField" has no mapping in ModelSerializer. It may be a deprecated field. Defaulting to "string"
/home/jstretch/projects/netbox/netbox/extras/api/serializers_/customfields.py:18: Warning [CustomFieldChoiceSetViewSet > CustomFieldChoiceSetSerializer]: unable to resolve type hint for function "choices_count". Consider using a type hint or @extend_schema_field. Defaulting to string.
/home/jstretch/projects/netbox/netbox/extras/api/serializers_/customfields.py:18: Warning [CustomFieldViewSet > CustomFieldSerializer > CustomFieldChoiceSetSerializer]: unable to resolve type hint for function "choices_count". Consider using a type hint or @extend_schema_field. Defaulting to string.
/home/jstretch/projects/netbox/netbox/extras/api/serializers_/customfields.py:18: Warning [CustomFieldViewSet > WritableCustomFieldSerializer > CustomFieldChoiceSetSerializer]: unable to resolve type hint for function "choices_count". Consider using a type hint or @extend_schema_field. Defaulting to string.
/home/jstretch/projects/netbox/netbox/ipam/filtersets.py:1166: Warning [ServiceViewSet > ServiceFilterSet]: model field "IPAddressField" has no mapping in ModelSerializer. It may be a deprecated field. Defaulting to "string"
/home/jstretch/projects/netbox/netbox/ipam/filtersets.py:950: Warning [VLANViewSet > VLANFilterSet]: Unable to guess choice types from values, filter method's type hint or find "interface_id" in model. Defaulting to string.
/home/jstretch/projects/netbox/netbox/ipam/filtersets.py:950: Warning [VLANViewSet > VLANFilterSet]: Unable to guess choice types from values, filter method's type hint or find "vminterface_id" in model. Defaulting to string.
/home/jstretch/projects/netbox/netbox/virtualization/filtersets.py:238: Error [VMInterfaceViewSet > VMInterfaceFilterSet]: could not resolve model field "dcim.MACAddress.mac_address". Failed to resolve through serializer_field_mapping, get_internal_type(), or any override mechanism. Defaulting to "string"
/home/jstretch/projects/netbox/netbox/virtualization/filtersets.py:82: Warning [VirtualMachineViewSet > VirtualMachineFilterSet]: model field "IPAddressField" has no mapping in ModelSerializer. It may be a deprecated field. Defaulting to "string"
Warning: operationId "core_background_queues_retrieve" has collisions [('/api/core/background-queues/', 'get'), ('/api/core/background-queues/{name}/', 'get')]. resolving with numeral suffixes.
Warning: operationId "core_background_tasks_retrieve" has collisions [('/api/core/background-tasks/', 'get'), ('/api/core/background-tasks/{id}/', 'get')]. resolving with numeral suffixes.
Warning: operationId "core_background_workers_retrieve" has collisions [('/api/core/background-workers/', 'get'), ('/api/core/background-workers/{name}/', 'get')]. resolving with numeral suffixes.

Schema generation summary:
Warnings: 29 (14 unique)
Errors:   29 (7 unique)

Metadata

Metadata

Assignees

Labels

severity: lowDoes not significantly disrupt application functionality, or a workaround is availablestatus: acceptedThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the application

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions