Skip to content

Nullable fields not nullable in the OpenAPI spec #15588

@fbs

Description

@fbs

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

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions