Skip to content

Instantly share code, notes, and snippets.

@peterjaap
Last active December 5, 2019 22:04
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterjaap/85952d87f4d46df7ca1724b75f917a1e to your computer and use it in GitHub Desktop.
Save peterjaap/85952d87f4d46df7ca1724b75f917a1e to your computer and use it in GitHub Desktop.
Generate PHP client with Swagger for Magento 2 including private endpoints (make sure you have the Swagger modules installed & enabled)
#!/bin/bash
SHOP_URL=https://yourshop.url
ADMIN_USERNAME=yourusername
ADMIN_PASSWORD=yourpassword
BEARER=$(curl -XPOST -H 'Content-Type: application/json' ${SHOP_URL}/index.php/rest/V1/integration/admin/token -d '{ "username": "${ADMIN_USERNAME}", "password": "${ADMIN_PASSWORD}" }')
curl -XGET -H "Authorization: Bearer ${BEARER}" ${SHOP_URL}/rest/default/schema?services=all | tee swagger.json
docker run --rm -v ${PWD}:/local swaggerapi/swagger-codegen-cli generate -i /local/swagger.json -l php -o /local/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment