|
| 1 | +package netbox |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/fbreckle/go-netbox/netbox/client/wireless" |
| 5 | + "github.com/go-openapi/runtime" |
| 6 | + "github.com/go-openapi/strfmt" |
| 7 | + "github.com/go-viper/mapstructure/v2" |
| 8 | +) |
| 9 | + |
| 10 | +type wirelessInterceptWriter struct { |
| 11 | + runtime.ClientRequest |
| 12 | + fields map[string]any |
| 13 | +} |
| 14 | + |
| 15 | +func (iw wirelessInterceptWriter) SetBodyParam(p any) error { |
| 16 | + out := make(map[string]any) |
| 17 | + dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{ |
| 18 | + TagName: "json", |
| 19 | + Result: &out, |
| 20 | + }) |
| 21 | + if err != nil { |
| 22 | + return err |
| 23 | + } |
| 24 | + if err := dec.Decode(p); err != nil { |
| 25 | + return err |
| 26 | + } |
| 27 | + for fieldName, value := range iw.fields { |
| 28 | + out[fieldName] = value |
| 29 | + } |
| 30 | + return iw.ClientRequest.SetBodyParam(out) |
| 31 | +} |
| 32 | + |
| 33 | +type wirelessInterceptParams struct { |
| 34 | + inner runtime.ClientRequestWriter |
| 35 | + fields map[string]any |
| 36 | +} |
| 37 | + |
| 38 | +func (ip wirelessInterceptParams) WriteToRequest(req runtime.ClientRequest, reg strfmt.Registry) error { |
| 39 | + writer := wirelessInterceptWriter{ClientRequest: req, fields: ip.fields} |
| 40 | + return ip.inner.WriteToRequest(writer, reg) |
| 41 | +} |
| 42 | + |
| 43 | +func hackSerializeWirelessWithValues(fields map[string]any) wireless.ClientOption { |
| 44 | + overrideFields := make(map[string]any, len(fields)) |
| 45 | + for fieldName, value := range fields { |
| 46 | + overrideFields[fieldName] = value |
| 47 | + } |
| 48 | + return func(co *runtime.ClientOperation) { |
| 49 | + originalParams := co.Params |
| 50 | + co.Params = wirelessInterceptParams{inner: originalParams, fields: overrideFields} |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +func hackSerializeWirelessAsNull(fields ...string) wireless.ClientOption { |
| 55 | + overrideFields := make(map[string]any, len(fields)) |
| 56 | + for _, field := range fields { |
| 57 | + overrideFields[field] = nil |
| 58 | + } |
| 59 | + return hackSerializeWirelessWithValues(overrideFields) |
| 60 | +} |
0 commit comments