Skip to content

Commit 85b7b72

Browse files
committed
Add validateDateTime & validateGuid
Initial work to tacke some of the missing validation (Issue #993)
1 parent bd6e482 commit 85b7b72

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/core/utils.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,12 +500,25 @@ export const validateString = ( val ) => {
500500
}
501501
}
502502

503+
export const validateDateTime = (val) => {
504+
if (val && typeof val !== "string") {
505+
return "Value must be a DateTime"
506+
}
507+
}
508+
509+
export const validateGuid = (val) => {
510+
if (val && typeof val !== "string") {
511+
return "Value must be a Guid"
512+
}
513+
}
514+
503515
// validation of parameters before execute
504516
export const validateParam = (param, isXml) => {
505517
let errors = []
506518
let value = isXml && param.get("in") === "body" ? param.get("value_xml") : param.get("value")
507519
let required = param.get("required")
508520
let type = param.get("type")
521+
let format = param.get("format")
509522

510523
/*
511524
If the parameter is required OR the parameter has a value (meaning optional, but filled in)
@@ -528,7 +541,14 @@ export const validateParam = (param, isXml) => {
528541
}
529542

530543
if ( type === "string" ) {
531-
let err = validateString(value)
544+
let err
545+
if (format === "date-time") {
546+
err = validateDateTime(value)
547+
} else if (format === "uuid") {
548+
err = validateGuid(value)
549+
} else {
550+
err = validateString(value)
551+
}
532552
if (!err) return errors
533553
errors.push(err)
534554
} else if ( type === "boolean" ) {

0 commit comments

Comments
 (0)