Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('returns static example', () => {
jest.spyOn(helpers, 'negotiateOptionsForInvalidRequest');
jest.spyOn(helpers, 'negotiateOptionsForValidRequest');
mock({
config: { dynamic: false },
resource: mockResource,
input: Object.assign({}, mockInput, { validations: [{ severity: DiagnosticSeverity.Warning }] }),
})(logger);
expect(helpers.negotiateOptionsForValidRequest).toHaveBeenCalled();
expect(helpers.negotiateOptionsForInvalidRequest).not.toHaveBeenCalled();
});
});
expect(results).toEqual([
{
code: 'no-script-tags-in-markdown',
message: 'Markdown descriptions should not contain `
expect(results).toEqual([
{
code: 'operation-operationId-valid-in-url',
message: 'operationId may only use characters that are valid when used in a URL.',
path: ['paths', '/todos', 'get', 'operationId'],
range: {
end: {
character: 31,
line: 5,
},
start: {
character: 23,
line: 5,
},
},
severity: DiagnosticSeverity.Warning,
},
]);
});
});
expect(results).toEqual([
{
code: 'operation-tags',
message: 'Operation should have non-empty `tags` array.',
path: ['paths', '/todos', 'get', 'tags'],
range: {
end: {
character: 15,
line: 4,
},
start: {
character: 12,
line: 4,
},
},
severity: DiagnosticSeverity.Warning,
},
]);
});
});
error =>
expect(error).toEqual([
{
code: 'deprecated',
message: 'Query param productId is deprecated',
path: ['query', 'productId'],
severity: DiagnosticSeverity.Warning,
},
])
);
expect(results).toEqual([
{
code: 'operation-summary-formatted',
message: 'Operation `summary` should start with upper case and end with a dot.',
path: ['paths', '/todos', 'get', 'summary'],
range: {
end: {
character: 48,
line: 5,
},
start: {
character: 19,
line: 5,
},
},
severity: DiagnosticSeverity.Warning,
},
]);
});
});
expect(results).toEqual([
{
code: 'no-eval-in-markdown',
message: 'Markdown descriptions should not contain `eval(`.',
path: ['info', 'description'],
range: {
end: {
character: 52,
line: 5,
},
start: {
character: 19,
line: 5,
},
},
severity: DiagnosticSeverity.Warning,
},
{
code: 'no-eval-in-markdown',
message: 'Markdown descriptions should not contain `eval(`.',
path: ['info', 'title'],
range: {
end: {
character: 40,
line: 4,
},
start: {
character: 13,
line: 4,
},
},
severity: DiagnosticSeverity.Warning,
E.fromOption(() => ({
message: `Unable to match the returned status code with those defined in the document: ${responses
.map(response => response.code)
.join(',')}`,
severity: inRange(statusCode, 200, 300) ? DiagnosticSeverity.Error : DiagnosticSeverity.Warning,
})),
E.mapLeft>(error => [error])
* @param {number} count A number controlling whether word should be pluralized.
* @returns {string} The original word with an s on the end if count is not one.
*/
function pluralize(word: string, count: number): string {
return count === 1 ? word : `${word}s`;
}
function formatRange(range?: IRange): string {
if (!range) return '';
return ` ${range.start.line + 1}:${range.start.character + 1}`;
}
const SEVERITY_COLORS = {
[DiagnosticSeverity.Error]: 'red',
[DiagnosticSeverity.Warning]: 'yellow',
[DiagnosticSeverity.Information]: 'blue',
[DiagnosticSeverity.Hint]: 'white',
};
function getColorForSeverity(severity: DiagnosticSeverity) {
return SEVERITY_COLORS[severity];
}
function getMessageType(severity: DiagnosticSeverity) {
const color = getColorForSeverity(severity);
switch (severity) {
case DiagnosticSeverity.Error:
return chalk[color]('error');
case DiagnosticSeverity.Warning:
return chalk[color]('warning');
function createDiagnosticFor(scheme: string): IPrismDiagnostic {
return {
message: `We currently do not support this type of security scheme: ${scheme}`,
severity: DiagnosticSeverity.Warning,
};
}