Skip to content
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

Closed
wants to merge 16 commits into from

Conversation

nalysius
Copy link
Contributor

@nalysius nalysius commented Mar 1, 2018

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/*"

@jbrooksuk
Copy link
Member

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?

@nalysius
Copy link
Contributor Author

nalysius commented Mar 1, 2018

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.

@jbrooksuk
Copy link
Member

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?

@nalysius
Copy link
Contributor Author

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 ./doc/api_data.json on the hosted doc.
It is pretty easy to do, I can do that it you're ok with that.

@joecohens
Copy link
Contributor

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

@nalysius
Copy link
Contributor Author

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?

@nalysius nalysius force-pushed the automatic-api-doc branch from 61d3359 to 0968585 Compare March 22, 2018 19:17
@jbrooksuk
Copy link
Member

I don't sorry, are any of their older versions compatible?

Do we need to support older versions of PHP to generate documentation though?

@nalysius
Copy link
Contributor Author

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?

@jbrooksuk
Copy link
Member

We could write Swagger but that means it'll be out of date in two places potentially.

@nalysius
Copy link
Contributor Author

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.
We aren't the firsts to use Swagger with Laravel, there is probably someone who uses Laravel's routes with Swagger in order to keep being synced.

@nalysius nalysius force-pushed the automatic-api-doc branch from 0968585 to f40ff08 Compare March 30, 2018 21:34
@jbrooksuk
Copy link
Member

http://blog.cjwfuller.com/2015/05/30/swaggervel/ Does this help?

@nalysius
Copy link
Contributor Author

@jbrooksuk as you can see in the "Controller Annotation" section, the path is in the doc block.

@SWG\Api(
    path="/animals",
    @SWG\Operation(
        method="GET",
	summary="Fetch animals"
    )
)

The /animals path is the URL. If in our Laravel's routes we update the route, the one configured above becomes wrong.
In an ideal world, the annotation in the php doc would look for the path in the Laravel's routes for the current controller/action/method.

@nalysius nalysius force-pushed the automatic-api-doc branch from f40ff08 to 8e58928 Compare April 1, 2018 20:46
@nalysius nalysius force-pushed the automatic-api-doc branch 2 times, most recently from 432bbd2 to 9070d5a Compare April 29, 2018 14:49
@jbrooksuk
Copy link
Member

Wow, lots of changes here, awesome!

@nalysius
Copy link
Contributor Author

Yes I have not finishes yet! But it's in progress. I'll try to finish that this weekend.

@nalysius nalysius force-pushed the automatic-api-doc branch 2 times, most recently from 919fe65 to 153fb9a Compare June 2, 2018 10:25
nalysius added 6 commits June 18, 2018 20:29
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.
nalysius added 10 commits June 18, 2018 20:29
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
@nalysius nalysius force-pushed the automatic-api-doc branch from 153fb9a to ff25ab8 Compare June 18, 2018 18:33
@GrahamCampbell
Copy link
Contributor

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?

@nalysius
Copy link
Contributor Author

@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?

@GrahamCampbell
Copy link
Contributor

Autopresenter is heavily used in the views. All models are replaced with their presented versions in the environment for view rendering.

@nalysius
Copy link
Contributor Author

Ok I understand what it is and why it's useful. I don't remember removing it. It's probably a mistake.

@jbrooksuk
Copy link
Member

@anthonybocci are you happy if we close this and go down the manual route for now?

@nalysius
Copy link
Contributor Author

nalysius commented Feb 2, 2019

@jbrooksuk Yes you can. I am overwhelmed these times so I didn't finish this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants