Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should have proper structure', function () {
var path = '/pet/{petId}';
var pathObject = apiDefinition.getOperation(path, 'get').pathObject;
assert.deepEqual(pathObject.apiDefinition, apiDefinition);
assert.equal(pathObject.path, path);
assert.equal(pathObject.ptr, JsonRefs.pathToPtr(['paths', path]));
assert.deepEqual(pathObject.definition, apiDefinition.definitionRemotesResolved.paths[path]);
assert.deepEqual(pathObject.definitionFullyResolved, apiDefinition.definitionFullyResolved.paths[path]);
// Make sure they are of the proper type
assert.ok(pathObject.regexp instanceof RegExp);
// Make sure they have the proper keys
assert.equal(1, pathObject.regexp.keys.length);
assert.equal('petId', pathObject.regexp.keys[0].name);
// Make sure they match the expected URLs
assert.ok(_.isArray(pathObject.regexp.exec(apiDefinition.definitionFullyResolved.basePath + '/pet/1')));
assert.ok(!_.isArray(pathObject.regexp.exec(apiDefinition.definitionFullyResolved.basePath + '/pets/1')));
assert.ok(!_.isArray(pathObject.regexp.exec(apiDefinition.definitionFullyResolved.basePath + '/Pet/1')));
});
cOperation.parameters = _.map(_.values(oParams), function (parameter) {
// Used later by getOperationParameters to circumvent the chicken/egg situation (Removed there as well)
parameter.definition.$$$ptr$$$ = JsonRefs.pathToPtr(parameter.path);
return parameter.definition;
});
if (_.isUndefined(cOperation.security)) {
cOperation.security = pathObject.api.resolved.security;
}
operations.push(new Operation(pathObject.api,
pathObject,
method,
JsonRefs.pathToPtr(oPath),
cOperation,
cOperation.consumes || pathObject.api.resolved.consumes || [],
cOperation.produces || pathObject.api.resolved.produces || []));
});
_.forEach(security, function (scopes, name) {
var sdPath = ['securityDefinitions', name];
var sdPtr = JsonRefs.pathToPtr(sdPath);
var srPath = path.concat([index.toString(), name]);
// Identify missing reference to the security definition
if (_.indexOf(referenceable, sdPtr) === -1) {
response.errors.push({
code: 'UNRESOLVABLE_REFERENCE',
message: 'Security definition could not be resolved: ' + name,
path: srPath
});
} else {
addReference(sdPtr, JsonRefs.pathToPtr(srPath));
_.forEach(scopes, function (scope, sIndex) {
var ssrPath = srPath.concat(sIndex.toString());
var ssrPtr = JsonRefs.pathToPtr(sdPath.concat(['scopes', scope]));
if (_.indexOf(referenceable, ssrPtr) === -1) {
response.errors.push({
code: 'UNRESOLVABLE_REFERENCE',
message: 'Security scope definition could not be resolved: ' + scope,
path: ssrPath
});
} else {
addReference(JsonRefs.pathToPtr(sdPath.concat(['scopes', scope])), ssrPtr);
}
});
}
_.each(model.subTypes, function (subType, index) {
var subPath = ['models', subType];
var subPtr = JsonRefs.pathToPtr(subPath);
var subMetadata = documentMetadata.definitions[subPtr];
var refPath = modelDefPath.concat(['subTypes', index.toString()]);
// If the metadata does not yet exist, create it
if (!subMetadata && documentMetadata.resolved[modelDefsProp][subType]) {
subMetadata = getDefinitionMetadata(subPath);
}
// If the reference is valid, add the parent
if (addReference(documentMetadata, subPath, refPath, results)) {
subMetadata.parents.push(JsonRefs.pathToPtr(modelDefPath));
}
});
var ptrPath = JsonRefs.pathFromPtr(ptr);
if (!_.has(metadata, 'missing')) {
// This reference is a document reference, record it for later
if (['relative', 'remote'].indexOf(metadata.type) > -1 && metadata.fqURI.indexOf('#') === -1) {
if (_.isUndefined(docReferences[metadata.fqURI])) {
docReferences[metadata.fqURI] = [];
}
docReferences[metadata.fqURI].push(ptr);
}
addReference(metadata.fqURI, ptr);
if (ptrPath[ptrPath.length - 2] === 'allOf') {
addAncestor(JsonRefs.pathToPtr(ptrPath.slice(0, ptrPath.length - 2)), metadata.uri);
}
}
});
const updateChangeProperties = (change: ChangeProperties, pf: ProcessedFile): ChangeProperties => {
if (change.location) {
const s = change.location.split(":")
const position = { line: parseInt(s[s.length - 2]), column: parseInt(s[s.length - 1]) - 1 }
const originalPosition = pf.map.originalPositionFor(position)
if (!originalPosition) {
return {...change}
}
const name = originalPosition.name as string
const namePath = name ? name.split("\n")[0] : ""
const parsedPath = namePath ? JSON.parse(namePath) as string[] : ""
const ref = parsedPath ? `${originalPosition.source}${jsonRefs.pathToPtr(parsedPath, true)}` : ""
const location = `${originalPosition.source}:${originalPosition.line}:${(originalPosition.column as number) + 1}`
return { ...change, ref, location }
} else {
return {}
}
}
_.forEach(def.scopes, function (description, scope) {
var ptr = JsonRefs.pathToPtr(sPath.concat(['scopes', scope]));
if (_.indexOf(referenceable, ptr) === -1) {
referenceable.push(ptr);
}
});
});
var addReference = function (cacheEntry, defPathOrPtr, refPathOrPtr, results, omitError) {
var result = true;
var swaggerVersion = helpers.getSwaggerVersion(cacheEntry.resolved);
var defPath = _.isArray(defPathOrPtr) ? defPathOrPtr : JsonRefs.pathFromPtr(defPathOrPtr);
var defPtr = _.isArray(defPathOrPtr) ? JsonRefs.pathToPtr(defPathOrPtr) : defPathOrPtr;
var refPath = _.isArray(refPathOrPtr) ? refPathOrPtr : JsonRefs.pathFromPtr(refPathOrPtr);
var refPtr = _.isArray(refPathOrPtr) ? JsonRefs.pathToPtr(refPathOrPtr) : refPathOrPtr;
var code;
var def;
var displayId;
var i;
var msgPrefix;
var type;
def = cacheEntry.definitions[defPtr];
type = defPath[0];
code = type === 'securityDefinitions' ?
'SECURITY_DEFINITION' :
type.substring(0, type.length - 1).toUpperCase();
displayId = swaggerVersion === '1.2' ? defPath[defPath.length - 1] : defPtr;
msgPrefix = type === 'securityDefinitions' ?
'Security definition' :
code.charAt(0) + code.substring(1).toLowerCase();
_.forEach(scopes, function (scope, sIndex) {
var ssrPath = srPath.concat(sIndex.toString());
var ssrPtr = JsonRefs.pathToPtr(sdPath.concat(['scopes', scope]));
if (_.indexOf(referenceable, ssrPtr) === -1) {
response.errors.push({
code: 'UNRESOLVABLE_REFERENCE',
message: 'Security scope definition could not be resolved: ' + scope,
path: ssrPath
});
} else {
addReference(JsonRefs.pathToPtr(sdPath.concat(['scopes', scope])), ssrPtr);
}
});
}
constructor (definition, parent, pathToDefinition) {
this.definition = definition
this.parent = parent
this.pathToDefinition = pathToDefinition
_.assign(this, definition)
this.pathObject = parent.parent
this.ptr = JsonRefs.pathToPtr(pathToDefinition)
this.schema = helpers.computeParameterSchema(definition)
}