Object count fields are documented in Swagger for REST API GET requests but not included in the response #9651

Closed
opened 2025-12-29 21:20:18 +01:00 by adam · 9 comments
Owner

Originally created by @atownson on GitHub (May 10, 2024).

Deployment Type

Self-hosted

NetBox Version

v4.0.1

Python Version

3.11

Steps to Reproduce

The RelatedObjectCountField REST API serializer fields are being documented in the REST API Swagger for GET requests but not actually returned in the response.

  1. View the Swagger documentation for /dcim/devices/:
    image
  2. Invoke a corresponding GET request and review the response content:
{
    "count": 1,
    "next": null,
    "previous": null,
    "results": [
        {
            "id": 1,
            "url": "https://mynetbox.com/api/dcim/devices/1/",
            "display": "mydevice",
            "name": "mydevice",
            "device_type": {
                "id": 1,
                "url": "https://mynetbox.com/api/dcim/device-types/1/",
                "display": "mytype",
                "manufacturer": {
                    "id": 1,
                    "url": "https://mynetbox.com/api/dcim/manufacturers/1/",
                    "display": "mymanufacturer",
                    "name": "mymanufacturer",
                    "slug": "mymanufacturer",
                    "description": ""
                },
                "model": "mytype",
                "slug": "mytype",
                "description": ""
            },
            "role": {
                "id": 1,
                "url": "https://mynetbox.com/api/dcim/device-roles/1/",
                "display": "server",
                "name": "server",
                "slug": "server",
                "description": ""
            },
            "tenant": null,
            "platform": null,
            "serial": "",
            "asset_tag": null,
            "site": {
                "id": 1,
                "url": "https://mynetbox.com/api/dcim/sites/1/",
                "display": "mysite",
                "name": "mysite",
                "slug": "mysite",
                "description": ""
            },
            "location": null,
            "rack": null,
            "position": null,
            "face": null,
            "latitude": null,
            "longitude": null,
            "parent_device": null,
            "status": {
                "value": "active",
                "label": "Active"
            },
            "airflow": null,
            "primary_ip": {
                "id": 2,
                "url": "https://mynetbox.com/api/ipam/ip-addresses/2/",
                "display": "192.168.0.10/32",
                "family": {
                    "value": 4,
                    "label": "IPv4"
                },
                "address": "192.168.0.10/32",
                "description": ""
            },
            "primary_ip4": {
                "id": 2,
                "url": "https://mynetbox.com/api/ipam/ip-addresses/2/",
                "display": "192.168.0.10/32",
                "family": {
                    "value": 4,
                    "label": "IPv4"
                },
                "address": "192.168.0.10/32",
                "description": ""
            },
            "primary_ip6": null,
            "oob_ip": null,
            "cluster": null,
            "virtual_chassis": null,
            "vc_position": null,
            "vc_priority": null,
            "description": "",
            "comments": "",
            "config_template": null,
            "config_context": {},
            "local_context_data": null,
            "tags": [],
            "custom_fields": {},
            "created": "2023-10-04T17:05:56.749955Z",
            "last_updated": "2023-10-04T23:36:26.264584Z",
            "console_port_count": 0,
            "console_server_port_count": 0,
            "power_port_count": 0,
            "power_outlet_count": 0,
            "interface_count": 1,
            "front_port_count": 0,
            "rear_port_count": 0,
            "device_bay_count": 0,
            "module_bay_count": 0,
            "inventory_item_count": 0
        }
    ]
}

The behavior seems consistent wherever RelatedObjectCountField is used.

Expected Behavior

Based on the serializer classes, I assume the intention is to include these count fields since they're included in the brief fields. Either way, the Swagger scheme documentation should match the response content.

Observed Behavior

The Swagger documented schemes differ from the response content.

