netbox-openapi 0.6.0

low level netbox bindings (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
Documentation
//! Generic foreign-key fields, derived from the NetBox OpenAPI schema.
//! Auto-generated by `scripts/generate.sh` - do not edit.

/// How a generic foreign key is encoded in a NetBox write payload.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GenericFkEncoding {
    /// A single nested `{ "object_type": ..., "object_id": ... }`.
    Nested,
    /// An array of nested `{ "object_type": ..., "object_id": ... }`.
    NestedList,
    /// A sibling scalar pair: a `<field>_type` content type and a `<field>_id`.
    Split,
}

/// `(app_label.model, field, encoding)` for every generic foreign key in the
/// NetBox write API. `field` is the logical base name; for `Split` it expands to
/// `<field>_type` and `<field>_id` on the wire, otherwise it is the property
/// carrying the (array of) `GenericObjectRequest`.
pub const GENERIC_FK_FIELDS: &[(&str, &str, GenericFkEncoding)] = &[
    (
        "circuits.circuitgroupassignment",
        "member",
        GenericFkEncoding::Split,
    ),
    (
        "circuits.circuittermination",
        "termination",
        GenericFkEncoding::Split,
    ),
    (
        "dcim.cable",
        "a_terminations",
        GenericFkEncoding::NestedList,
    ),
    (
        "dcim.cable",
        "b_terminations",
        GenericFkEncoding::NestedList,
    ),
    ("dcim.inventoryitem", "component", GenericFkEncoding::Split),
    (
        "dcim.inventoryitemtemplate",
        "component",
        GenericFkEncoding::Split,
    ),
    (
        "dcim.macaddress",
        "assigned_object",
        GenericFkEncoding::Split,
    ),
    ("extras.bookmark", "object", GenericFkEncoding::Split),
    (
        "extras.eventrule",
        "action_object",
        GenericFkEncoding::Split,
    ),
    ("extras.imageattachment", "object", GenericFkEncoding::Split),
    (
        "extras.journalentry",
        "assigned_object",
        GenericFkEncoding::Split,
    ),
    ("extras.notification", "object", GenericFkEncoding::Split),
    ("extras.subscription", "object", GenericFkEncoding::Split),
    (
        "ipam.fhrpgroupassignment",
        "interface",
        GenericFkEncoding::Split,
    ),
    (
        "ipam.ipaddress",
        "assigned_object",
        GenericFkEncoding::Split,
    ),
    ("ipam.prefix", "scope", GenericFkEncoding::Split),
    ("ipam.service", "parent_object", GenericFkEncoding::Split),
    ("ipam.vlangroup", "scope", GenericFkEncoding::Split),
    (
        "tenancy.contactassignment",
        "object",
        GenericFkEncoding::Split,
    ),
    ("virtualization.cluster", "scope", GenericFkEncoding::Split),
    (
        "vpn.l2vpntermination",
        "assigned_object",
        GenericFkEncoding::Split,
    ),
    (
        "vpn.tunneltermination",
        "termination",
        GenericFkEncoding::Split,
    ),
    ("wireless.wirelesslan", "scope", GenericFkEncoding::Split),
];

/// Returns the [`GenericFkEncoding`] for `field` on `model` (keyed as
/// `app_label.model`, e.g. `"dcim.cable"`) if it is a generic foreign key.
pub fn generic_fk_encoding(model: &str, field: &str) -> Option<GenericFkEncoding> {
    GENERIC_FK_FIELDS
        .iter()
        .find(|(m, f, _)| *m == model && *f == field)
        .map(|(_, _, enc)| *enc)
}

/// Returns `true` if `field` on `model` is a generic foreign key whose value
/// must be encoded as a content-type reference rather than a bare id.
pub fn is_generic_fk(model: &str, field: &str) -> bool {
    generic_fk_encoding(model, field).is_some()
}