Skip to content

Commit f9cf7e3

Browse files
authored
fix: null typecheck in parameter validation (#849)
1 parent 175d02f commit f9cf7e3

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/ActionParameterHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class ActionParameterHandler<T extends BaseDriver> {
6464
// check cases when parameter is required but its empty and throw errors in this case
6565
if (param.required) {
6666
const isValueEmpty = value === null || value === undefined || value === '';
67-
const isValueEmptyObject = typeof value === 'object' && Object.keys(value).length === 0;
67+
const isValueEmptyObject = typeof value === 'object' && value !== null && Object.keys(value).length === 0;
6868

6969
if (param.type === 'body' && !param.name && (isValueEmpty || isValueEmptyObject)) {
7070
// body has a special check and error message

test/ActionParameterHandler.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,26 @@ describe('ActionParameterHandler', () => {
115115

116116
expect(processedValue).to.be.eq(undefined);
117117
});
118+
119+
it('handle - null provided', async () => {
120+
try {
121+
const param = buildParamMetadata('id', 'param', true);
122+
const action = {
123+
request: {
124+
params: {
125+
id: null,
126+
},
127+
},
128+
response: {},
129+
};
130+
131+
await actionParameterHandler.handle(action, param);
132+
} catch (error) {
133+
expect(error.toString()).to.be.eq(
134+
'ParamRequiredError: Parameter "id" is required for request on undefined undefined'
135+
);
136+
}
137+
});
118138
});
119139
describe('negative', () => {
120140
it('handle - throws error if the parameter is required', async () => {

0 commit comments

Comments
 (0)