How to use the @stoplight/types.HttpParamStyles.DeepObject 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 / cli / src / util / __tests__ / paths.spec.ts View on Github external
it('generates deepObject style', () => {
      assertRight(
        createExamplePath({
          id: '123',
          path: '/path',
          method: 'get',
          request: {
            query: [
              {
                name: 'p',
                style: HttpParamStyles.DeepObject,
                examples: [{ key: 'foo', value: { a: { aa: 1, ab: 2 } } }],
              },
            ],
          },
          responses: [{ code: '200' }],
        }),
        r => expect(r).toEqual('/path?p%5Ba%5D%5Baa%5D=1&p%5Ba%5D%5Bab%5D=2')
      );
    });
github stoplightio / prism / packages / http / src / validator / validators / __tests__ / body.spec.ts View on Github external
it('returns validation errors', () => {
        assertLeft(
          httpBodyValidator.validate(
            encodeURI('key[a][ab]=str'),
            [
              {
                mediaType: 'application/x-www-form-urlencoded',
                encodings: [{ property: 'key', style: HttpParamStyles.DeepObject }],
                schema: {
                  type: 'object',
                  properties: {
                    key: {
                      type: 'object',
                      properties: {
                        a: {
                          type: 'object',
                          properties: { aa: { type: 'string' } },
                          required: ['aa'],
                        },
                      },
                      required: ['a'],
                    },
                  },
                  required: ['key'],
github stoplightio / prism / packages / http / src / validator / validators / __tests__ / body.spec.ts View on Github external
it('returns no validation errors', () => {
        assertRight(
          httpBodyValidator.validate(
            encodeURI('key[a]=str'),
            [
              {
                mediaType: 'application/x-www-form-urlencoded',
                encodings: [{ property: 'key', style: HttpParamStyles.DeepObject }],
                schema: {
                  type: 'object',
                  properties: {
                    key: {
                      type: 'object',
                      properties: { a: { type: 'string' } },
                      required: ['a'],
                    },
                  },
                  required: ['key'],
                },
              },
            ],
            'application/x-www-form-urlencoded'
          )
        );
github stoplightio / prism / packages / http / src / validator / deserializers / style / __tests__ / deepObject.spec.ts View on Github external
it('returns true', () => {
        expect(deepObjectStyleDeserializer.supports(HttpParamStyles.DeepObject)).toBe(true);
      });
    });
github stoplightio / prism / packages / cli / src / util / __tests__ / paths.spec.ts View on Github external
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' }],
        }),
        r =>
          expect(r).toEqual(
            '/path/test1/.test1,test2/;p3=test1,test2?q1=test1&q2=test1%20test2&q3=test1%7Ctest2&q4=test1&q4=test2&q5%5Ba%5D%5B%5D=test1&q5%5Ba%5D%5B%5D=test2&q5%5Bb%5D%5Bba%5D=1&q5%5Bb%5D%5Bbb%5D=2'
          )
      );
    });
  });
github stoplightio / prism / packages / http / src / validator / deserializers / style / deepObject.ts View on Github external
public supports(style: HttpParamStyles) {
    return style === HttpParamStyles.DeepObject;
  }
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(