ruby-on-rails - 如何在用户对象中编辑 YAML 响应
问题描述
我正在通过 swagger 制作 API 文档在我的 swagger 编辑器中,我正在返回此响应
{
"id": "70020ed1-50fe-4c7e-afed",
"email": "test123@gmail.com",
"authentication_token": "xzmsjvvkvgf448449"
}
通过以下来自招摇编辑器的代码
responses:
200:
description: User credentials.
schema:
# $ref: '#/definitions/User'
properties:
id:
type: string
example: 70020ed1-50fe-4c7e-afed
email:
type: string
example: test123@gmail.com
authentication_token:
type: string
example: xzmsjvvkvgf448449
我想以一种实际的方式来展示它。像这样
{
"message": "User Information & already exist",
"user": {
"id": "2386d9c5-5530-4950-b8fe-",
"email": "saad.arshad@yahoo.com",
"authentication_token": "kagHmoRSmPiu2R"}}
可能在用户对象中。
解决方案
您需要将您的嵌套user
在一个对象中:
responses:
200:
description: User credentials.
content:
application/json:
schema:
properties:
message:
type: string
example: "User Information already exists"
user:
type: object
properties:
id:
type: string
example: 70020ed1-50fe-4c7e-afed
email:
type: string
example: test123@gmail.com
authentication_token:
type: string
example: xzmsjvvkvgf448449
请参阅https://swagger.io/docs/specification/data-models/data-types/#nested了解更多信息,以及有关如何使用引用的说明。
推荐阅读
- android - java.net.UnknownServiceException:网络安全策略不允许与 t.main.wedeep.com.cn 进行 CLEARTEXT 通信
- angular - 尝试对 Angular 进行 docker 化时出现 Dockerfile 错误 - 没有这样的文件或目录
- sql - 正则表达式查找字符串中的特定字符
- grafana - 如何捕获 GRAFANA 刷新按钮
- reactjs - 如何将 React-number-format 应用于反应中的一组数字
- database - Flutter + 全局变量还是 SQL?
- c# - 由 IHttpClientFactory 注入时模拟 HttpClient 处理程序
- android - viewpager2 中的 recyclerView 将在导航中从下一页返回后自动向上滚动
- java - Java:按给定字符串属性的子字符串对对象列表进行排序(模式 ITEM/LOC/YYYY/N)
- ssas - SSAS 表格模型 - 将列添加到现有表