Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
describe('request.query is set', () => {
it(
'validates query',
validate(
{ request: { query: [{ style: HttpParamStyles.SpaceDelimited, name: 'hey', required: true }] } },
undefined,
1
)
);
});
});
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')
);
});
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,
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;
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);
}
})
);