daodao97 / apidog Goto Github PK
View Code? Open in Web Editor NEWApi Watch Dog, Hyperf 框架的 Api参数校验 和 swagger 生成组件
License: MIT License
Api Watch Dog, Hyperf 框架的 Api参数校验 和 swagger 生成组件
License: MIT License
如何验证三个字段中只能有一个字段不为空谢谢您
通过自定义的方式, 添加了验证规则, 在 Request 中是有效的, 但是在使用了 APIDOG 的时候, 会提示规则不存在
apidog/src/Annotation/Param.php
Lines 35 to 40 in 32be225
此处的 required
判定是否加上 |
符号比较好?因为像 required_if
之类的规则,会在 swagger-ui 前端就被拦截提交,不好做测试。不知 swagger 是否能实现这种关联检测的判定。
如果想对参数某一规则做地定义错误描述,是否只能通过callback的方式来检验?如 required
规则,我希望只提示说 参数错误 而不提示具体的字段名称。
这个api注解支持多server吗,在@APIController(server="")好像没用啊
在demo中,对于传入的header注解:@Header(key="token|接口访问凭证", rule="required")。当进行header规则验证的时候,会将该key的首字符大写。
ValidationApi.php:128
$real_headers[implode('-', array_map('ucfirst', explode('-', $key)))] = $val;
因此注解中@Header(key="token|接口访问凭证", rule="required") 如果首字母是小写的,会报错:
[ERROR] 接口访问凭证 字段是必须的[69] in /var/workspace/hyperf-skeleton/vendor/daodao97/apidog/src/Middleware/ApiValidationMiddleware.php.
原因是token首字母是小写,所以找不到。
综上:
在注解header中,key的首字母必须大写。demo中是小写的。
怎么写上传文件的注解
你好大佬,目前想使用你得插件,遇到个问题,在@ApiResponse如何定义枚举型啊
错误提示信息怎么要做多语言,怎么实现啊
formdata时就不是。
apidog/src/Swagger/SwaggerJson.php
Line 73 in aaeb046
@APIController(prefix="/admin" 不起作用
// 当你有多个 http server 时, 可以在输出文件的名称中增加 {server} 字面变量
// 比如 /public/swagger/swagger_{server}.json
开启多服务时必须配置成 /public/swagger/swagger_{server}.json。每个服务会生成一次wagger.json,如果是/public/swagger/swagger.json,最后一次服务会覆盖掉之前的。
文档和发布自动生成的配置文件中都是
field_error_msg
源码里是
field_error_message
麻烦统一一下吧
/**
* @ApiServer(name="admin")
* @ApiController(prefix="admin/passport", tag="授权登录", server="admin")
* @Middleware(CorsMiddleware::class)
*/
测试,路由是生效的,但没有生成该控制器的API文档
看了一下代码,应该是只是生成了 http 的文档:
$router = $container->get(DispatcherFactory::class)->getRouter('http');
改成这样就可以了,希望修复一下:
/*$router = $container->get(DispatcherFactory::class)->getRouter('http');
$data = $router->getData();*/
$servers = $config->get('server.servers');
if (count($servers) > 1 && !Str::contains($output, '{server}')) {
$logger->warning('You have multiple serve, but your apidog.output_file not contains {server} var');
}
foreach ($servers as $server) {
$router = $container->get(DispatcherFactory::class)->getRouter($server['name']);
$data = $router->getData();
$swagger = new SwaggerJson($server['name']);
$ignore = $config->get('apidog.ignore', function ($controller, $action) {
return false;
});
array_walk_recursive($data, function ($item) use ($swagger, $ignore) {
if ($item instanceof Handler && !($item->callback instanceof \Closure)) {
[$controller, $action] = $this->prepareHandler($item->callback);
(!$ignore($controller, $action)) && $swagger->addPath($controller, $action);
}
});
$swagger->save();
}
PHP Fatal error: Uncaught ReflectionException: Method index does not exist in /home/vagrant/hyperf-test/vendor/hyperf/di/src/ReflectionManager.php:45
Stack trace:
#0 /home/vagrant/hyperf-test/vendor/hyperf/di/src/ReflectionManager.php(45): ReflectionClass->getMethod()
#1 /home/vagrant/hyperf-test/vendor/daodao97/apidog/src/ApiAnnotation.php(22): Hyperf\Di\ReflectionManager::reflectMethod()
#2 /home/vagrant/hyperf-test/vendor/daodao97/apidog/src/Swagger/SwaggerJson.php(76): Hyperf\Apidog\ApiAnnotation::methodMetadata()
#3 /home/vagrant/hyperf-test/vendor/daodao97/apidog/src/BootAppConfListener.php(63): Hyperf\Apidog\Swagger\SwaggerJson->addPath()
#4 [internal function]: Hyperf\Apidog\BootAppConfListener->Hyperf\Apidog{closure}()
#5 /home/vagrant/hyperf-test/vendor/daodao97/apidog/src/BootAppConfListener.php(65): array_walk_recursive()
#6 /home/vagrant/hyperf-test/vendor/hyperf/event/src/EventDispatcher.php(48): Hyperf\Apidog\BootAppConfListener->process()
#7 /home/vagrant/hyperf-test/vendor/hyperf/framework/src/ApplicationFac in /home/vagrant/hyperf-test/vendor/hyperf/di/src/ReflectionManager.php on line 45
@Header(key="Authorization|接口访问凭证", rule="required")
在有传Authorization的情况,依然会提示。原因是getHeaders会把得到key是小写
if ($header_rules) {
$headers = $request->getHeaders();
$headers = array_map(function ($item) {
return $item[0];
}, $headers);
[
$data,
$error,
] = $this->check($header_rules, $headers, $controllerInstance);
if ($data === null) {
return [
$field_error_code => $error_code,
$field_error_message => implode(PHP_EOL, $error),
];
}
}
一开始这个问题其实并不严重 但是当我需要使用中间件来通过token 验证用户时 发现了这个问题
`
/**
"token|token":"",
"exp|过期时间": 7200,
}
Router::post('/refresh_token', 'App\Controller\UserController@refreshToken', ['middleware' => $middleware]);
`
代码如上
错误信息:
PHP Fatal error: Uncaught FastRoute\BadRouteException: Cannot register two routes matching "/refresh_token" for method "POST" in /home/www/apitest.qiduo.net/vendor/nikic/fast-route/src/DataGenerator/RegexBasedAbstract.php:86
@Body(rules={
"apis": {"a","b","c"}
})
生成的swagger文档为
{ "apis": [{}] }
我希望的是
{ "apis": [""] }
UICommand -> handle->host=>127.0.0.1 文档启动外网无法访问 修改为0.0.0.0时 外网能访问 但是文档页面访问的0.0.0.0:9939/swagger.json 需要页面手动将0.0.0.0改成访问地址才能正常访问
public function __construct(ContainerInterface $container, HttpResponse $response, RequestInterface $request, ValidationApi $validation)
{
$this->container = $container;
$this->response = $response;
$this->request = $request;
$this->validationApi = $validation;
parent::__construct($container, 'http');
}
在方法里面写注解看着好难受
如题
/**
* @postapi(path="login", description="添加一个用户")
* @Header(key="token|接口访问凭证", rule="required")
* @formdata(key="username|用户名或者手机号", rule="required")
* @formdata(key="password|密码", rule="required")
* @ApiResponse(code="-1", description="参数错误")
* @ApiResponse(code="0", description="成功", schema={"id":1})
*/
请问可以对 ApiResponse 下schema 里面的值进行描述的么?谢谢
swagger是生成是有路由地址的,但是postman请求返回not found、
需要在config/routes.php 添加相同的路由 才可以请求
之前的1.6版本呢?现在1.5的consumes有点问题啊
UICommand.php中handle方法$host固定成127.0.0.1的话,docker容器无法启动
根据hyper文档写得自定义验证规则添加,识别不了
BadMethodCallException:Method Hyperf\Validation\Validator::validateFoo does not exist.(236) in /www/wwwroot/hyperf/vendor/hyperf/validation/src/Validator.php
环境:php7.4,hyperf 2.0.11 ,daodao97/apidog 1.5.17
按照部署文档:
请问这是为什么,谢谢!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.