swagger-mongoose
swagger-mongoose copied to clipboard
Newb alert: Error: Unrecognized schema type: undefined
Everything I do is ending up with the error Error: Unrecognized schema type: undefined
. I see where that's happening in the source; however, there is no indication as to what line of the spec it's failing on.
Even if I strip things back to a minimal case, with the normal petstore.json
, I have the same problem...
const swaggerMongoose = require('swagger-mongoose');
const fs = require('fs');
const path = require('path');
var swagger = fs.readFileSync(path.join( __dirname, '../swagger/petstore.json'));
var Pet = swaggerMongoose.compile(swagger).models.Pet;
Gets me...
Error: Unrecognized schema type: undefined
at propertyMap (/usr/src/node_modules/swagger-mongoose/lib/index.js:48:13)
...
Any ideas what I might be doing wrong?
Same here :'(
I solved this. I can't specifically remember what it was. But what i did to find it was modify the code at one of the files in the stack dump to print more information. Looking back through the terminal:
Its the error - property is: "string"
Error: Unrecognized schema type: undefined
at propertyMap (/Users/bbos/dev/dhs/bots/bottal-api/bottal-api/node_modules/swagger-mongoose/lib/index.js:49:13)
at getSchemaProperty (/Users/bbos/dev/dhs/bots/bottal-api/bottal-api/node_modules/swagger-mongoose/lib/index.js:231:16)
I went to swagger-mongoose/lib/index.js:49
and it was switching on property.type
. The error message I added and can be seen ("Its the error ...") was printing property
. So property was meant to be an object. And thus I worked backwards to see that i was using string
incorrectly. But yes, if you have lots of string
then this won't help pinpoint it. But in which case (since. you don't understand the format), drop back to using a really simple swagger data file.