我已经使用我的模型(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的替代品,它允许我定义我确实想要的属性,但我似乎找不到它。
有人知道这可能是什么吗?
发布于 2019-11-06 21:25:13
在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'https://stackoverflow.com/questions/58724391
复制相似问题