我有这样的 DTO:
# AppBundle\DTO
/**
* @OA\Schema(
* schema="ProductDto",
* type="object",
* required={
* "foo",
* "bar",
* "baz",
* },
* )
*/
class ProductDto
{
/**
* @OA\Property(description="foo bar baz")
* @var string|null
*/
private $foo;
...
}
我试图在我的控制器中引用这个 DTO,但似乎这个文件没有被解析。
# AppBundle\Controller\Api\v1
class ProductController {
...
/**
* @OA\Post(
* @OA\RequestBody(
* required=true,
* content={
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* type="object",
* ref="#/components/schemas/ProductDto",
* ),
* ),
* }
* ),
* )
*/
public function create(Request $request): ApiResponse
...
}
这导致:
用户注意:$ref "#/components/schemas/ProductDto" 在 /srv/vendor/doctrine/annotations/lib/Doctrine 中的 \Doctrine\Common\Annotations\DocParser->Annotation() 中找不到 @OA\Schema() /Common/Annotations/DocParser.php 在第 827 行
似乎如果我将我的 DTO 放入 Controller 命名空间,正在找到并解析该文件,但引用仍然不起作用。不过,它适用于纯 swagger-php 包。
我正在使用当前的 Beta(v4.0.0,NelmioApiDocBundle),因为我想使用 OpenAPI 3。我需要以不同的方式引用它吗?这是包中的错误,还是我做错了?