我正在阅读两个json文件,每个文件都包含一个学生/教师数组。
let student = require('../data/student.json');
let teacher = require('../data/teacher.json');
当我打电话时:
res.status(200).json({student: student}, {teacher: teacher});
只有第一个(在这种情况下是学生(被打印在响应中。老师没有打印出来。
在我的yaml文件中,响应消息的格式是这样的。
content:
application/json:
schema:
$ref: '#/components/schemas/StudentsAndTeachers'
这是学生和教师:
StudentsAndTeachers:
type: object
properties:
student:
type: array
items:
$ref: '#/components/schemas/Person'
teacher:
type: array
items:
$ref: '#/components/schemas/Person'
required:
- student
- teacher
此人:
Person:
type: object
properties:
id:
type: string
name:
type: string
required:
- id
- name
为什么响应中只打印第一个属性(学生(?
这就是我得到的错误:
500
Error: Internal Server Error
Response body
{
"message": ".response should have required property 'teacher',
"errors": [
{
"path": ".response.teacher",
"message": "should have required property 'teacher'",
"errorCode": "required.openapi.validation"
},
],
"status": 500
}
更改
res.status(200).json({student: student}, {teacher: teacher});
至
res.status(200).json({student: student, teacher: teacher});
注意,student
和teacher
在同一个{ }
对象内。