Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('returns true', () => {
expect(labelStyleDeserializer.supports(HttpParamStyles.Label)).toBe(true);
});
});
it('generates label style', () => {
assertRight(
createExamplePath({
id: '123',
path: '/path/{p}',
method: 'get',
request: { path: [{ name: 'p', style: HttpParamStyles.Label, examples: [{ key: 'foo', value: 'test' }] }] },
responses: [{ code: '200' }],
}),
r => expect(r).toEqual('/path/.test')
);
});
it('generates correct path', () => {
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',
public supports(style: HttpParamStyles) {
return style === HttpParamStyles.Label;
}
function createParamUriTemplate(name: string, style: HttpParamStyles, explode: boolean) {
const starOrVoid = explode ? '*' : '';
switch (style) {
case HttpParamStyles.Simple:
return E.right(`{${name}${starOrVoid}}`);
case HttpParamStyles.Label:
return E.right(`{.${name}${starOrVoid}}`);
case HttpParamStyles.Matrix:
return E.right(`{;${name}${starOrVoid}}`);
default:
return E.left(new Error(`Unsupported parameter style: ${style}`));
}
}