@@ -154,15 +154,13 @@ type Component struct {
154154 Properties map [string ]interface {} `json:"properties"`
155155 Layer map [string ]interface {} `json:"layer"`
156156 Domain map [string ]interface {} `json:"domain"`
157- Environment map [string ]interface {} `json:"environment,omitempty"`
158157 Link string `json:"link"`
159158}
160159
161160type ComponentMetadata struct {
162161 ComponentTypes map [string ]string
163- Layers map [int64 ]string
164- Domains map [int64 ]string
165- Environments map [int64 ]string
162+ Layers map [string ]string
163+ Domains map [string ]string
166164}
167165
168166// handleSnapshotError checks if the response is a typed error by examining the _type discriminator
@@ -255,31 +253,20 @@ func parseSnapshotResponse(
255253// all metadata categories in a single loop.
256254var metadataFieldMapping = []struct {
257255 field string
258- setter func (* ComponentMetadata , interface {}) error
256+ setter func (* ComponentMetadata , interface {})
259257}{
260- {"componentTypes" , parseComponentTypesField },
261- {"layers" , func (m * ComponentMetadata , val interface {}) error {
262- m .Layers = parseMetadataField (val )
263- return nil
264- }},
265- {"domains" , func (m * ComponentMetadata , val interface {}) error {
266- m .Domains = parseMetadataField (val )
267- return nil
268- }},
269- {"environments" , func (m * ComponentMetadata , val interface {}) error {
270- m .Environments = parseMetadataField (val )
271- return nil
272- }},
258+ {"componentTypes" , func (m * ComponentMetadata , val interface {}) { m .ComponentTypes = parseMetadataByIdentifier (val ) }},
259+ {"layers" , func (m * ComponentMetadata , val interface {}) { m .Layers = parseMetadataByIdentifier (val ) }},
260+ {"domains" , func (m * ComponentMetadata , val interface {}) { m .Domains = parseMetadataByIdentifier (val ) }},
273261}
274262
275- // parseMetadata extracts component type, layer, domain, and environment metadata
263+ // parseMetadata extracts component type, layer, and domain metadata
276264// from the opaque Snapshot response using a table-driven approach.
277265func parseMetadata (respMap map [string ]interface {}) ComponentMetadata {
278266 metadata := ComponentMetadata {
279267 ComponentTypes : make (map [string ]string ),
280- Layers : make (map [int64 ]string ),
281- Domains : make (map [int64 ]string ),
282- Environments : make (map [int64 ]string ),
268+ Layers : make (map [string ]string ),
269+ Domains : make (map [string ]string ),
283270 }
284271
285272 metadataMap , ok := respMap ["metadata" ].(map [string ]interface {})
@@ -289,63 +276,32 @@ func parseMetadata(respMap map[string]interface{}) ComponentMetadata {
289276
290277 for _ , mapping := range metadataFieldMapping {
291278 if fieldValue , ok := metadataMap [mapping .field ]; ok {
292- mapping .setter (& metadata , fieldValue ) //nolint:errcheck
279+ mapping .setter (& metadata , fieldValue )
293280 }
294281 }
295282
296283 return metadata
297284}
298285
299- // parseComponentTypesField extracts component types from metadata, using identifier as key
300- func parseComponentTypesField (m * ComponentMetadata , metadataValue interface {}) error {
301- if metadataValue == nil {
302- return nil
303- }
304-
305- items , ok := metadataValue .([]interface {})
306- if ! ok {
307- return nil
308- }
309-
310- for _ , item := range items {
311- if itemMap , ok := item .(map [string ]interface {}); ok {
312- var key string
313- if identifier , ok := itemMap ["identifier" ].(string ); ok {
314- key = identifier
315- } else {
316- continue
317- }
318-
319- if name , ok := itemMap ["name" ].(string ); ok {
320- m .ComponentTypes [key ] = name
321- }
322- }
323- }
324-
325- return nil
326- }
327-
328- // parseMetadataField extracts id/name pairs from a metadata field.
329- // Each item in the slice should have "id" and "name" fields.
330- func parseMetadataField (metadataValue interface {}) map [int64 ]string {
331- result := make (map [int64 ]string )
286+ // parseMetadataByIdentifier extracts metadata items by identifier.
287+ func parseMetadataByIdentifier (metadataValue interface {}) map [string ]string {
288+ result := make (map [string ]string )
332289
333290 if metadataValue == nil {
334291 return result
335292 }
336293
337- // The JSON decoder produces []interface{} for arrays
338294 items , ok := metadataValue .([]interface {})
339295 if ! ok {
340296 return result
341297 }
342298
343299 for _ , item := range items {
344300 if itemMap , ok := item .(map [string ]interface {}); ok {
345- id , idOk := itemMap ["id " ].(float64 )
301+ identifier , idOk := itemMap ["identifier " ].(string )
346302 name , nameOk := itemMap ["name" ].(string )
347303 if idOk && nameOk {
348- result [int64 ( id ) ] = name
304+ result [identifier ] = name
349305 }
350306 }
351307 }
@@ -400,10 +356,9 @@ func parseComponentFromMap(compMap map[string]interface{}, metadata ComponentMet
400356 comp .Properties = propertiesRaw
401357 }
402358
403- // Parse layer, domain, and environment references
404- comp .Layer = parseComponentReference (compMap , "layer" , metadata .Layers )
405- comp .Domain = parseComponentReference (compMap , "domain" , metadata .Domains )
406- comp .Environment = parseComponentReference (compMap , "environment" , metadata .Environments )
359+ // Parse layer and domain references
360+ comp .Layer = parseComponentReference (compMap , "layerIdentifier" , metadata .Layers )
361+ comp .Domain = parseComponentReference (compMap , "domainIdentifier" , metadata .Domains )
407362
408363 // Build link
409364 if len (comp .Identifiers ) > 0 {
@@ -413,19 +368,18 @@ func parseComponentFromMap(compMap map[string]interface{}, metadata ComponentMet
413368 return comp
414369}
415370
416- // parseComponentReference extracts a reference field (layer, domain, or environment )
371+ // parseComponentReference extracts a reference field (layer or domain )
417372// from a component and looks up its name in the provided metadata map.
418- // Returns a map with "id" and "name" keys, or nil if the field is not present.
419- func parseComponentReference (compMap map [string ]interface {}, fieldName string , metadataMap map [int64 ]string ) map [string ]interface {} {
420- if refID , ok := compMap [fieldName ].(float64 ); ok {
421- refIDInt := int64 (refID )
373+ // Returns a map with "identifier" and "name" keys, or nil if the field is not present.
374+ func parseComponentReference (compMap map [string ]interface {}, identifierFieldName string , metadataMap map [string ]string ) map [string ]interface {} {
375+ if refIdentifier , ok := compMap [identifierFieldName ].(string ); ok {
422376 refName := "Unknown"
423- if name , found := metadataMap [refIDInt ]; found {
377+ if name , found := metadataMap [refIdentifier ]; found {
424378 refName = name
425379 }
426380 return map [string ]interface {}{
427- "id " : refIDInt ,
428- "name" : refName ,
381+ "identifier " : refIdentifier ,
382+ "name" : refName ,
429383 }
430384 }
431385 return nil
0 commit comments