collectDeepAttrs takes either a single object or an array of objects and flattens it into a list of object attributes, collecting attributes from all of the objects in a given array. Ordering is preserved, so a list of objects that each have one property will result in those properties being return
(v node, labelName *string)
| 326 | // messages to refer to block labels rather than attributes and child blocks. |
| 327 | // It has no other effect. |
| 328 | func (b *body) collectDeepAttrs(v node, labelName *string) ([]*objectAttr, hcl.Diagnostics) { |
| 329 | var diags hcl.Diagnostics |
| 330 | var attrs []*objectAttr |
| 331 | |
| 332 | switch tv := v.(type) { |
| 333 | case *nullVal: |
| 334 | // If a value is null, then we don't return any attributes or return an error. |
| 335 | |
| 336 | case *objectVal: |
| 337 | attrs = append(attrs, tv.Attrs...) |
| 338 | |
| 339 | case *arrayVal: |
| 340 | for _, ev := range tv.Values { |
| 341 | switch tev := ev.(type) { |
| 342 | case *objectVal: |
| 343 | attrs = append(attrs, tev.Attrs...) |
| 344 | default: |
| 345 | if labelName != nil { |
| 346 | diags = append(diags, &hcl.Diagnostic{ |
| 347 | Severity: hcl.DiagError, |
| 348 | Summary: "Incorrect JSON value type", |
| 349 | Detail: fmt.Sprintf("A JSON object is required here, to specify %s labels for this block.", *labelName), |
| 350 | Subject: ev.StartRange().Ptr(), |
| 351 | }) |
| 352 | } else { |
| 353 | diags = append(diags, &hcl.Diagnostic{ |
| 354 | Severity: hcl.DiagError, |
| 355 | Summary: "Incorrect JSON value type", |
| 356 | Detail: "A JSON object is required here, to define arguments and child blocks.", |
| 357 | Subject: ev.StartRange().Ptr(), |
| 358 | }) |
| 359 | } |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | default: |
| 364 | if labelName != nil { |
| 365 | diags = append(diags, &hcl.Diagnostic{ |
| 366 | Severity: hcl.DiagError, |
| 367 | Summary: "Incorrect JSON value type", |
| 368 | Detail: fmt.Sprintf("Either a JSON object or JSON array of objects is required here, to specify %s labels for this block.", *labelName), |
| 369 | Subject: v.StartRange().Ptr(), |
| 370 | }) |
| 371 | } else { |
| 372 | diags = append(diags, &hcl.Diagnostic{ |
| 373 | Severity: hcl.DiagError, |
| 374 | Summary: "Incorrect JSON value type", |
| 375 | Detail: "Either a JSON object or JSON array of objects is required here, to define arguments and child blocks.", |
| 376 | Subject: v.StartRange().Ptr(), |
| 377 | }) |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | return attrs, diags |
| 382 | } |
| 383 | |
| 384 | func (e *expression) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) { |
| 385 | switch v := e.src.(type) { |
no test coverage detected