如何在 Swagger 响应中指定特定参数而不是使用“allOf”?

How do I specify specific parameters in a Swagger response rather than use `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'