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 validation error', () => {
assertLeft(
httpPathValidator.validate({}, [{ name: 'aParam', style: HttpParamStyles.Simple, required: true }]),
error =>
expect(error).toEqual([
{
code: 'required',
message: "should have required property 'aparam'",
path: ['path'],
severity: 0,
},
])
);
});
});
it('returns false', () => {
expect(labelStyleDeserializer.supports(HttpParamStyles.Simple)).toBe(false);
});
});
it('generates simple style', () => {
assertRight(
createExamplePath({
id: '123',
path: '/path/{p}',
method: 'get',
request: { path: [{ name: 'p', style: HttpParamStyles.Simple, examples: [{ key: 'foo', value: 'test' }] }] },
responses: [{ code: '200' }],
}),
r => expect(r).toEqual('/path/test')
);
});
it('omits schema validation', () => {
jest.spyOn(registry, 'get').mockReturnValueOnce(undefined);
const param: IHttpPathParam = {
name: 'param',
style: HttpParamStyles.Simple,
schema: { type: 'number' },
};
assertRight(httpPathValidator.validate({ param: 'abc' }, [param]));
expect(validateAgainstSchemaModule.validateAgainstSchema).toReturnWith(O.none);
});
});
],
},
],
},
{
id: 'todo',
method: 'get',
path: '/todos/{todoId}',
request: {},
responses: [
{
code: '200',
headers: [
{
name: 'x-todos-publish',
style: HttpParamStyles.Simple,
schema: { type: 'string', format: 'date-time' },
},
],
contents: [
{
mediaType: 'application/json',
schema: {
type: 'object',
properties: {
name: {
type: 'string',
},
completed: {
type: 'boolean',
},
},
],
},
],
},
{
id: 'todo',
method: 'get',
path: '/todos/{todoId}',
request: {},
responses: [
{
code: '200',
headers: [
{
name: 'x-todos-publish',
style: HttpParamStyles.Simple,
schema: { type: 'string', format: 'date-time' },
},
],
contents: [
{
mediaType: 'application/json',
schema: {
type: 'object',
properties: {
name: {
type: 'string',
},
completed: {
type: 'boolean',
},
},
method: 'get',
path: '/a/{a}/b/{b}',
id: '1',
request: {
path: [
{ name: 'a', style: HttpParamStyles.Simple },
{ name: 'b', style: HttpParamStyles.Matrix },
],
},
responses: [{ code: '200' }],
},
element: { method: 'get', url: { path: '/a/1/b/;b=2' } },
});
expect(validator.pathValidator.validate).toHaveBeenCalledWith({ a: '1', b: ';b=2' }, [
{ name: 'a', style: HttpParamStyles.Simple },
{ name: 'b', style: HttpParamStyles.Matrix },
]);
});
});
required: ['name', 'completed'],
},
},
],
},
query: [
{
name: 'overwrite',
style: HttpParamStyles.Form,
schema: { type: 'string', pattern: '^(yes|no)$' },
},
],
headers: [
{
name: 'x-todos-publish',
style: HttpParamStyles.Simple,
schema: { type: 'string', format: 'date-time' },
examples: [],
encodings: [],
},
],
cookie: [],
path: [],
},
responses: [
{
code: '200',
},
],
},
];
public supports(style: HttpParamStyles) {
return style === HttpParamStyles.Simple;
}
constructor(
registry: IHttpParamDeserializerRegistry,
prefix: string,
style: HttpParamStyles = HttpParamStyles.Simple
) {
super(registry, prefix, style);
}
public validate(target: IHttpNameValue, specs: IHttpPathParam[]) {