1

lets say I have this:

https://api.apis.guru/v2/specs/adyen.com/CheckoutService/64/openapi.json

and I want to grab:

/orders
/orders/cancel
/originKeys
/paymentLinks
/paymentLinks/{linkId}
/paymentMethods
/paymentMethods/balance
/paymentSession
/payments
/payments/details
/payments/result

I want to do that on an elegant way, just grabbing the paths, what I am doing is this ugly workaround, that doesn't work well with some apis:

curl -A "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:86.0) Gecko/20100101 Firefox/86.0" -ks "https://api.apis.guru/v2/specs/adyen.com/CheckoutService/64/openapi.json"  | jq -r '.paths' | grep "/" | grep "{" | egrep -iv "microsoft|amz|application/json|application/jwt|\*|text/xml|text/plain|application/|multipart/form-data|text/html" | cut -d "\"" -f 2
aDoN
  • 1,877
  • 4
  • 39
  • 55

1 Answers1

2

Using jq:

$ jq -r '.paths | keys | .[]' openapi.json
/orders
/orders/cancel
/originKeys
/paymentLinks
/paymentLinks/{linkId}
/paymentMethods
/paymentMethods/balance
/paymentSession
/payments
/payments/details
/payments/result

In your case, you'd want to pipe your curl output to jq instead of using a file, of course.

The import bits compared to your use of jq is piping the .paths array to keys and that to .[] to get one element per line instead of a JSON array, and -r to avoid printing each line as a JSON string complete with quote marks.

Shawn
  • 47,241
  • 3
  • 26
  • 60