在非oo项目上使用Swagger-PHP

时间:2014-08-21 06:58:50

标签: swagger swagger-php

目前,对于一个项目,我需要使用Swagger为它创建文档。由于项目是在php中完成的,我将使用Swagger-Php来注释代码并创建文档。现在我注意到,在所有示例项目中,它们都是面向对象的;换句话说,当发出请求时,会调用控制器,然后调用模型等。在我参与的项目中,项目没有这样组织:每个页面都有自己的文件,并负责该文件中的所有操作。我如何使用Swagger以这种方式记录代码?

例如,以下伪代码基本上是每个文件的作用:

<?php
    //get paramters
    //query database
    //return json file, either data or status of the operation
?>

我会这样做吗?

<?php
    /*
     * @SWG\Resource(
     * apiVersion="1.0",
     * basePath="http://url.com/exampleFile"
     * )
     * */
    /* @SWG\Api(
     * @SWG\Operation(
     * summary="Retreives data from database and prints out in json",
     * method="GET",
     * type="", // what would go here?
     * @SWG\Parameter(name="param1",type="string"),
     * @SWG\Parameter(name="param2",type="int")
     * )
     * )
     * */
     //How will I show example of json to be printed to the user?

    //get paramters
    //query database
    //return json file, either data or status of the operation
?>

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

几个月前我已经想到了这一点,但忘了更新这篇文章。面向对象的方法将自动为您创建带有注释的api。如果您不使用此方法,则在每个文件中,您必须手动添加所有内容,如上所示。