How to use the @stoplight/types.HttpParamStyles.PipeDelimited 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 / 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 / cli / src / util / __tests__ / paths.spec.ts View on Github external
it('generates pipeDelimited style', () => {
      assertRight(
        createExamplePath({
          id: '123',
          path: '/path',
          method: 'get',
          request: {
            query: [
              {
                name: 'p',
                style: HttpParamStyles.PipeDelimited,
                examples: [{ key: 'foo', value: [1, 2, 3] }],
              },
            ],
          },
          responses: [{ code: '200' }],
        }),
        r => expect(r).toEqual('/path?p=1%7C2%7C3')
      );
    });
github stoplightio / prism / packages / http / src / validator / deserializers / style / __tests__ / delimited.spec.ts View on Github external
it('returns true', () => {
        expect(delimitedStyleDeserializer.supports(HttpParamStyles.PipeDelimited)).toBe(true);
      });
    });
github stoplightio / prism / packages / http / src / validator / deserializers / style / __tests__ / deepObject.spec.ts View on Github external
it('returns false', () => {
        expect(deepObjectStyleDeserializer.supports(HttpParamStyles.PipeDelimited)).toBe(false);
      });
    });
github stoplightio / prism / packages / cli / src / util / __tests__ / paths.spec.ts View on Github external
request: {
            path: [
              { name: 'p1', style: HttpParamStyles.Simple, examples: [{ key: 'foo', value: 'test1' }] },
              { name: 'p2', style: HttpParamStyles.Label, examples: [{ key: 'foo', value: ['test1', 'test2'] }] },
              { name: 'p3', style: HttpParamStyles.Matrix, examples: [{ key: 'foo', value: ['test1', 'test2'] }] },
            ],
            query: [
              { name: 'q1', style: HttpParamStyles.Form, examples: [{ key: 'foo', value: 'test1' }] },
              {
                name: 'q2',
                style: HttpParamStyles.SpaceDelimited,
                examples: [{ key: 'foo', value: ['test1', 'test2'] }],
              },
              {
                name: 'q3',
                style: HttpParamStyles.PipeDelimited,
                examples: [{ key: 'foo', value: ['test1', 'test2'] }],
              },
              {
                name: 'q4',
                style: HttpParamStyles.PipeDelimited,
                explode: true,
                examples: [{ key: 'foo', value: ['test1', 'test2'] }],
              },
              {
                name: 'q5',
                style: HttpParamStyles.DeepObject,
                examples: [{ key: 'foo', value: { a: ['test1', 'test2'], b: { ba: 1, bb: 2 } } }],
              },
            ],
          },
          responses: [{ code: '200' }],
github stoplightio / prism / packages / cli / src / util / paths.ts View on Github external
E.chain(value => {
      switch (spec.style) {
        case HttpParamStyles.DeepObject:
          return E.right(serializeWithDeepObjectStyle(spec.name, value));

        case HttpParamStyles.PipeDelimited:
          return pipe(
            value,
            E.fromPredicate(
              Array.isArray,
              () => new Error('Pipe delimited style is only applicable to array parameter')
            ),
            E.map(v => serializeWithPipeDelimitedStyle(spec.name, v, spec.explode))
          );

        case HttpParamStyles.SpaceDelimited:
          return pipe(
            value,
            E.fromPredicate(
              Array.isArray,
              () => new Error('Space delimited style is only applicable to array parameter')
            ),
github stoplightio / prism / packages / http / src / validator / deserializers / index.ts View on Github external
import { HttpParamDeserializerRegistry } from './registry';
import {
  DeepObjectStyleDeserializer,
  DelimitedStyleDeserializer,
  FormStyleDeserializer,
  SimpleStyleDeserializer,
} from './style';
import { LabelStyleDeserializer } from './style/label';
import { MatrixStyleDeserializer } from './style/matrix';

export const header = new HttpParamDeserializerRegistry([new SimpleStyleDeserializer()]);

export const query = new HttpParamDeserializerRegistry([
  new FormStyleDeserializer(),
  new DelimitedStyleDeserializer('%20', HttpParamStyles.SpaceDelimited),
  new DelimitedStyleDeserializer('|', HttpParamStyles.PipeDelimited),
  new DelimitedStyleDeserializer(',', HttpParamStyles.CommaDelimited),
  new DeepObjectStyleDeserializer(),
]);

export const path = new HttpParamDeserializerRegistry([
  new SimpleStyleDeserializer(),
  new LabelStyleDeserializer(),
  new MatrixStyleDeserializer(),
]);

export const body = query;