Add Postman Collection v2.1 export command#3
Conversation
Adds `apicli export postman` to convert stored requests to a Postman Collection JSON file that can be imported directly into Postman. Supports three modes: - Export all collections (default) - Export a specific collection: --collection <name> - Export request history: --history Output goes to stdout by default; use --output <file> to write to a file. URLs are fully parsed into Postman's structured format (protocol, host, path segments, query params). Request bodies are auto-detected as JSON. https://claude.ai/code/session_01PyL8EW4HoiuaCszqviyfGt
PR Review: Add Postman Collection v2.1 export commandOverall the implementation is clean and well-structured. Good separation of concerns across the builder functions, proper error handling with Bugs / Correctness1. Both flags can be passed simultaneously ( if collectionName != "" && exportHistory {
format.PrintError("--collection and --history are mutually exclusive")
os.Exit(1)
}2. Strings like func isJSON(s string) bool {
return json.Valid([]byte(strings.TrimSpace(s)))
}3. All collections are flattened in When exporting multiple collections, all requests are merged into a single flat list — collection names are lost. Postman v2.1 supports folder items ( type postmanItem struct {
Name string `json:"name"`
Request *postmanRequest `json:"request,omitempty"` // nil for folders
Items []postmanItem `json:"item,omitempty"` // non-nil for folders
}Then each collection becomes a folder item containing its requests. Code Quality4. Use
postmanCmd.Flags().Bool("history", false, "Export request history instead of collections")5. Non-deterministic header ordering Iterating over keys := make([]string, 0, len(headers))
for k := range headers { keys = append(keys, k) }
sort.Strings(keys)
for _, k := range keys {
pHeaders = append(pHeaders, postmanHeader{Key: k, Value: headers[k]})
}6. The logic that picks the single collection's name when there's exactly one collection ( Test CoverageNo tests are included. At minimum, consider adding unit tests for:
Minor
|
Adds
apicli export postmanto convert stored requests to a PostmanCollection JSON file that can be imported directly into Postman.
Supports three modes:
Output goes to stdout by default; use --output to write to a file.
URLs are fully parsed into Postman's structured format (protocol, host,
path segments, query params). Request bodies are auto-detected as JSON.
https://claude.ai/code/session_01PyL8EW4HoiuaCszqviyfGt