swagger-php - 是否需要 nelmio_api_doc.yaml 中的架构部分?
问题描述
我一直在使用 Swagger-PHP 设置 Nelmio API Doc Bundle。一切都按预期工作,我似乎无法弄清楚/理解的唯一一件事是模式。
在用户控制器中,我有以下注释:
* @OA\RequestBody(
* description="Updated user object",
* required=true,
* @OA\MediaType(
* mediaType="multipart/form-data",
* @OA\Schema(ref="#/components/schemas/User")
* )
* )
在我的Entity/User
课堂上,我将架构定义如下:
/**
* User
*
* @OA\Schema(schema="User")
*
* @ORM\Table(schema="app", name="users")
* @ORM\Entity
*/
class User implements UserInterface
在用户控制器中,我也use App\Entity\User;
定义了。
在我看来,这足以找到架构,但它不起作用,否则我不会在这里发布:)
我能够使其工作的唯一方法是运行vendor/bin/openapi --format yaml src
模式输出并将其复制/粘贴到nelmio_api_doc.yaml
文件中。这是我复制/粘贴的架构部分:
User:
properties:
first_name:
type: string
middle_name:
type: string
last_name:
type: string
initials:
type: string
username:
type: string
password:
type: string
status:
type: integer
email:
type: string
id:
type: integer
customer_id:
type: integer
locked:
type: boolean
type: object
所以我的问题是,这是解决它的方法还是应该自动创建架构部分?
感谢您的任何见解。
解决方案
NelmioApiDocBundle 不会加载所有文件以获取与 swagger-php 相反的注释,要加载模式,您应该使用@Model
注释,请参阅https://symfony.com/doc/current/bundles/NelmioApiDocBundle/index.html#use-模型。
在您的情况下,这将给出以下内容:
use Nelmio\ApiDocBundle\Annotation\Model;
/**
* @OA\RequestBody(
* description="Updated user object",
* required=true,
* @OA\MediaType(
* mediaType="multipart/form-data",
* @OA\Schema(ref=@Model(type=User::class))
* )
* )
*/
推荐阅读
- html - PNG图片有我不需要的大透明边.HTML
- http - 如何通过 Ubuntu 上的终端从 Google Drive 下载受限文件
- python - 如何调整整数的数值精度
- hadoop - HBase 2.X 是否适合在 Hadoop 3.X 上运行?
- mysql - Laravel 查询生成器:addSelect 之后的 where 子句(mysql)
- django - 他们是限制 django 模型中某个字段的更新次数的直接方法吗?
- reactjs - 在哪里为 React 应用程序存储大量图像?
- java - 如何在不删除主题的情况下删除工具栏
- java - 如何用word文档中的段落替换表格?Apache POI [解决方案]
- c# - Blazor:TelerikUpload 组件