Open zunkree opened 1 month ago
Aside from the issue of code complexity, this is an even bigger problem for object references that do not have a unique name, ie IPAddress
can have duplicated address
properties, but the BriefIPAddressRequest
object only provides the address
field as reference key.
type BriefIPAddressRequest struct {
Address string `json:"address"`
Description *string `json:"description,omitempty"`
AdditionalProperties map[string]interface{}
}
Deployment Type
Self-hosted
NetBox Version
v4.1.3
Python Version
3.12
Steps to Reproduce
Access the NetBox REST API documentation generated from the OpenAPI specification (e.g.,
/api/schema/swagger-ui/
).Navigate to the API endpoint for creating a new device (
POST /api/dcim/devices/
).Review the schema for the request body in the OpenAPI specification.
Observe that foreign key fields, such as
device_role
,device_type
,site
, etc., are defined as requiring nested objects with specific attributes.Attempt to create a new device by specifying related objects using numeric IDs in the request body:
Expected Behavior
According to the NetBox documentation under the "Related Objects" section:
When performing write API actions (POST, PUT, and PATCH), related objects may be specified by either numeric ID (primary key) or by a set of attributes sufficiently unique to return the desired object.
For example, creating a new device by specifying its rack using a numeric ID should be acceptable:
The OpenAPI specification should reflect this flexibility, allowing foreign key fields to accept either a numeric ID or a nested object with unique attributes.
Client code generated from the OpenAPI schema should support specifying related objects using numeric IDs, resulting in concise and manageable code, especially in statically typed languages.
Observed Behavior
The OpenAPI specification only allows for specifying related objects as nested objects with specific attributes and does not provide the option to use numeric IDs.
Client code generated from the OpenAPI schema enforces the use of verbose nested objects for related fields, leading to cumbersome and less maintainable code.
This discrepancy between the documentation and the OpenAPI specification creates confusion and hinders the development of client applications, particularly in statically typed languages like Go.
For example, in Go, creating a device requires constructing nested objects for each related field: