示例#1
0
    async.eachSeries(files, function parseSwagger(file, swagCallback) {

        parser.bundle(file, function (err, api, metadata) {

            if (err && path.extname(file) === '.yaml') {
                return swagCallback(err);
            }

            if (err) {
                //Was this an actual swagger file?  Could just be a partial swagger pointed to by a $ref
                try {
                    var json = JSON.parse(fs.readFileSync(file));

                    //valid JSON
                    if (isSwaggerFile(json)) {
                        //this must be a swagger file, but it doesn't validate. fail
                        return swagCallback(err);
                    }
                } catch (err) {
                    //wasn't even valid JSON, error out
                    return swagCallback(err);
                }

                logger.warn('Skipping %s', file);
                return swagCallback();
            }

            //no error
            var handlerName = path.basename(file); //use the swagger filename as our handler module id
            handlerName = handlerName.substring(0, handlerName.lastIndexOf('.')); //strip extensions

            specs.bundled[handlerName] = api;
            deref(api, function (err, apiAsPlainJson) {
                if (err) {
                    logger.error('Failed dereferencing swagger spec: ' + file);
                    return swagCallback(err);
                }
                specs.dereferenced[handlerName] = apiAsPlainJson;
                return swagCallback();
            });
        });
    }, function(err) {
示例#2
0
 .then(function(api){
   return parser.bundle(api);
 })