How to use the @stoplight/types.HttpParamStyles.SpaceDelimited 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 / __tests__ / index.spec.ts View on Github external
describe('request.query is set', () => {
          it(
            'validates query',
            validate(
              { request: { query: [{ style: HttpParamStyles.SpaceDelimited, name: 'hey', required: true }] } },
              undefined,
              1
            )
          );
        });
      });
github stoplightio / prism / packages / cli / src / util / __tests__ / paths.spec.ts View on Github external
it('generates spaceDelimited style', () => {
      assertRight(
        createExamplePath({
          id: '123',
          path: '/path',
          method: 'get',
          request: {
            query: [
              {
                name: 'p',
                style: HttpParamStyles.SpaceDelimited,
                examples: [{ key: 'foo', value: [1, 2, 3] }],
              },
            ],
          },
          responses: [{ code: '200' }],
        }),
        r => expect(r).toEqual('/path?p=1%202%203')
      );
    });
github stoplightio / prism / packages / cli / src / util / __tests__ / paths.spec.ts View on Github external
assertRight(
        createExamplePath({
          id: '123',
          path: '/path/{p1}/{p2}/{p3}',
          method: 'get',
          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,
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;
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')
            ),
            E.map(v => serializeWithSpaceDelimitedStyle(spec.name, v, spec.explode))
          );

        default:
          return E.right(value);
      }
    })
  );