Choice field is not serialized as string #7852

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

Originally created by @amhn on GitHub (Apr 2, 2023).

Originally assigned to: @arthanson on GitHub.

NetBox version

v3.5-beta

Python version

3.10

Steps to Reproduce

Create Aggregate. Go to API and List Aggregates

Expected Behavior

The family field is a string as specified in openapi spec. Or openapi-spec is changed to specify this field as an object in the response.

Observed Behavior

The family field actually is an object:

      "family": {
        "value": 4,
        "label": "IPv4"
      },

This violates the definition.

Removing @extend_schema_field(OpenApiTypes.STR) from class ChoiceField produces in this case a more correct API definition:

                    "family": {
                        "type": "object",
                        "properties": {
                            "value": {
                                "type": "string"
                            },
                            "label": {
                                "type": "string"
                            }
                        },
                        "readOnly": true
                    },

instead of

                    "family": {
                        "type": "string",
                        "readOnly": true
                    },
Originally created by @amhn on GitHub (Apr 2, 2023). Originally assigned to: @arthanson on GitHub. ### NetBox version v3.5-beta ### Python version 3.10 ### Steps to Reproduce Create Aggregate. Go to API and List Aggregates ### Expected Behavior The family field is a string as specified in openapi spec. Or openapi-spec is changed to specify this field as an object in the response. ### Observed Behavior The family field actually is an object: ``` "family": { "value": 4, "label": "IPv4" }, ``` This violates the definition. Removing `@extend_schema_field(OpenApiTypes.STR)` from class ChoiceField produces in this case a more correct API definition: ``` "family": { "type": "object", "properties": { "value": { "type": "string" }, "label": { "type": "string" } }, "readOnly": true }, ``` instead of ``` "family": { "type": "string", "readOnly": true }, ```
adam added the type: bugstatus: acceptedbeta labels 2025-12-29 20:29:01 +01:00
adam closed this issue 2025-12-29 20:29:01 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7852