When exporting a Postman Collection, the body of a request is stored in the "raw" property as a single string.
When using git diff
, it is hard to compare the changes because the whole line has changed.
It is possible to define in a .gitattributes file what diff driver to use. For every driver, a command can be specified that converts the input file before the LCS algorithm is executed. That is, we can use Git's feature of diffing but alter how the single lines are generated.
Note: The following snippets are written for Git on Windows machines.
In the first step, create a new "postman" diff driver by adding the following line to git config:
[diff "postman"]
textconv=jq \"(.item[].request.body?.raw | select (.)) |= (. | select ((. | length) > 0) | fromjson)\"
cachetextconv = true
You can also achieve this by running git config diff.postman.textconv "jq \"(.item[].request.body?.raw | select (.)) |= (. | select ((. | length) > 0) | fromjson)\""
and git config diff.postman.cachetextconv true
.
Specify the diff driver to use in the .gitattributes:
*.postman_collection.json diff=postman
Lastly, download jq and add it to the cmd folder in your Git directoy.