Are there ways to populate a schema in Joi from another schema (like Mongoose does)?

时光毁灭记忆、已成空白 提交于 2019-12-08 03:38:17

问题


I'm currently only using Joi to validate and building schemas. However I feel like I'm missing features like reference another schema like Mongoose does.

Or is the only way to do this by using both (or mongoose only)?

I want to use something similar to this:

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const personSchema = Schema({
  _id: Schema.Types.ObjectId,
  name: String,
  age: Number,
  stories: [{ type: Schema.Types.ObjectId, ref: 'Story' }]
});

const storySchema = Schema({
  author: { type: Schema.Types.ObjectId, ref: 'Person' },
  title: String,
  fans: [{ type: Schema.Types.ObjectId, ref: 'Person' }]
});

const Story = mongoose.model('Story', storySchema);
const Person = mongoose.model('Person', personSchema);

But in Joi instead. I cannot find anything in the Documentation for Joi.

来源:https://stackoverflow.com/questions/54254097/are-there-ways-to-populate-a-schema-in-joi-from-another-schema-like-mongoose-do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!