Build Swagger UI under thinkphp

Source: Internet
Author: User

As a background developer, always avoid to the app to write API interface documents, previously used HTML5 and Css3+jqury to write dynamic pages, but each time the change is cumbersome, and it is possible to change the code forgot to modify the document, so on the Internet to find some information, found swagger UI This framework everyone is more recommended, now record the setting of the environment.
The swagger UI is also based on Html+javascript implementations, and enables the ability of online testing to allow developers and testers to test and view the result information of interface calls.
Install the swagger UI in the Ubuntu14.04 and thinkphp frameworks:

     1. $ cd/var/www/api
     2. Install composer
         $ apt-get Update
         $ curl-ss https://getcomposer.org/installer | php
         $/usr/bin/php composer.phar--version
         $ sudo mv Composer.phar/usr/local/bin/composer
         $ composer-version
         appears with the following information to prove the installation was successful

3. Install swagger-php
    $ composer require zircote/swagger-php
    $ composer global require zircote/swagger-php
At this time in the API folder will generate a vendor folder, said the installation successfully downloaded Swagger UI file: Https://github.com/swagger-api/swagger-ui download successfully can be placed into the custom directory, Note The directory can access the

Modify the Index.html page in the Dist directory

To modify the generated JSON file path, don't worry. Here's how to generate the JSON file. I am in the API folder, the new Swagger-docs folder, and then run the command

    $ php/var/www/api/vendor/zircote/swagger-php/bin/swagger/var/www/api/vendor/zircote/swagger-php/examples-o/var/ Www/api/swagger-docs/swagger.json

Access to the dist file below index.html OK

For information about how the JSON file is generated, refer to the file below the examples folder.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.