【发布时间】:2019-11-06 09:19:47
【问题描述】:
我有这个数据模型:
"use strict";
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
let ProviderSchema = new Schema({
name: {
type: String,
required: true
},
emailTemplate: {
type: Schema.ObjectId,
ref: "EmailTemplate",
required: false
}
});
let ProductsSchema = new Schema({
brand: {
type: Schema.ObjectId,
ref: "Brand",
required: true
},
providers: {
type: [ProviderSchema],
required: false
}
});
let ListSchema = new Schema({
code: {
type: String,
unique: true,
trim: true,
required: true
},
products: {
type: [ProductsSchema],
default: [],
required: true
}
}, { collection: 'list' });
module.exports = mongoose.model("List", ListSchema);
但是当我尝试构建 swagger 定义时,我遇到了问题。如何定义模型的“产品”属性? 我尝试使用类型数组来执行此操作,但它在招摇验证中给了我一个错误,我认为是因为它构建得很糟糕。我是招摇的新手,定义这个很复杂
这是我的 .yaml
required:
- code
properties:
code:
type: string
products:
type: array
items:
$ref: '#/definitions/Brand'
【问题讨论】:
-
您是手动编写 YAML 还是从代码生成它?
-
我是手动写的,不知道怎么用代码生成,谢谢
标签: node.js mongoose yaml swagger