views:

214

answers:

2

OK I know there's PhpDocumentor for generating documentation from php code. It seems it hasnt been updated in a long time (but maybe they figure its mostly feature complete).

While this might be good for documenting things for other programmers, it doesn't seem well suited for documenting the external "API" of a web service. IE, if I've got a nice MVC structured project, PhpDocumentor might be great for documenting all the models and internal libraries and such for other developers on that project, but how do I document the web service it provides?

I am thinking something where you could document the methods on the controllers using tags like:

/**
 @service /device/add
 @access POST
 @return JSON 
*/

which in the generated docs would show that you need to do a POST request, it returns JSON data and the URL to access it is http://whatever.com/device/add. Obviously there would be a global config file for the documentation that defines what the base url is for these service calls.

At this point I am thinking I will just implement something myself using reflection on the phpdoc blocks (or using Annotations with the addendum library) and have the docs accessible dynamically right in the application.

A: 

I think what your asking (documenting an API (especially if its RESTful)) would be to use a WADL. Granted its not going to be generated from source (no tools for that in PHP), but a WADL is excellent for documenting a service.

You can have sample payloads in all sorts of media types, all the response codes and how you handle them -- really everything you need.

Mr-sk
That WADL stuff is interesting. I will look more into that. I'd like to see something that does WADL does using DocBlock comments in PHP, and a parser that produces documentation from those (and maybe WADL files too).
Greywire
I'm not sure WADL is the right thing here. WADL seems to be more about defining the web service in a way that can be used to generate code, rather than the other way around (code with comments that can generate documentation).I think what would be really cool is some kind of completely generic generator that lets you define whatever tags you want and provide handlers for those. This would play well with concepts like Annotations where you are making up your own types of tags (ie, the annotation means something to the code as well as to the documentation generator)
Greywire
+1  A: 

You might prefer DoxyGen (or PHPxRef) to PhpDocumentor .

"While this might be good for documenting things for other programmers, it doesn't seem well suited for documenting the external "API" of a web service".

Why not put DoxyGen (or whatever) comments only into the API functions which are externally visible?

Give a description of each and use @param [in], @param [out] and @return.

Wouldn't that achieve what you want? Or did I miss something?

Mawg
Because I also want to document the internal stuff for other programmers (not to mention myself)...
Greywire
yes, I understood that. But if you add comments *only* for the interaces, and then run DoxyGen, then you have generated interface docs which you can give to others.Wouldn't taht work?
Mawg
I'm not sure what you mean by comments only for the interfaces?If you mean, document the controller methods as the external service calls, and the models as internal, that wont work in my design because there is a generic controller for standard CRUD operations on any model, so the only place to document is in the model method (I am also using annotations to define the db access for the model, etc).
Greywire
Now that I've sat down to work on this, I tried just using the @param tags to document the POST variables that a method accepts through the web interface. Problem here is that phpDocumentor assumes these are arguments to that method, and so thats what the docs show, which is wrong. I was also thinking I could use @link to show what the actual URL would look like, but its kinda confusing in the generated docs.
Greywire