Skip to content

Commit d50cafe

Browse files
authored
Differentiate postman folder from request when at collection root (#3912)
* Modified scanItem to keep track of parent folder and eliminate folder info being identical to request info * Use UID for parent ID and request ID for consistency * Updated description of UID * Added commentary for parent folder ID business
1 parent 709cd08 commit d50cafe

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

pkg/sources/postman/postman.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -329,16 +329,15 @@ func (s *Source) scanCollection(ctx context.Context, chunksChan chan *sources.Ch
329329
}
330330

331331
for _, item := range collection.Items {
332-
s.scanItem(ctx, chunksChan, collection, metadata, item)
332+
s.scanItem(ctx, chunksChan, collection, metadata, item, "")
333333
}
334334

335335
}
336336

337-
func (s *Source) scanItem(ctx context.Context, chunksChan chan *sources.Chunk, collection Collection, metadata Metadata, item Item) {
337+
func (s *Source) scanItem(ctx context.Context, chunksChan chan *sources.Chunk, collection Collection, metadata Metadata, item Item, parentItemId string) {
338338
s.attemptToAddKeyword(item.Name)
339339

340340
// override the base collection metadata with item-specific metadata
341-
metadata.FolderID = item.ID
342341
metadata.Type = FOLDER_TYPE
343342
if metadata.FolderName != "" {
344343
// keep track of the folder hierarchy
@@ -353,13 +352,22 @@ func (s *Source) scanItem(ctx context.Context, chunksChan chan *sources.Chunk, c
353352
}
354353
// recurse through the folders
355354
for _, subItem := range item.Items {
356-
s.scanItem(ctx, chunksChan, collection, metadata, subItem)
355+
s.scanItem(ctx, chunksChan, collection, metadata, subItem, item.UID)
357356
}
358357

358+
// The assignment of the folder ID to be the current item UID is due to wanting to assume that your current item is a folder unless you have request data inside of your item.
359+
// If your current item is a folder, you will want the folder ID to match the UID of the current item.
360+
// If your current item is a request, you will want the folder ID to match the UID of the parent folder.
361+
// If the request is at the root of a collection and has no parent folder, the folder ID will be empty.
362+
metadata.FolderID = item.UID
359363
// check if there are any requests in the folder
360364
if item.Request.Method != "" {
361365
metadata.FolderName = strings.Replace(metadata.FolderName, (" > " + item.Name), "", -1)
362-
metadata.RequestID = item.ID
366+
metadata.FolderID = parentItemId
367+
if metadata.FolderID == "" {
368+
metadata.FolderName = ""
369+
}
370+
metadata.RequestID = item.UID
363371
metadata.RequestName = item.Name
364372
metadata.Type = REQUEST_TYPE
365373
if item.UID != "" {
@@ -381,14 +389,6 @@ func (s *Source) scanItem(ctx context.Context, chunksChan chan *sources.Chunk, c
381389
for _, event := range item.Events {
382390
s.scanEvent(ctx, chunksChan, metadata, event)
383391
}
384-
385-
if metadata.RequestID != "" {
386-
metadata.LocationType = source_metadatapb.PostmanLocationType_REQUEST_AUTHORIZATION
387-
} else if metadata.FolderID != "" {
388-
metadata.LocationType = source_metadatapb.PostmanLocationType_FOLDER_AUTHORIZATION
389-
} else if metadata.CollectionInfo.UID != "" {
390-
metadata.LocationType = source_metadatapb.PostmanLocationType_COLLECTION_AUTHORIZATION
391-
}
392392
// an auth all by its lonesome could be inherited to subfolders and requests
393393
s.scanAuth(ctx, chunksChan, metadata, item.Auth, item.Request.URL)
394394
metadata.LocationType = source_metadatapb.PostmanLocationType_UNKNOWN_POSTMAN

pkg/sources/postman/postman_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ type Item struct {
109109
Request Request `json:"request,omitempty"`
110110
Response []Response `json:"response,omitempty"`
111111
Description string `json:"description,omitempty"`
112-
UID string `json:"uid,omitempty"` //Need to use this to get the collection via API
112+
UID string `json:"uid,omitempty"` //Need to use this to get the collection via API. The UID is a concatenation of the ID and the user ID of whoever created the item.
113113
}
114114

115115
type Auth struct {

0 commit comments

Comments
 (0)