Originally created by @atownson on GitHub (May 10, 2024). ### Deployment Type Self-hosted ### NetBox Version v4.0.1 ### Python Version 3.11 ### Steps to Reproduce The `RelatedObjectCountField` REST API serializer fields are being documented in the REST API Swagger for GET requests but not actually returned in the response. 1. View the Swagger documentation for /dcim/devices/: ![image](https://github.com/netbox-community/netbox/assets/52260120/67d654bf-7f01-4e88-a231-56ae50361444) 2. Invoke a corresponding GET request and review the response content: ``` { "count": 1, "next": null, "previous": null, "results": [ { "id": 1, "url": "https://mynetbox.com/api/dcim/devices/1/", "display": "mydevice", "name": "mydevice", "device_type": { "id": 1, "url": "https://mynetbox.com/api/dcim/device-types/1/", "display": "mytype", "manufacturer": { "id": 1, "url": "https://mynetbox.com/api/dcim/manufacturers/1/", "display": "mymanufacturer", "name": "mymanufacturer", "slug": "mymanufacturer", "description": "" }, "model": "mytype", "slug": "mytype", "description": "" }, "role": { "id": 1, "url": "https://mynetbox.com/api/dcim/device-roles/1/", "display": "server", "name": "server", "slug": "server", "description": "" }, "tenant": null, "platform": null, "serial": "", "asset_tag": null, "site": { "id": 1, "url": "https://mynetbox.com/api/dcim/sites/1/", "display": "mysite", "name": "mysite", "slug": "mysite", "description": "" }, "location": null, "rack": null, "position": null, "face": null, "latitude": null, "longitude": null, "parent_device": null, "status": { "value": "active", "label": "Active" }, "airflow": null, "primary_ip": { "id": 2, "url": "https://mynetbox.com/api/ipam/ip-addresses/2/", "display": "192.168.0.10/32", "family": { "value": 4, "label": "IPv4" }, "address": "192.168.0.10/32", "description": "" }, "primary_ip4": { "id": 2, "url": "https://mynetbox.com/api/ipam/ip-addresses/2/", "display": "192.168.0.10/32", "family": { "value": 4, "label": "IPv4" }, "address": "192.168.0.10/32", "description": "" }, "primary_ip6": null, "oob_ip": null, "cluster": null, "virtual_chassis": null, "vc_position": null, "vc_priority": null, "description": "", "comments": "", "config_template": null, "config_context": {}, "local_context_data": null, "tags": [], "custom_fields": {}, "created": "2023-10-04T17:05:56.749955Z", "last_updated": "2023-10-04T23:36:26.264584Z", "console_port_count": 0, "console_server_port_count": 0, "power_port_count": 0, "power_outlet_count": 0, "interface_count": 1, "front_port_count": 0, "rear_port_count": 0, "device_bay_count": 0, "module_bay_count": 0, "inventory_item_count": 0 } ] } ``` The behavior seems consistent wherever `RelatedObjectCountField` is used. ### Expected Behavior Based on the serializer classes, I assume the intention is to include these count fields since they're included in the brief fields. Either way, the Swagger scheme documentation should match the response content. ### Observed Behavior The Swagger documented schemes differ from the response content.
adam added the type: bugseverity: lowtopic: OpenAPI labels 2025-12-29 21:20:18 +01:00
adam closed this issue 2025-12-29 21:20:18 +01:00
Author
Owner

@jeremystretch commented on GitHub (May 13, 2024):

Related object counts are intended to be included only for the root object: The data is not available on the underlying queryset when nesting. Opening this for anyone who would like to correct the OpenAPI schema to reflect this.

@jeremystretch commented on GitHub (May 13, 2024): Related object counts are intended to be included only for the root object: The data is not available on the underlying queryset when nesting. Opening this for anyone who would like to correct the OpenAPI schema to reflect this.
Author
Owner

@jeffgdotorg commented on GitHub (Jun 7, 2024):

As laid out in #16418, this kind of discrepancy can wreak havoc with strongly-typed client generator frameworks. Bumping severity to medium.

