Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function validateSwagger(swagger, source) {
let target = 'swagger_2';
if (swagger.openapi) target = 'openapi_3';
return converter.getSpec(swagger, target)
.then(function(spec){
var relativeBase = source.split('/');
relativeBase.pop();
relativeBase = relativeBase.join('/');
// 'relativeBase' is for the released version of sway/json-refs, the latest version uses 'location'
let jsonRefs = {relativeBase: relativeBase, location: source, loaderOptions: {processContent:
function (res, cb) {
cb(undefined, YAML.safeLoad(res.text,{json:true}));
}
}};
if (source.indexOf('azure.com')>=0) {
jsonRefs.includeInvalid = true;
jsonRefs.resolveCirculars = true;
}
else {
jsonRefs.includeInvalid = false;
function writeSpec(source, format, exPatch, command) {
var context = {source};
resolverContext = {
anyDiff: false,
called: false,
source: source,
format: format,
etag: !command.slow
};
return converter.getSpec(source, format)
.then(spec => {
context.spec = spec;
if (resolverContext.called && !resolverContext.anyDiff)
throw Error('Warning: 304 Not modified');
var fixup = util.readYaml(getOriginFixupPath(spec));
jsondiffpatch.patch(spec, fixup);
return convertToSwagger(spec,exPatch,command);
})
.then(swagger => {
context.swagger = swagger;
delete exPatch.info.version; // testing
patchSwagger(swagger, exPatch);
expandPathTemplates(swagger);
async function transformSpec(api: config.API) {
LOGGER.debug("Transforming spec of api '%s' to swagger2 format", api.name)
return Converter.getSpec(api.specification, 'openapi_3')
.then((fromSpec: any) => fromSpec.convertTo('swagger_2'))
}
async function validateSpec(api: config.API, type: string) {
LOGGER.debug("Validating spec of api '%s'", api.name);
return Converter.getSpec(api.specification, type)
.then((fromSpec: any) => {
return fromSpec.validate()
}).then((result: any) => {
if (result.errors) {
throw new Error("Validation error of api '" + api.name + "':" + pretty_yaml.stringify(result.errors));
}
if (result.warnings) {
LOGGER.warn("%s", pretty_yaml.stringify(result.warnings));
}
});
}