Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
"no-unused-vars": [2, {"args": "none"}], // Allow unused argument definition in order to keep functions signatures self documented.
"no-use-before-define": [2, "nofunc"],
"quote-props": [2, "as-needed"], // Disallow to quote properties (of object) when it's not requiered.
"max-len": 1 // Seems to be redundant to me.
},
}
45 changes: 45 additions & 0 deletions src/rules/break/delete-array-value.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

export default function deleteArrayValue({ kind, path, item }) {
const match = kind === 'A'
&& path.length > 1
&& item
&& item.kind === 'D';
if (match) {
const pathId = path[1];
const arrayType = path.slice(-1);
const arrayName = path.slice(-2)[0];

if (path[0] === 'paths' && path[3] === 'parameters') {
const paramName = path[4];
const method = path[2];

return {
path: pathId,
message: `${pathId} (${method}) - param ${paramName} - ${arrayName}.${item.lhs} ${arrayType} value deleted`,
method,
param: paramName,
arrayName,
arrayValue: item.lhs,
};
} else if (path[0] === 'definitions' && path[2] === 'properties') {
const objectPath = path.slice(0, -2).join('/');
const propertyName = path[3];

return {
message: `${objectPath} - Object property - ${arrayName}.${item.lhs} ${arrayType} value deleted`,
path: objectPath,
property: propertyName,
arrayName,
arrayValue: item.lhs,
};
}

return {
message: `${arrayName}.${item.lhs} - ${arrayType} value deleted`,
path: pathId,
arrayName,
arrayValue: item.lhs,
};
}
return false;
}
2 changes: 2 additions & 0 deletions src/rules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default {
break: {
'add-required-object-property': require('./break/add-required-object-property.js'),
'add-required-param': require('./break/add-required-param.js'),
'delete-array-value': require('./break/delete-array-value.js'),
'delete-definition': require('./break/delete-definition.js'),
'delete-method': require('./break/delete-method.js'),
'delete-operation-id': require('./break/delete-operation-id.js'),
Expand All @@ -26,6 +27,7 @@ export default {
'edit-response': require('./break/edit-response.js'),
},
smooth: {
'add-array-value': require('./smooth/add-array-value.js'),
'add-definition': require('./smooth/add-definition.js'),
'add-description': require('./smooth/add-description.js'),
'add-method': require('./smooth/add-method.js'),
Expand Down
45 changes: 45 additions & 0 deletions src/rules/smooth/add-array-value.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

export default function addArrayValue({ kind, path, item }) {
const match = kind === 'A'
&& path.length > 1
&& item
&& item.kind === 'N';
if (match) {
const pathId = path[1];
const arrayType = path.slice(-1);
const arrayName = path.slice(-2)[0];

if (path[0] === 'paths' && path[3] === 'parameters') {
const paramName = path[4];
const method = path[2];

return {
path: pathId,
message: `${pathId} (${method}) - param ${paramName} - ${arrayName}.${item.rhs} ${arrayType} value added`,
method,
param: paramName,
arrayName,
arrayValue: item.rhs,
};
} else if (path[0] === 'definitions' && path[2] === 'properties') {
const objectPath = path.slice(0, -2).join('/');
const propertyName = path[3];

return {
message: `${objectPath} - Object property - ${arrayName}.${item.rhs} ${arrayType} value added`,
path: objectPath,
property: propertyName,
arrayName,
arrayValue: item.rhs,
};
}

return {
message: `${arrayName}.${item.rhs} - ${arrayType} value added`,
path: pathId,
arrayName,
arrayValue: item.rhs,
};
}
return false;
}
22 changes: 22 additions & 0 deletions test/rules/break/delete-array-value/0-new.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Test API"
},
"paths": {},
"definitions": {
"Definition.Path.Name": {
"type": "object",
"properties": {
"EnumProperty": {
"enum": [
"Value1",
"Value2"
],
"type": "string"
}
}
}
}
}
23 changes: 23 additions & 0 deletions test/rules/break/delete-array-value/0-old.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Test API"
},
"paths": {},
"definitions": {
"Definition.Path.Name": {
"type": "object",
"properties": {
"EnumProperty": {
"enum": [
"Value1",
"Value2",
"Value3"
],
"type": "string"
}
}
}
}
}
14 changes: 14 additions & 0 deletions test/rules/break/delete-array-value/0-output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"breaks": [
{
"ruleId": "delete-array-value",
"message": "definitions/Definition.Path.Name/properties - Object property - EnumProperty.Value3 enum value deleted",
"path": "definitions/Definition.Path.Name/properties",
"property": "EnumProperty",
"arrayName": "EnumProperty",
"arrayValue": "Value3"
}
],
"smooths": [],
"unmatchDiffs": []
}
25 changes: 25 additions & 0 deletions test/rules/break/delete-array-value/1-new.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Test API"
},
"paths": {
"/test/": {
"get": {
"parameters": [
{
"name": "enumParam",
"in": "query",
"required": false,
"type": "string",
"enum": [
"Value1",
"Value2"
]
}
]
}
}
}
}
26 changes: 26 additions & 0 deletions test/rules/break/delete-array-value/1-old.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Test API"
},
"paths": {
"/test/": {
"get": {
"parameters": [
{
"name": "enumParam",
"in": "query",
"required": false,
"type": "string",
"enum": [
"Value1",
"Value2",
"Value3"
]
}
]
}
}
}
}
15 changes: 15 additions & 0 deletions test/rules/break/delete-array-value/1-output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"breaks": [
{
"ruleId": "delete-array-value",
"message": "/test/ (get) - param enumParam - enumParam.Value3 enum value deleted",
"path": "/test/",
"method": "get",
"param": "enumParam",
"arrayName": "enumParam",
"arrayValue": "Value3"
}
],
"smooths": [],
"unmatchDiffs": []
}
24 changes: 24 additions & 0 deletions test/rules/smooth/add-array-value/0-new.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Test API"
},
"paths": {},
"definitions": {
"Definition.Path.Name": {
"type": "object",
"properties": {
"EnumProperty": {
"enum": [
"Value1",
"Value2",
"Value3",
"Value4"
],
"type": "string"
}
}
}
}
}
23 changes: 23 additions & 0 deletions test/rules/smooth/add-array-value/0-old.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Test API"
},
"paths": {},
"definitions": {
"Definition.Path.Name": {
"type": "object",
"properties": {
"EnumProperty": {
"enum": [
"Value1",
"Value2",
"Value3"
],
"type": "string"
}
}
}
}
}
14 changes: 14 additions & 0 deletions test/rules/smooth/add-array-value/0-output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"breaks": [],
"smooths": [
{
"ruleId": "add-array-value",
"message": "definitions/Definition.Path.Name/properties - Object property - EnumProperty.Value4 enum value added",
"path": "definitions/Definition.Path.Name/properties",
"property": "EnumProperty",
"arrayName": "EnumProperty",
"arrayValue": "Value4"
}
],
"unmatchDiffs": []
}
27 changes: 27 additions & 0 deletions test/rules/smooth/add-array-value/1-new.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Test API"
},
"paths": {
"/test/": {
"get": {
"parameters": [
{
"name": "enumParam",
"in": "query",
"required": false,
"type": "string",
"enum": [
"Value1",
"Value2",
"Value3",
"Value4"
]
}
]
}
}
}
}
26 changes: 26 additions & 0 deletions test/rules/smooth/add-array-value/1-old.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Test API"
},
"paths": {
"/test/": {
"get": {
"parameters": [
{
"name": "enumParam",
"in": "query",
"required": false,
"type": "string",
"enum": [
"Value1",
"Value2",
"Value3"
]
}
]
}
}
}
}
15 changes: 15 additions & 0 deletions test/rules/smooth/add-array-value/1-output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"breaks": [],
"smooths": [
{
"ruleId": "add-array-value",
"message": "/test/ (get) - param enumParam - enumParam.Value4 enum value added",
"path": "/test/",
"method": "get",
"param": "enumParam",
"arrayName": "enumParam",
"arrayValue": "Value4"
}
],
"unmatchDiffs": []
}