VGTech is a blog where the developers and devops of Norways most visited website share code and tricks of the trade… Read more



Are you brilliant? We're hiring. Read more

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

PHP

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.

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

Show code
"kbrabrand/zf2-swagger-ui": "dev-master"

…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;

Show code
cd [ZF2-app-root]/public && ln -s ../vendor/kbrabrand/zf2-swagger-ui/public swagger-ui

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!

PHP. Javascript. Squash. @kbrabrand


1 comments

Leave your comment