swagger-mongoose icon indicating copy to clipboard operation
swagger-mongoose copied to clipboard

Newb alert: Error: Unrecognized schema type: undefined

Open shankie-codes opened this issue 7 years ago • 2 comments

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?

shankie-codes avatar Jul 05 '17 15:07 shankie-codes

Same here :'(

ThirtyOne34 avatar Jul 13 '17 16:07 ThirtyOne34

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.

oehm-smith avatar Nov 19 '18 05:11 oehm-smith