我目前正在通过Symfony (5.1)路由和NelmioApiDocBundle生成OpenAPI注释,
其中一条路由如下所示:
* @Route("/users/{id}", methods={"GET"}, requirements={"id": "\d+"})
* @OA\Parameter(name="id", in="path", description="The id of the user", required=true, @OA\Schema(type="integer"))和另一个类似的
* @Route("/users/followed", methods={"GET"})我正在使用联盟的PSR7消息验证器(https://github.com/thephpleague/openapi-psr7-validator),通过使用symfony/psr-http-message-bridge和nyholm/psr7将Symfony请求转换为OpenAPI -7请求。除了这两个端点之外,一切都运行得很好。我不断地得到
The given request matched these operations: [/api/users/{id},get],[/api/charter-calculations/followed,get]. However, it matched not a single schema of theirs.
有没有可能/followed只能与/{id}匹配?因此验证器会被弄糊涂?或者像我已经做过的那样,{id}的正则表达式是可能的吗?
发布于 2020-09-28 22:48:11
想明白了,所以回答我自己。它在某种程度上针对我的问题,但可能对其他人有帮助。
我有一些额外的参数,比如
* @OA\Parameter(name="pageSize", in="query", @OA\Schema(type="integer"))当我对一些验证进行单元测试以触发错误(例如pageSize=test)时,它会抛出League\OpenAPIValidation\PSR7\Exception\Validation\InvalidQueryArgs。
但是当我添加"/users/followed"端点时,前面的测试将抛出一个不同的错误:League\OpenAPIValidation\PSR7\Exception\MultipleOperationsMismatchForRequest,因为现在的错误不是“嘿,我找到了端点,但是查询错误!”而是“嘿,我发现了多个可能的端点,它们都错了!”
https://stackoverflow.com/questions/64099341
复制相似问题