Nullable fields not nullable in the OpenAPI spec #9415

Closed
opened 2025-12-29 20:49:30 +01:00 by adam · 3 comments
Owner

Originally created by @fbs on GitHub (Mar 30, 2024).

Originally assigned to: @arthanson on GitHub.

Deployment Type

Self-hosted

NetBox Version

v3.7.4

Python Version

3.11

Steps to Reproduce

Compare the API spec on dcim/devices to the actual API response

Expected Behavior

An unknown number of fields should be marked nullable in the openapi spec

This include at least:

  • primary_ip on VirtualMachineWithConfigContext
  • primary_ip on DeviceWithConfigContext

I think there are more as I expect this an issue with how the spec is generated from properties

Observed Behavior

$ curl -s -X 'GET' 'http://localhost:9876/api/dcim/devices/?name=NAME' -H 'accept: application/json' -H 'Authorization: token KEY' | jq '.results[0]|[.role, .primary_ip, .primary_ip4 ]'
[
  {
    "id": 15,
    "url": "http://localhost:9876/api/dcim/device-roles/15/",
    "display": "Server",
    "name": "Server",
    "slug": "server"
  },
  null, # <- primary_ip
  null  # <- primary_ip4
]

compared to the spec:

$ curl -s http://localhost:9876/api/schema/ | yq '.components.schemas.VirtualMachineWithConfigContext.properties.primary_ip'
allOf:
  - $ref: '#/components/schemas/NestedIPAddress'
readOnly: true

Note how primary_ipv4 is marked nullable, as expected

$ curl -s http://localhost:9876/api/schema/ | yq '.components.schemas.VirtualMachineWithConfigContext.properties.primary_ip4'
allOf:
  - $ref: '#/components/schemas/NestedIPAddress'
nullable: true

The above is just one instance, it happens to other schemas as well. E.g. DeviceWithConfigContext has the same problem

Originally created by @fbs on GitHub (Mar 30, 2024). Originally assigned to: @arthanson on GitHub. ### Deployment Type Self-hosted ### NetBox Version v3.7.4 ### Python Version 3.11 ### Steps to Reproduce Compare the API spec on dcim/devices to the actual API response ### Expected Behavior An unknown number of fields should be marked nullable in the openapi spec This include at least: - `primary_ip` on `VirtualMachineWithConfigContext` - `primary_ip` on `DeviceWithConfigContext` I think there are more as I expect this an issue with how the spec is generated from properties ### Observed Behavior ``` $ curl -s -X 'GET' 'http://localhost:9876/api/dcim/devices/?name=NAME' -H 'accept: application/json' -H 'Authorization: token KEY' | jq '.results[0]|[.role, .primary_ip, .primary_ip4 ]' [ { "id": 15, "url": "http://localhost:9876/api/dcim/device-roles/15/", "display": "Server", "name": "Server", "slug": "server" }, null, # <- primary_ip null # <- primary_ip4 ] ``` compared to the spec: ``` $ curl -s http://localhost:9876/api/schema/ | yq '.components.schemas.VirtualMachineWithConfigContext.properties.primary_ip' allOf: - $ref: '#/components/schemas/NestedIPAddress' readOnly: true ``` Note how primary_ipv4 is marked nullable, as expected ``` $ curl -s http://localhost:9876/api/schema/ | yq '.components.schemas.VirtualMachineWithConfigContext.properties.primary_ip4' allOf: - $ref: '#/components/schemas/NestedIPAddress' nullable: true ``` The above is just one instance, it happens to other schemas as well. E.g. `DeviceWithConfigContext` has the same problem
adam added the type: bugstatus: acceptedseverity: lowtopic: OpenAPI labels 2025-12-29 20:49:30 +01:00
adam closed this issue 2025-12-29 20:49:30 +01:00
Author
Owner

@fbs commented on GitHub (Mar 30, 2024):

My guess would be that this comes from the primary_ip being a property, making it read only but not nullable. But I'm not sure whether thats in the right direction.

I'd be open to fixing this but will need some pointers

@fbs commented on GitHub (Mar 30, 2024): My guess would be that this comes from the primary_ip being a [property](https://github.com/netbox-community/netbox/blob/699dd7259761da0d70f1a1bf94b088d44090f56d/netbox/dcim/models/devices.py#L1439), making it read only but not nullable. But I'm not sure whether thats in the right direction. I'd be open to fixing this but will need some pointers
Author
Owner

@jeremystretch commented on GitHub (Apr 1, 2024):

These fields should be nullable

Please spend some more time on your report. Without an explicit list of fields which you believe to be erroneously defined, this is not actionable.

@jeremystretch commented on GitHub (Apr 1, 2024): > These fields should be nullable Please spend some more time on your report. Without an explicit list of fields which you believe to be erroneously defined, this is not actionable.
Author
Owner

@fbs commented on GitHub (Apr 2, 2024):

These fields should be nullable

Please spend some more time on your report. Without an explicit list of fields which you believe to be erroneously defined, this is not actionable.

Sorry, I've updated the issue description to list the fields I identified.

I think we can identify all fields impacted when we understand what is causing the spec for these to be wrong

@fbs commented on GitHub (Apr 2, 2024): > > These fields should be nullable > > Please spend some more time on your report. Without an explicit list of fields which you believe to be erroneously defined, this is not actionable. Sorry, I've updated the issue description to list the fields I identified. I think we can identify all fields impacted when we understand what is causing the spec for these to be wrong
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9415