Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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')
);
});
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'],
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'
)
);
it('returns true', () => {
expect(deepObjectStyleDeserializer.supports(HttpParamStyles.DeepObject)).toBe(true);
});
});
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'
)
);
});
});
public supports(style: HttpParamStyles) {
return style === HttpParamStyles.DeepObject;
}
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(