Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Because of this issue ( https://github.com/APIDevTools/json-schema-ref-parser/issues/101#issuecomment-421755168 )
// We need this workaround ( use '$RefParser.dereference' instead of '$RefParser.bundle' ) if asked by user
if (typeof filePath === 'string') {
const origCwd = process.cwd();
const specDir = path.resolve(origCwd, path.dirname(filePath));
const absolutePath = path.resolve(origCwd, filePath);
if (fs.existsSync(absolutePath)) {
// Get document, or throw exception on error
try {
process.chdir(specDir);
const docWithRefs = jsYaml.safeLoad(
fs.readFileSync(absolutePath, 'utf8'),
{ json: true },
);
return $refParser.mode === 'dereference'
? $RefParser.dereference(docWithRefs)
: $RefParser.bundle(docWithRefs);
} finally {
process.chdir(origCwd);
}
} else {
throw new Error(
`${this.loggingPrefix}spec could not be read at ${filePath}`,
);
}
}
return $refParser.mode === 'dereference'
? $RefParser.dereference(filePath)
: $RefParser.bundle(filePath);
}
const uuid62 = require('uuid62');
const uuidv4 = require('uuid/v4');
const refParser = require('json-schema-ref-parser');
const mergeAllOf = require('json-schema-merge-allof');
const utils = require('../utils');
const config = require('../../config');
const { validate } = require('../../../lib/schemas');
const credentialDao = require('./credential.dao.js');
const s = {};
const dereferencePromise = refParser.dereference(config.models.credentials).then(derefSchema => mergeAllOf(derefSchema));
s.insertScopes = function (scopes) {
return validateNewScopes(scopes)
.then(newScopes => {
if (!newScopes) {
return true; // no scopes to insert
}
return credentialDao.insertScopes(newScopes).then(v => !!v);
});
};
s.removeScopes = function (scopes) {
return credentialDao.removeScopes(scopes).then(v => !!v);
};
schemas: {
SecuritySchemeModel: {
type: 'http',
scheme: 'basic',
descriptions: 'example text for def with unused security def'
}
},
securitySchemes: {
scheme1: {
$ref: '#/components/schemas/SecuritySchemeModel'
}
}
}
};
const resolvedSpec = await resolver.dereference(spec);
const res = validate({ resolvedSpec, isOAS3: true }, config);
expect(res.errors.length).toEqual(0);
expect(res.warnings.length).toEqual(1);
expect(res.warnings[0].message).toEqual(
'A security scheme is defined but never used: scheme1'
);
});
it('should warn about an unused security definition', function() {
function resolve(obj){
return refParser.dereference(obj).then(spec => resolveAllOf(spec));
}
before( function () {
return parser.dereference( 'http://petstore.swagger.io/v2/swagger.json' )
.then( function ( api_ ) {
api = gotSwag.annotateApi( api_ );
gotSwag.scanApiVars( api, memory );
} );
} );
function importedComplexYamlTestCase(input, expected, done){
var inputobj = requireYaml(input);
var expectedobj = requireYaml(expected);
refParser.dereference(inputobj)
.then(function(schema) {
resolveAllOf(schema).should.deep.equal(expectedobj);
done();
})
.catch(done);
}
before( function () {
return parser.dereference( 'http://petstore.swagger.io/v2/swagger.json' )
.then( function ( api_ ) {
api = api_;
} );
} );
fs.readFile('swagger.yml', 'utf8', function(err, data) {
if (err) throw err;
var json = yaml.parse(data);
refParser.dereference(json, function(err, schema) {
if (err) {
console.error(err);
} else {
res.send(schema);
}
});
});
});
async function dereference (json) {
return RefParser.dereference(json, {
dereference: {
circular: 'ignore'
}
})
}
function parseV2(obj, dst, config, callback) {
$RefParser.dereference(obj, function (err, input) {
if (err) {
return callback(err);
}
try {
var marked_opt = {
renderer: new marked.Renderer(),
gfm: true,
tables: true,
breaks: false,
pedantic: false,
sanitize: true,
smartLists: true,
smartypants: false
};