Rest 如何在招摇过市的响应中指定特定参数,而不是使用“allOf”?
我在模型PHP中使用注释定义了一些参数,并使用DarkanLine/l5 swagger将该批代码编译为JSON。注释如下所示:Rest 如何在招摇过市的响应中指定特定参数,而不是使用“allOf”?,rest,api,swagger,openapi,Rest,Api,Swagger,Openapi,我在模型PHP中使用注释定义了一些参数,并使用DarkanLine/l5 swagger将该批代码编译为JSON。注释如下所示: /** * @OA\Schema(schema="UserModel", required={""}) */ class User extends Authenticatable { /** * @OA\Property( * property="id", * type="integer", * format="int64", * des
/**
* @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'
真烦人。这意味着我必须重复属性。例如,电子邮件将存在于创建负载和响应中。然而其他人,如id和密码,则不然。@michael,我最初误解了你的意思,我已经解决了。注释示例可以在这里看到:感谢您的帮助。