首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Swagger响应中指定具体参数,而不是使用`allOf`?

如何在Swagger响应中指定具体参数,而不是使用`allOf`?
EN

Stack Overflow用户
提问于 2019-11-06 14:39:27
回答 1查看 754关注 0票数 0

我已经使用我的模型(PHP)中的注释定义了一些参数,并使用darkaonline/l5-swagger将批次编译为JSON。注释如下所示:

代码语言:javascript
复制
/** 
* @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的替代品,它允许我定义我确实想要的属性,但我似乎找不到它。

有人知道这可能是什么吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-11-06 21:25:13

在openapi中没有allOf的替代品,它允许您选择要使用的不同对象中的哪些属性。如果您确实需要该功能,您可以分别定义包含每个字段的不同对象,然后重用您真正需要的对象。大概是这样的:

代码语言:javascript
复制
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'
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58724391

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档