How to use the @stoplight/types.DiagnosticSeverity.Error function in @stoplight/types

To help you get started, we’ve selected a few @stoplight/types examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stoplightio / spectral / src / rulesets / oas / __tests__ / oas3-valid-schema-example.ts View on Github external
describe('oas3-valid-schema-example ', () => {
  const s = new Spectral();
  s.registerFormat('oas3', () => true);
  s.setRules({
    'oas3-valid-schema-example ': Object.assign(ruleset.rules['oas3-valid-schema-example '], {
      recommended: true,
      severity: DiagnosticSeverity.Error,
      type: RuleType[ruleset.rules['oas3-valid-schema-example ']!.type],
    }),
  });

  test('will pass when simple example is valid', async () => {
    const results = await s.run({
      openapi: '3.0.2',
      components: {
        schemas: {
          xoxo: {
            type: 'string',
            example: 'doggie',
          },
        },
      },
    });
github stoplightio / prism / packages / http / src / mocker / __tests__ / HttpMocker.spec.ts View on Github external
it('returns static example', () => {
        jest.spyOn(helpers, 'negotiateOptionsForValidRequest');
        jest.spyOn(helpers, 'negotiateOptionsForInvalidRequest');

        mock({
          config: { dynamic: false },
          resource: mockResource,
          input: Object.assign({}, mockInput, { validations: [{ severity: DiagnosticSeverity.Error }] }),
        })(logger);

        expect(helpers.negotiateOptionsForValidRequest).not.toHaveBeenCalled();
        expect(helpers.negotiateOptionsForInvalidRequest).toHaveBeenCalled();
      });
    });
github stoplightio / spectral / src / rulesets / oas / __tests__ / templates / _schema-example.ts View on Github external
test('will fail when simple example is invalid', async () => {
    const results = await s.run({
      openapi: '3.0.2',
      [path]: {
        xoxo: {
          schema: {
            type: 'string',
            example: 123,
          },
        },
      },
    });
    expect(results).toEqual([
      expect.objectContaining({
        severity: DiagnosticSeverity.Error,
        code: ruleName,
        message: '"schema.example" property type should be string',
      }),
    ]);
  });
github stoplightio / prism / packages / http / src / utils / __tests__ / logger.spec.ts View on Github external
it('logs error', () => {
      violationLogger(logger)({ severity: DiagnosticSeverity.Error, message: 'Test' });
      expect(logger.error).toHaveBeenCalledWith({ name: 'VALIDATOR' }, 'Violation: Test');
      expect(logger.warn).not.toHaveBeenCalled();
      expect(logger.info).not.toHaveBeenCalled();
    });
  });
github stoplightio / prism / packages / http / src / validator / __tests__ / functional.spec.ts View on Github external
error =>
            expect(error).toContainEqual({
              code: 'pattern',
              message: 'should match pattern "^(yes|no)$"',
              path: ['query', 'overwrite'],
              severity: DiagnosticSeverity.Error,
            })
        );
github stoplightio / prism / packages / http / src / validator / validators / body.ts View on Github external
Array.reduce([], (diagnostics, encoding) => {
      const allowReserved = get(encoding, 'allowReserved', false);
      const property = encoding.property;
      const value = encodedUriParams[property];

      if (!allowReserved && typeof value === 'string' && /[/?#[\]@!$&'()*+,;=]/.test(value)) {
        diagnostics.push({
          path: [property],
          message: 'Reserved characters used in request body',
          severity: DiagnosticSeverity.Error,
        });
      }

      return diagnostics;
    }),
    diagnostics => (Array.isNonEmpty(diagnostics) ? E.left(diagnostics) : E.right(encodedUriParams))
github stoplightio / spectral / src / formatters / junit.ts View on Github external
        result => result.severity === DiagnosticSeverity.Error,
      );
github stoplightio / prism / packages / http / src / validator / validators / utils.ts View on Github external
    O.map(errors => convertAjvErrors(errors, DiagnosticSeverity.Error, prefix))
  );
github stoplightio / prism / packages / http / src / utils / logger.ts View on Github external
return (violation: IPrismDiagnostic) => {
    const path = violation.path ? violation.path.join('.') + ' ' : '';
    const message = `Violation: ${path}${violation.message}`;
    if (violation.severity === DiagnosticSeverity.Error) {
      logger.error({ name: 'VALIDATOR' }, message);
    } else if (violation.severity === DiagnosticSeverity.Warning) {
      logger.warn({ name: 'VALIDATOR' }, message);
    } else {
      logger.info({ name: 'VALIDATOR' }, message);
    }
  };
});
github stoplightio / prism / packages / http / src / mocker / index.ts View on Github external
function negotiateResponse(
  mockConfig: IHttpOperationConfig,
  input: IPrismInput,
  resource: IHttpOperation
) {
  const { [DiagnosticSeverity.Error]: errors, [DiagnosticSeverity.Warning]: warnings } = groupBy(
    input.validations,
    validation => validation.severity
  );

  if (errors) {
    return handleInputValidation(input, resource);
  } else {
    return pipe(
      withLogger(logger => {
        warnings && warnings.forEach(warn => logger.warn({ name: 'VALIDATOR' }, warn.message));
        return logger.success(
          { name: 'VALIDATOR' },
          'The request passed the validation rules. Looking for the best response'
        );
      }),
      R.chain(() => helpers.negotiateOptionsForValidRequest(resource, mockConfig))