-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generation of the API documentation #2929
Conversation
Interesting! I don't have a much time at the moment, but please leave this with me and I'll take a look when I can. Perhaps @joecohens could help out here? |
I'm glad to know you are interested! I understand that you haven't lot of time, when you'll have a moment to touch that you can leave a comment here, I'm available if some modifications are needed. For the documentation I've set doc blocks above the API methods by mixing the content of the online documentation an what I've found in the code. If there are some elements that are missing or wrong I'll update them. |
I've just checked the branch out and it generated really nicely. I'd be keen on keeping documentation in sync with the hosted docs though. Is there something we could do to sync with https://readme-sync.readme.io/docs/full-example? |
It seems readme.io uses the ApiDoc standard. So I could update some things in the doc blocks in order to use ApiDoc instead. If so, the only thing to so would be generating the file |
I think that Readme feature using apiDoc is kind of stale, but we could do it using swagger https://readme.readme.io/docs/swagger-1 |
It may be a good idea, Swagger is a well known standard. I know the package DarkaOnLine/L5-Swagger that generates Swagger from php doc, but it's compatible with PHP >= 7.1, do you know an other package that is compatible with PHP >=5.6? |
61d3359
to
0968585
Compare
I don't sorry, are any of their older versions compatible? Do we need to support older versions of PHP to generate documentation though? |
An older version of the package (4.0 I think) is compatible with our version of PHP. But as said in the associated issue, should we write all the Swagger, or may a part be generated using the Laravel's routes? |
We could write Swagger but that means it'll be out of date in two places potentially. |
Yes that's the problem, we could write Swagger ourselves ignoring Laravel's routes, but the problem is we could be outdated in the swagger. It's the same. |
0968585
to
f40ff08
Compare
http://blog.cjwfuller.com/2015/05/30/swaggervel/ Does this help? |
@jbrooksuk as you can see in the "Controller Annotation" section, the path is in the doc block.
The |
f40ff08
to
8e58928
Compare
432bbd2
to
9070d5a
Compare
Wow, lots of changes here, awesome! |
Yes I have not finishes yet! But it's in progress. I'll try to finish that this weekend. |
919fe65
to
153fb9a
Compare
The API action's parameters are listed in a table in doc blocks, but the information about if a parameter was required or not was not in the table. The information is now present in the table.
The doc blocks above every method describe the parameter the API takes. It aims to replace the hand-written API documentation.
When generating the API documentation, the package uses doc blocks to show texts, parameters and so on. The doc blocks can contain markdown text. Because the text had some issues, mainly about tables, these issues were fixed.
A generated API documentation was added, so instead of viewing an out of date documentation on the Web it's possible to manually generate the API documentation. The documentation is generated under public/docs, so to prevent the committing of a documentation this directory is added to the ignore list.
Some documentation was added onto the API controllers, but it was not following any ruled or standard. Using 'DarkaOnLine/L5-Swagger', Swagger annotations are added and can be generated into the 'storage/' directory. For now, only the ComponentController has annotations about API. The AbstractApiController only has only common Swagger annotation like the version and the name. To set the API host, copy the file 'config/swagger-constants.php.dist' to 'config/swagger-constants.php' and set the constant 'API_HOST'. See: cachethq/docs#4
Also complete annotation for the 'index' method, about 'sort', 'per_page' and 'order'. See: cachethq/docs#4
The Swagger annotations have been added for the ComponentGroupController to explain what is taken as parameter, what is returned. See: cachethq/docs#4
Swagger annotations were added on IncidentController. Also a typo has been fixed ComponentControlelr. See: cachethq/docs#4
Swagger annotations were added on IncidentUpdatesController. See: cachethq/docs#4
153fb9a
to
ff25ab8
Compare
Thanks for the PR @anthonybocci. Is this PR complete now? Is there anything outstanding we need to look at? Also, can I ask why autopresenter has been removed? |
@GrahamCampbell this pull is old now, but I just checked and some controllers are not annotated so it's not finished. I'd a bit forgotten this to be honest. I have to finish it. For autopresenter, I don't know. I don't know what it is really. What is it doing? |
Autopresenter is heavily used in the views. All models are replaced with their presented versions in the environment for view rendering. |
Ok I understand what it is and why it's useful. I don't remember removing it. It's probably a mistake. |
@anthonybocci are you happy if we close this and go down the manual route for now? |
@jbrooksuk Yes you can. I am overwhelmed these times so I didn't finish this issue. |
The online documentation seems to be out of date and as a developer it is difficult to think about update the online documentation at the same time as developing an API method. An other problem with the online documentation is that it is required to have an Internet connection to view it, so when developing in a train or something it's not possible to see the documentation. The documentation is the subject of #2903
The ideal would be to be able to generate the documentation when we need it. Doing so, we will be able to generate our own documentation on our local machine during development, and it doesn't prevent an online documentation that may be updated more frequently and more easily.
To do so I've included the mpociot/laravel-apidoc-generator package that generates the API documentation using the routes and the doc blocks. So, a developer updating the API only has to update the doc block.
To generate the documentation you can execute the command
php artisan api:generate --routePrefix="api/v1/*"