@jeffgdotorg commented on GitHub (Jun 7, 2024): As laid out in #16418, this kind of discrepancy can wreak havoc with strongly-typed client generator frameworks. Bumping severity to medium.
Author
Owner

@jeremystretch commented on GitHub (Jun 7, 2024):

@jeffgdotorg any issues with the OpenAPI schema should be classified as low severity as they do not impact the operation of NetBox itself.

@jeremystretch commented on GitHub (Jun 7, 2024): @jeffgdotorg any issues with the OpenAPI schema should be classified as low severity as they do not impact the operation of NetBox itself.
Author
Owner

@jeffgdotorg commented on GitHub (Jun 11, 2024):

@janhlavin in #16418 (dupe of this issue) you mentioned that dropping device_count from the relevant section of the OpenAPI definition would resolve this problem for your use case. If you're in a position to create a PR to that effect, please chime in and a maintainer will assign the issue to you.

@jeffgdotorg commented on GitHub (Jun 11, 2024): @janhlavin in #16418 (dupe of this issue) you mentioned that dropping `device_count` from the relevant section of the OpenAPI definition would resolve this problem for your use case. If you're in a position to create a PR to that effect, please chime in and a maintainer will assign the issue to you.
Author
Owner

@jeffgdotorg commented on GitHub (Jun 11, 2024):

@atownson same goes for you – PRs are welcome. Just let us know if you'd like to work it through, so we can assign the issue to you.

@jeffgdotorg commented on GitHub (Jun 11, 2024): @atownson same goes for you – PRs are welcome. Just let us know if you'd like to work it through, so we can assign the issue to you.
Author
Owner

@deathbeam commented on GitHub (Jun 18, 2024):

Also encountered this issue, but in broader sense, the brief fields being returned instead of the whole model in the swagger definition is incorrect even outside of just the count fields and as mentioned above breaks swagger generators. Not sure if I should open new issue or this one encapsulates that.

@deathbeam commented on GitHub (Jun 18, 2024): Also encountered this issue, but in broader sense, the `brief` fields being returned instead of the whole model in the swagger definition is incorrect even outside of just the `count` fields and as mentioned above breaks swagger generators. Not sure if I should open new issue or this one encapsulates that.
Author
Owner

@arthanson commented on GitHub (Jul 12, 2024):

I think this is related to #16670

@arthanson commented on GitHub (Jul 12, 2024): I think this is related to #16670
Author
Owner

@arthanson commented on GitHub (Aug 6, 2024):

closing as dupe of #16670

@arthanson commented on GitHub (Aug 6, 2024): closing as dupe of #16670
Author
Owner

@mohamedazouz commented on GitHub (Sep 19, 2024):

The issue still exists with version 4.1.1, screenshots are from demo Netbox which has the same version i'm start to use.

@arthanson can you reopen the issue?

Screenshot 2024-09-19 at 14 05 58 Screenshot 2024-09-19 at 14 04 30 Screenshot 2024-09-19 at 14 04 57
@mohamedazouz commented on GitHub (Sep 19, 2024): The issue still exists with version 4.1.1, screenshots are from [demo Netbox](https://demo.netbox.dev/api/status) which has the same version i'm start to use. @arthanson can you reopen the issue? <img width="890" alt="Screenshot 2024-09-19 at 14 05 58" src="https://github.com/user-attachments/assets/f8f79a1d-8f26-4bd8-8960-addf01138fee"> <img width="834" alt="Screenshot 2024-09-19 at 14 04 30" src="https://github.com/user-attachments/assets/61d1b781-56a8-47ac-be54-56e2a70d2218"> <img width="1338" alt="Screenshot 2024-09-19 at 14 04 57" src="https://github.com/user-attachments/assets/ca3e5bee-a571-494f-b2f7-a6f1b6d6c06a">
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9651