Swagger docs in ZF2 with examples – Part 2: Swagger UI

This blog post on Swagger UI is a follow-up on my recent post on Swagger annotation parsing in ZF2. If you’re not already set up with Swagger annotation parsing in you ZF2 app I recommend that you read part 1 first.

In the last post we got ZF2 set up with annotation parsing and everything, and the only thing missing was Swagger UI for the neat presentation. I skipped that previosly but today we’ll add the last piece.

Entry image

To make things really easy I’ve packaged Swagger UI as a ZF2 module and submitted it to packagist. Just add

…to your composer.json file and do a “composer update” and enable the module in your ZF2 application by adding “SwaggerUI” to the modules array. The last thing to do then is to add a symlink for the public assets needed for the SwaggerUI documentation viewer;

That’s it! Given that you haven’t changed the route for SwaggerModule (the module we added in the previous blog post to utilize Swagger-PHP in a ZF2 app) the nice Swagger UI docs should now be visible at [ZF2-app-root]/api/swagger.

If your Swagger JSON files is located somewhere else than the default location (/api/docs), you will need to copy the swagger-ui.global.php.dist into you config/autoloads folder, remove the dist extension and set the correct path or URL to where you’ve put them.

Once again: happy documenting!

Published 2014-03-06