How to use @stoplight/types - 10 common examples

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 / prism / packages / http / src / validator / deserializers / style / __tests__ / delimited.spec.ts View on Github external
describe('DelimitedStyleDeserializer', () => {
  const delimitedStyleDeserializer = new DelimitedStyleDeserializer('|', HttpParamStyles.PipeDelimited);

  describe('supports()', () => {
    describe('style is supported', () => {
      it('returns true', () => {
        expect(delimitedStyleDeserializer.supports(HttpParamStyles.PipeDelimited)).toBe(true);
      });
    });

    describe('style is not supported', () => {
      it('returns false', () => {
        // Force compile to pass for purpose of test.
        // @ts-ignore
        expect(delimitedStyleDeserializer.supports('invalid')).toBe(false);
      });
    });
  });
github stoplightio / prism / packages / http / src / mocker / __tests__ / HttpMocker.spec.ts View on Github external
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();
      });
    });
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 / validators / __tests__ / path.spec.ts View on Github external
it('returns validation error', () => {
            assertLeft(
              httpPathValidator.validate({}, [{ name: 'aParam', style: HttpParamStyles.Simple, required: true }]),
              error =>
                expect(error).toEqual([
                  {
                    code: 'required',
                    message: "should have required property 'aparam'",
                    path: ['path'],
                    severity: 0,
                  },
                ])
            );
          });
        });
github stoplightio / prism / packages / http / src / validator / deserializers / style / __tests__ / label.spec.ts View on Github external
it('returns false', () => {
        expect(labelStyleDeserializer.supports(HttpParamStyles.Simple)).toBe(false);
      });
    });
github stoplightio / prism / packages / cli / src / util / __tests__ / paths.spec.ts View on Github external
it('generates simple style', () => {
      assertRight(
        createExamplePath({
          id: '123',
          path: '/path/{p}',
          method: 'get',
          request: { path: [{ name: 'p', style: HttpParamStyles.Simple, examples: [{ key: 'foo', value: 'test' }] }] },
          responses: [{ code: '200' }],
        }),
        r => expect(r).toEqual('/path/test')
      );
    });
github stoplightio / prism / packages / http / src / validator / validators / __tests__ / path.spec.ts View on Github external
it('omits schema validation', () => {
              jest.spyOn(registry, 'get').mockReturnValueOnce(undefined);
              const param: IHttpPathParam = {
                name: 'param',
                style: HttpParamStyles.Simple,
                schema: { type: 'number' },
              };

              assertRight(httpPathValidator.validate({ param: 'abc' }, [param]));
              expect(validateAgainstSchemaModule.validateAgainstSchema).toReturnWith(O.none);
            });
          });