Skip to main content

netbox_openapi/
generic_fk.rs

1//! Generic foreign-key fields, derived from the NetBox OpenAPI schema.
2//! Auto-generated by `scripts/generate.sh` - do not edit.
3
4/// How a generic foreign key is encoded in a NetBox write payload.
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum GenericFkEncoding {
7    /// A single nested `{ "object_type": ..., "object_id": ... }`.
8    Nested,
9    /// An array of nested `{ "object_type": ..., "object_id": ... }`.
10    NestedList,
11    /// A sibling scalar pair: a `<field>_type` content type and a `<field>_id`.
12    Split,
13}
14
15/// `(app_label.model, field, encoding)` for every generic foreign key in the
16/// NetBox write API. `field` is the logical base name; for `Split` it expands to
17/// `<field>_type` and `<field>_id` on the wire, otherwise it is the property
18/// carrying the (array of) `GenericObjectRequest`.
19pub const GENERIC_FK_FIELDS: &[(&str, &str, GenericFkEncoding)] = &[
20    (
21        "circuits.bulkcircuitgroupassignment",
22        "member",
23        GenericFkEncoding::Split,
24    ),
25    (
26        "circuits.bulkcircuittermination",
27        "termination",
28        GenericFkEncoding::Split,
29    ),
30    (
31        "circuits.circuitgroupassignment",
32        "member",
33        GenericFkEncoding::Split,
34    ),
35    (
36        "circuits.circuittermination",
37        "termination",
38        GenericFkEncoding::Split,
39    ),
40    (
41        "dcim.bulkcable",
42        "a_terminations",
43        GenericFkEncoding::NestedList,
44    ),
45    (
46        "dcim.bulkcable",
47        "b_terminations",
48        GenericFkEncoding::NestedList,
49    ),
50    (
51        "dcim.bulkinventoryitem",
52        "component",
53        GenericFkEncoding::Split,
54    ),
55    (
56        "dcim.bulkinventoryitemtemplate",
57        "component",
58        GenericFkEncoding::Split,
59    ),
60    (
61        "dcim.bulkmacaddress",
62        "assigned_object",
63        GenericFkEncoding::Split,
64    ),
65    (
66        "dcim.cable",
67        "a_terminations",
68        GenericFkEncoding::NestedList,
69    ),
70    (
71        "dcim.cable",
72        "b_terminations",
73        GenericFkEncoding::NestedList,
74    ),
75    ("dcim.inventoryitem", "component", GenericFkEncoding::Split),
76    (
77        "dcim.inventoryitemtemplate",
78        "component",
79        GenericFkEncoding::Split,
80    ),
81    (
82        "dcim.macaddress",
83        "assigned_object",
84        GenericFkEncoding::Split,
85    ),
86    ("extras.bookmark", "object", GenericFkEncoding::Split),
87    ("extras.bulkbookmark", "object", GenericFkEncoding::Split),
88    (
89        "extras.bulkeventrule",
90        "action_object",
91        GenericFkEncoding::Split,
92    ),
93    (
94        "extras.bulkimageattachment",
95        "object",
96        GenericFkEncoding::Split,
97    ),
98    (
99        "extras.bulkjournalentry",
100        "assigned_object",
101        GenericFkEncoding::Split,
102    ),
103    (
104        "extras.bulknotification",
105        "object",
106        GenericFkEncoding::Split,
107    ),
108    (
109        "extras.bulksubscription",
110        "object",
111        GenericFkEncoding::Split,
112    ),
113    (
114        "extras.eventrule",
115        "action_object",
116        GenericFkEncoding::Split,
117    ),
118    ("extras.imageattachment", "object", GenericFkEncoding::Split),
119    (
120        "extras.journalentry",
121        "assigned_object",
122        GenericFkEncoding::Split,
123    ),
124    ("extras.notification", "object", GenericFkEncoding::Split),
125    ("extras.subscription", "object", GenericFkEncoding::Split),
126    (
127        "ipam.bulkfhrpgroupassignment",
128        "interface",
129        GenericFkEncoding::Split,
130    ),
131    (
132        "ipam.bulkipaddress",
133        "assigned_object",
134        GenericFkEncoding::Split,
135    ),
136    ("ipam.bulkprefix", "scope", GenericFkEncoding::Split),
137    (
138        "ipam.bulkservice",
139        "parent_object",
140        GenericFkEncoding::Split,
141    ),
142    ("ipam.bulkvlangroup", "scope", GenericFkEncoding::Split),
143    (
144        "ipam.fhrpgroupassignment",
145        "interface",
146        GenericFkEncoding::Split,
147    ),
148    (
149        "ipam.ipaddress",
150        "assigned_object",
151        GenericFkEncoding::Split,
152    ),
153    ("ipam.prefix", "scope", GenericFkEncoding::Split),
154    ("ipam.service", "parent_object", GenericFkEncoding::Split),
155    ("ipam.vlangroup", "scope", GenericFkEncoding::Split),
156    (
157        "tenancy.bulkcontactassignment",
158        "object",
159        GenericFkEncoding::Split,
160    ),
161    (
162        "tenancy.contactassignment",
163        "object",
164        GenericFkEncoding::Split,
165    ),
166    (
167        "virtualization.bulkcluster",
168        "scope",
169        GenericFkEncoding::Split,
170    ),
171    ("virtualization.cluster", "scope", GenericFkEncoding::Split),
172    (
173        "vpn.bulkl2vpntermination",
174        "assigned_object",
175        GenericFkEncoding::Split,
176    ),
177    (
178        "vpn.bulktunneltermination",
179        "termination",
180        GenericFkEncoding::Split,
181    ),
182    (
183        "vpn.l2vpntermination",
184        "assigned_object",
185        GenericFkEncoding::Split,
186    ),
187    (
188        "vpn.tunneltermination",
189        "termination",
190        GenericFkEncoding::Split,
191    ),
192    (
193        "wireless.bulkwirelesslan",
194        "scope",
195        GenericFkEncoding::Split,
196    ),
197    ("wireless.wirelesslan", "scope", GenericFkEncoding::Split),
198];
199
200/// Returns the [`GenericFkEncoding`] for `field` on `model` (keyed as
201/// `app_label.model`, e.g. `"dcim.cable"`) if it is a generic foreign key.
202pub fn generic_fk_encoding(model: &str, field: &str) -> Option<GenericFkEncoding> {
203    GENERIC_FK_FIELDS
204        .iter()
205        .find(|(m, f, _)| *m == model && *f == field)
206        .map(|(_, _, enc)| *enc)
207}
208
209/// Returns `true` if `field` on `model` is a generic foreign key whose value
210/// must be encoded as a content-type reference rather than a bare id.
211pub fn is_generic_fk(model: &str, field: &str) -> bool {
212    generic_fk_encoding(model, field).is_some()
213}