diff --git a/src/ActionParameterHandler.ts b/src/ActionParameterHandler.ts index 3a16dde3..d168f6fd 100644 --- a/src/ActionParameterHandler.ts +++ b/src/ActionParameterHandler.ts @@ -64,7 +64,7 @@ export class ActionParameterHandler { // check cases when parameter is required but its empty and throw errors in this case if (param.required) { const isValueEmpty = value === null || value === undefined || value === ''; - const isValueEmptyObject = typeof value === 'object' && Object.keys(value).length === 0; + const isValueEmptyObject = typeof value === 'object' && value !== null && Object.keys(value).length === 0; if (param.type === 'body' && !param.name && (isValueEmpty || isValueEmptyObject)) { // body has a special check and error message diff --git a/test/ActionParameterHandler.spec.ts b/test/ActionParameterHandler.spec.ts index 9d322dc1..39bae99e 100644 --- a/test/ActionParameterHandler.spec.ts +++ b/test/ActionParameterHandler.spec.ts @@ -115,6 +115,26 @@ describe('ActionParameterHandler', () => { expect(processedValue).to.be.eq(undefined); }); + + it('handle - null provided', async () => { + try { + const param = buildParamMetadata('id', 'param', true); + const action = { + request: { + params: { + id: null, + }, + }, + response: {}, + }; + + await actionParameterHandler.handle(action, param); + } catch (error) { + expect(error.toString()).to.be.eq( + 'ParamRequiredError: Parameter "id" is required for request on undefined undefined' + ); + } + }); }); describe('negative', () => { it('handle - throws error if the parameter is required', async () => {