Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

fix: issue #2173 OpenApi3.0.0 #2214

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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'){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The param structure does not contain a schema property. See the implementation of compileParams which the result is passed to validateParams.

return {
  [name]: {
    required: getRequired(memberElement),
    default: getDefault(valueElement),
    example: getExample(valueElement),
    values: getValues(valueElement),
  },
};

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