Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ActionParameterHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class ActionParameterHandler<T extends BaseDriver> {
// 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
Expand Down
20 changes: 20 additions & 0 deletions test/ActionParameterHandler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down