[英]Swagger-php with Swagger-ui not working with Basic Authentication
[英]Swagger-PHP for generating JSON file for Swagger-UI
我正在尝试使用Swagger-PHP生成JSON文件,以便我可以将它与Swagger-UI一起用于自动文档。
我试过这个链接: - https://github.com/zircote/swagger-php
此外,我尝试在http://zircote.com/swagger-php/installation.html上处理文档
但我的运气不好,我无法实现它。
我能够正确安装composer。 此外,正确安装了Swagger-PHP捆绑包。
但问题是我无法使用/理解他们提供的测试示例。
所以,如果有人在处理它,请帮助!
提前致谢 !!
您只需在代码中添加注释aka注释,模型示例:
/**
* @SWG\Model(
* id="vps",
* required="['type', 'hostname']",
* @SWG\Property(name="hostname", type="string"),
* @SWG\Property(name="label", type="string"),
* @SWG\Property(name="type", type="string", enum="['vps', 'dedicated']")
* )
*/
class HostVps extends Host implements ResourceInterface
{
// ...
}
控制器示例:
/**
* @SWG\Resource(
* basePath="http://skyapi.dev",
* resourcePath="/vps",
* @SWG\Api(
* path="/vps",
* @SWG\Operation(
* method="GET",
* type="array",
* summary="Fetch vps lists",
* nickname="vps/index",
* @SWG\Parameter(
* name="expand",
* description="Models to expand",
* paramType="query",
* type="string",
* defaultValue="vps,os_template"
* )
* )
* )
* )
*/
class VpsController extends Controller
{
// ...
}
然后在控制台中:
php swagger.phar ./your-code-source/ -o ./directory-for-output-files
然后在Swagger UI中链接生成的文件。 这有帮助吗?
顺便说一下,这个文档:http: //zircote.com/swagger-php/annotations.html是不完整的。 最好依赖解析器错误,例如:
php swagger.phar ./skynode-api/api/ -o ./foo
Swagger-PHP 0.9.0
-----------------
[INFO] Skipping unsupported property: "foo" for @Swagger\Annotations\Property, expecting "name", "description", "type", "format", "items", "uniqueItems", "required", "minimum", "maximum", "enum", "defaultValue", "_partialId", "_partials" in HostVps in /home/kane/some-dir/some-file.php on line 3
编辑 :Swagger 2.0 在GitHub上有很好的规范
顺便说一下,考虑使用Swagger Editor来创建在Swagger UI中使用的api规范文件(json / yaml)。 导致php文件中的内联SWG文档非常难看,并且您在IDE中没有自动完成支持。
我最近在这个问题上苦苦挣扎,看到了一些差异,并设法让它发挥作用,并希望也可能将其他人改为:
// In the controller
/**
* (other swagger stuff like @SWG\Put, etc...)
* @SWG\Parameter(name="type",in="path",description="project|task",
* required=true, type="array",
* @SWG\Items(type="string"),
* default="project",
* enum={"project", "task"}),
* (next @SWG\Parameter or closing paran, etc)
*/
我以前在模型中使用枚举和@SWG \\ Items引用它,但没有保存那些代码(我只是搞乱了),我无法取回它。 我甚至看到我之前提出过问题并接受了答案! 但是上面是我现在能够让它工作的唯一方法,而且总比没有好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.