Skip to content

Commit af770ba

Browse files
committed
Improve validation for path parameters by adding empty string check and clarifying allowed types.
1 parent 6a15092 commit af770ba

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,16 @@ function validatePathParam(params: ParamMap, key: string) {
176176
if (!Object.hasOwn(params, key)) {
177177
throw new Error(`Missing value for path parameter ${key}.`)
178178
}
179+
179180
const type = typeof params[key]
181+
180182
if (type !== 'boolean' && type !== 'string' && type !== 'number') {
181183
throw new TypeError(
182184
`Path parameter ${key} cannot be of type ${type}. ` +
183185
'Allowed types are: boolean, string, number.',
184186
)
185187
}
188+
186189
if (type === 'string' && (params[key] as string).trim() === '') {
187190
throw new Error(`Path parameter ${key} cannot be an empty string.`)
188191
}

0 commit comments

Comments
 (0)