有人能帮我解决以下关于Open API 3.0规范的困惑吗。
假设我想为注册用例指定一个端点。
POST /signup
端点(在前端(应该接受带有以下参数(JSON格式(的requestBody:
{
"email": "user@user.com",
"password": "blaa",
"passwordConfirm": "blaa"
}
端点(在后端(应该返回一个repsonse,如下所示:
{
"email": "user@user.com",
"password": "blaa",
"passwordConfirm": "blaa",
"handle": "username",
"createdAt": "2021-05-28T12:39:47.802Z"
}
响应中应该还有两个字段需要在后端设置(createdAt
和handle
(
我的目标是生成前端和后端,它们应该输出不同的代码:
- 前端:电子邮件、密码、密码确认
- 后端:电子邮件,密码,密码确认,句柄,createdAt
这是我可以用Open API 3.0指定的吗?规格会是什么样子?
谢谢你的帮助。
有一个名为readOnly
的字段。如果设置为true,则表示特定参数可以作为响应的一部分发送,但不应作为请求的一部分进行发送。
您可以查看规范中的Read-Only and Write-Only Properties
部分。
例如,在您的情况下,它看起来像:
type: object
properties:
email:
type: string
password:
type: string
passwordConfirm:
type: string
handle:
type: string
readOnly: true
createdAt:
type: string
readOnly: true