rest - 如何在 Swagger 响应中指定特定参数而不是使用“allOf”?
问题描述
我已经在我的模型 (PHP) 中使用注释定义了一些参数,并darkaonline/l5-swagger
用于将批次编译为 JSON。注释是这样的:
/**
* @OA\Schema(schema="UserModel", required={""})
*/
class User extends Authenticatable
{
/**
* @OA\Property(
* property="id",
* type="integer",
* format="int64",
* description="The unique identifier of a user"
* )
*/
/**
* @OA\Property(
* property="email",
* type="string",
* example="john@example.com",
* description="The email address of a user"
* )
*/
/**
* @OA\Property(
* property="password",
* type="string",
* description="The password of a user"
* )
*/
/**
* @OA\Schema(
* schema="CreateUser",
* type="object",
* allOf={
* @OA\Schema(ref="#/components/schemas/UserModel"),
* }
* )
*/
在我为有效负载定义的架构中,我拥有的allOf
将包括所有属性。就加载文档而言,这确实有效,但我显然不想要id
那里的属性。我认为有一个替代方案allOf
可以让我定义我想要的属性,但我似乎找不到它。
有谁知道它可能是什么?
解决方案
openapi 中没有其他allOf
选择可以让您从要使用的不同对象中选择哪些属性。如果您确实需要该功能,您可以分别定义包含每个字段的不同对象,然后重用您真正需要的对象。像这样的东西:
UserIdModel:
properties:
id:
type: integer
...
UserEmailModel:
properties:
email:
type: string
...
UserPasswordModel:
properties:
password:
type: string
...
CreateUser:
allOf:
- $ref: '#/components/schemas/UserEmailModel'
- $ref: '#/components/schemas/UserPasswordModel'
推荐阅读
- ruby-on-rails - SSO:Rails 应用程序作为 IDP 和 Salesforce 作为服务提供商
- c - 第二次机会页面替换
- c++ - 继承真的不影响性能吗?
- python - 与熊猫 concat 函数在子函数中连接到位?
- google-chrome - Chrome 中需要空格的书签已损坏
- visual-studio-code - VS 代码。我不希望顶部选项卡中的文件,而是侧边栏中的文件
- python - 解决不了这个小bug。代码如下。凯伦没有回应输入
- gis - 需要帮助使用 GML 作为输入为地图服务器生成地图文件
- json - bashscript 将多个json文件合并为一个json
- python-3.x - 如何显示一个字符串,其中显示列表中属于某个标准的所有项目并在一个日期范围内?