Skip to content

Commit

Permalink
fix for issue apiaryio#2173
Browse files Browse the repository at this point in the history
  • Loading branch information
NamesNotRick committed May 4, 2023
1 parent 5ab7b16 commit 2b70ca8
Showing 1 changed file with 33 additions and 19 deletions.
52 changes: 33 additions & 19 deletions packages/dredd-transactions/compile/compileURI/validateParams.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,46 @@ module.exports = function validateParams(params) {
let text;
const param = params[paramName];


if (param.required && !(typeof param.example !== 'undefined' && param.example !== '') && !(typeof param.default !== 'undefined' && param.default !== '')) {
text = `Required URI parameter '${paramName}' has no example or default value.`;
result.errors.push(text);
}

switch (param.type) {
case 'number':
if (Number.isNaN(parseFloat(param.example))) {
text = `URI parameter '${paramName}' is declared as 'number' but it is a string.`;
result.errors.push(text);
}
break;
case 'boolean':
if ((param.example !== 'true') && (param.example !== 'false')) {
text = `URI parameter '${paramName}' is declared as 'boolean' but it is not.`;
if (param.schema && param.schema.example && typeof param.example === 'string'){
const example = param.schema.example;
if(!example || example.length){
text = `URI parameter '${paramName}' example value is an empty string.`;
result.warnings.push(text);
}
else if(param.example !== example){
text = `URI parameter '${paramName}' example value does not match schema's example value`
result.warnings.push(text);
}
}
else{
switch (param.type) {
case 'number':
if (Number.isNaN(parseFloat(param.example))) {
text = `URI parameter '${paramName}' is declared as 'number' but it is a string.`;
result.errors.push(text);
}
break;
case 'boolean':
if ((param.example !== 'true') && (param.example !== 'false')) {
text = `URI parameter '${paramName}' is declared as 'boolean' but it is not.`;
result.errors.push(text);
}
break;
default:
break;
}

if (param.values.length > 0) {
if (!(param.values.indexOf(param.example) > -1)) {
text = `URI parameter '${paramName}' example value is not one of enum values.`;
result.errors.push(text);
}
break;
default:
break;
}

if (param.values.length > 0) {
if (!(param.values.indexOf(param.example) > -1)) {
text = `URI parameter '${paramName}' example value is not one of enum values.`;
result.errors.push(text);
}
}
});
Expand Down

0 comments on commit 2b70ca8

Please sign in to comment.