如何将JSON模式转换为mongoose模式

有没有办法像下面那样采用有效的JSON模式,并把它变成mongoose模式?

{ "$schema": "http://json-schema.org/draft-04/schema#", "description": "some desc", "title": "Product", "type": "object", "properties": { "endpoints": { "type": "array", "items": { "type": "string" } }, "poi": { "type": "array", "items": { "type": "object", "properties": { "location_name": { "type": "string" }, "distance": { "type": "string" } } } } } } 

这对我来说似乎是如此基本和简单,但我还没有在网上find任何东西。
有很多关于如何获取JSON模式的例子,并且有大量的例子来说明如何从这样的对象中创buildmongoose模式:
const newSchema = new mongoose.Schema({ name: String });

如果我试图直接把JSON模式,我得到一个错误

 node_modules/mongoose/lib/schema.js:674 throw new TypeError('Undefined type `' + name + '` at `' + path + ^ TypeError: Undefined type `Http://json-schema.org/draft-04/schema#` at `$schema` Did you try nesting Schemas? You can only nest using refs or arrays. 

但是我无法从一种types的networking上find任何地方。
任何人有过这个问题吗?

我一直在看这个。 既然你在你的问题上放置了一个node标签,我发现这些npm回购:

两者都在工作到目前为止。

他们都是几岁。 前者(TypeScript)有更近期的提交。 我可能最终会喜欢后者。