Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Device in REST API doesn't include DeviceType.device_count as described in Swagger schema #16418

Closed
janhlavin opened this issue Jun 5, 2024 · 6 comments
Labels
severity: medium Results in substantial degraded or broken functionality for specfic workflows status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@janhlavin
Copy link

janhlavin commented Jun 5, 2024

Deployment Type

Self-hosted

NetBox Version

v4.0.3

Python Version

3.11

Steps to Reproduce

  1. create Manufacturer, Device type, Device role, Site and Device
  2. call GET to /api/dcim/devices/$DeviceID/

Expected Behavior

return:

{
 "id": 1,
 "device_type": {
  "id": 1,
  "device_count": 1,
  "...": "..."
 },
 "...": "..."
}

Observed Behavior

return:

{
 "id": 1,
 "device_type": {
  "id": 1,
  "...": "..."
 },
 "...": "..."
}

Narrative (from comments below, edited somewhat for clarity)

The main trouble is that there's an inconsistency between the Swagger schema and the actual API responses. The actual response fails to validate against the example schema provided by Swagger. This causes problems when using strongly-typed API client frameworks to generate code that talks to NetBox.

I don't need the property device_count as a child of device_type. A change in the Swagger definition, declaring device_type to be of type NestedDeviceType is fine and will fix this bug for my purposes.

@janhlavin janhlavin added status: needs triage This issue is awaiting triage by a maintainer type: bug A confirmed report of unexpected behavior in the application labels Jun 5, 2024
@tgoodsell-tempus
Copy link

tgoodsell-tempus commented Jun 5, 2024

I'm seeing similar behavior for the prefix_count attribute embedded in the vrf object of a Prefix:

  1. Call GET https://hostname/api/ipam/prefixes/

Return:

{
    "count": 4,
    "next": null,
    "previous": null,
    "results": [
        {
            "id": 3,
            "url": "https://hostname/api/ipam/prefixes/3/",
            "display": "10.64.0.0/11",
            "family": {
                "value": 4,
                "label": "IPv4"
            },
            "prefix": "10.64.0.0/11",
            "site": null,
            "vrf": {
                "id": 1,
                "url": "https://hostname/api/ipam/vrfs/1/",
                "display": "ZRO",
                "name": "ZRO",
                "rd": null,
                "description": ""
            },
            "tenant": null,
            "vlan": null,
            "status": {
                "value": "container",
                "label": "Container"
            },
            "role": null,
            "is_pool": true,
            "mark_utilized": false,
            "description": "ZRO",
            "comments": "",
            "tags": [],
            "custom_fields": {},
            "created": "2024-05-14T00:26:48.400795Z",
            "last_updated": "2024-05-14T00:26:48.400812Z",
            "children": 1,
            "_depth": 0
        },
        ...

Expected schema (from https://hostname/api/schema/swagger-ui/#/ipam/ipam_prefixes_list):

{
  "count": 123,
  "next": "http://api.example.org/accounts/?offset=400&limit=100",
  "previous": "http://api.example.org/accounts/?offset=200&limit=100",
  "results": [
    {
      "id": 0,
      "url": "string",
      "display": "string",
      "family": {
        "value": 4,
        "label": "IPv4"
      },
      "prefix": "string",
      "site": {
        "id": 0,
        "url": "string",
        "display": "string",
        "name": "string",
        "slug": "lt35brDofIze9mWTFO78eHPXsP-lqRLkbhUxRluQT66YdsdBXIAAdM1ZAIKNO_f-mR7PM5GDcKzhfsnZE-6kuX0W6MzqH",
        "description": "string"
      },
      "vrf": {
        "id": 0,
        "url": "string",
        "display": "string",
        "name": "string",
        "rd": "string",
        "description": "string",
        "prefix_count": 0
      },

Causes issues with strongly typed SDKs like the go-netbox sdk (ref: netbox-community/go-netbox#177)

When calling GET https://hostname/api/ipam/vrfs/1/:

{
    "id": 1,
    "url": "https://hostname/api/ipam/vrfs/1/",
    "display": "ZRO",
    "name": "ZRO",
    "rd": null,
    "tenant": null,
    "enforce_unique": true,
    "description": "",
    "comments": "",
    "import_targets": [],
    "export_targets": [],
    "tags": [],
    "custom_fields": {},
    "created": "2024-05-14T00:25:30.457087Z",
    "last_updated": "2024-05-14T00:25:30.457103Z",
    "ipaddress_count": 0,
    "prefix_count": 2
}

@jeffgdotorg jeffgdotorg added status: revisions needed This issue requires additional information to be actionable and removed status: needs triage This issue is awaiting triage by a maintainer labels Jun 6, 2024
@jeffgdotorg
Copy link
Contributor

Thanks for reporting a problem you've encountered in NetBox.

Do I understand correctly that you expect to see device_type.device_count in the response to /api/dcim/devices/{id}/ because the example schema produced by the Swagger UI specifies its presence?

If so, please update the issue body to clarify the reason for your expectation. As a person who's only somewhat familiar with OpenAPI, understanding why this is a problem took me quite some time.

@janhlavin
Copy link
Author

main trouble is in inconsistency Swagger schema and real API responses - I don't need property "device_count" in "device_type" => change in Swagger definition, where "device_type" is type of "NestedDeviceType" is fine and fix this bug

@jeffgdotorg
Copy link
Contributor

Thanks for clarifying the practical impact. I've adapted your previous comment and included it at the bottom of the issue body.

@jeffgdotorg jeffgdotorg added status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation severity: medium Results in substantial degraded or broken functionality for specfic workflows and removed status: revisions needed This issue requires additional information to be actionable labels Jun 7, 2024
@jeffgdotorg jeffgdotorg removed their assignment Jun 7, 2024
@jeffgdotorg jeffgdotorg changed the title Get Device in API don't return required DeviceType.device_count Get Device in REST API doesn't return DeviceType.device_count as described in Swagger schema Jun 7, 2024
@jeffgdotorg jeffgdotorg changed the title Get Device in REST API doesn't return DeviceType.device_count as described in Swagger schema Get Device in REST API doesn't include DeviceType.device_count as described in Swagger schema Jun 7, 2024
@jeffgdotorg
Copy link
Contributor

I just spotted #16085 which captures the same underlying problem as this issue. Resolving this one as a duplicate.

@jeffgdotorg
Copy link
Contributor

Duplicate of #16085

@jeffgdotorg jeffgdotorg marked this as a duplicate of #16085 Jun 7, 2024
@jeffgdotorg jeffgdotorg closed this as not planned Won't fix, can't repro, duplicate, stale Jun 7, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
severity: medium Results in substantial degraded or broken functionality for specfic workflows status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

No branches or pull requests

3 participants