Skip to content

Commit b0e73f1

Browse files
committed
Preparing for general reporting of deprecated properties.
1 parent 4f3641d commit b0e73f1

File tree

2 files changed

+46
-20
lines changed

2 files changed

+46
-20
lines changed

lib/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ module.exports = function(options) {
104104
for (var i = 0; i < apiPaths.length; i = i + 1) {
105105
var files = parseApiFile(apiPaths[i]);
106106
var swaggerJsDocComments = filterJsDocComments(files.jsdoc);
107+
108+
var problems = swaggerHelpers.findDeprecated([files, swaggerJsDocComments]);
109+
// Report a warning in case potential problems encountered.
110+
if (problems.length > 0) {
111+
console.warn('You are using properties to be deprecated in v2.0.0');
112+
console.warn('Please update to align with the swagger v2.0 spec.');
113+
console.warn(problems);
114+
}
115+
107116
swaggerHelpers.addDataToSwaggerObject(swaggerObject, files.yaml);
108117
swaggerHelpers.addDataToSwaggerObject(swaggerObject, swaggerJsDocComments);
109118
}

lib/swagger-helpers.js

+37-20
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
'use strict';
22

3-
/**
4-
* Yields a warning for a given deprecated property.
5-
* @function
6-
* @param {string} propertyName - The property to warn about.
7-
*/
8-
function _deprecatedPropertyWarning(propertyName) {
9-
if (propertyName === 'tag') {
10-
console.warn('tag will be deprecated in v2.0.0');
11-
console.warn('Please use tags as it aligns with the swagger v2.0 spec.');
12-
}
13-
}
14-
153
/**
164
* Adds the tags property to a swagger object.
175
* @function
@@ -77,15 +65,19 @@ function swaggerizeObj(swaggerObject) {
7765
}
7866

7967
/**
80-
* List of deprecated property names.
68+
* List of deprecated or wrong swagger schema properties in singular.
8169
* @function
8270
* @returns {array} The list of deprecated property names.
8371
*/
84-
function _getDeprecatePropertyNames() {
72+
function _getSwaggerSchemaWrongProperties() {
8573
return [
74+
'consume',
75+
'produce',
76+
'path',
8677
'tag',
8778
'definition',
8879
'securityDefinition',
80+
'scheme',
8981
'response',
9082
'parameter',
9183
];
@@ -97,9 +89,9 @@ function _getDeprecatePropertyNames() {
9789
* @param {string} propertyName - The swagger property name to check.
9890
* @returns {string} The updated propertyName if neccessary.
9991
*/
100-
function _getSwaggerKey(propertyName) {
101-
var deprecated = _getDeprecatePropertyNames();
102-
if (deprecated.indexOf(propertyName) > 0) {
92+
function _correctSwaggerKey(propertyName) {
93+
var wrong = _getSwaggerSchemaWrongProperties();
94+
if (wrong.indexOf(propertyName) > 0) {
10395
// Returns the corrected property name.
10496
return propertyName + 's';
10597
}
@@ -115,6 +107,14 @@ function _getSwaggerKey(propertyName) {
115107
*/
116108
function _organizeSwaggerProperties(swaggerObject, pathObject, propertyName) {
117109
var simpleProperties = [
110+
'consume',
111+
'consumes',
112+
'produce',
113+
'produces',
114+
'path',
115+
'paths',
116+
'schema',
117+
'schemas',
118118
'securityDefinition',
119119
'securityDefinitions',
120120
'response',
@@ -127,7 +127,7 @@ function _organizeSwaggerProperties(swaggerObject, pathObject, propertyName) {
127127

128128
// Common properties.
129129
if (simpleProperties.indexOf(propertyName) !== -1) {
130-
var keyName = _getSwaggerKey(propertyName);
130+
var keyName = _correctSwaggerKey(propertyName);
131131
var definitionNames = Object
132132
.getOwnPropertyNames(pathObject[propertyName]);
133133
for (var k = 0; k < definitionNames.length; k = k + 1) {
@@ -137,7 +137,6 @@ function _organizeSwaggerProperties(swaggerObject, pathObject, propertyName) {
137137
}
138138
// Tags.
139139
} else if (propertyName === 'tag' || propertyName === 'tags') {
140-
_deprecatedPropertyWarning(propertyName);
141140
var tag = pathObject[propertyName];
142141
_attachTags({
143142
tag: tag,
@@ -156,7 +155,7 @@ function _organizeSwaggerProperties(swaggerObject, pathObject, propertyName) {
156155
* Adds the data in to the swagger object.
157156
* @function
158157
* @param {object} swaggerObject - Swagger object which will be written to
159-
* @param {object[]} data - objects of parsed swagger data from yaml or jsDoc
158+
* @param {object[]} data - objects of parsed swagger data from yml or jsDoc
160159
* comments
161160
*/
162161
function addDataToSwaggerObject(swaggerObject, data) {
@@ -176,7 +175,25 @@ function addDataToSwaggerObject(swaggerObject, data) {
176175
}
177176
}
178177

178+
/**
179+
* Returns a list of problematic tags if any.
180+
* @param sources
181+
* @returns {Array}
182+
*/
183+
function findDeprecated(sources) {
184+
var wrong = _getSwaggerSchemaWrongProperties();
185+
186+
var problems = [];
187+
sources.forEach(function(source) {
188+
// Transverse the source for wrong usages.
189+
console.log(source);
190+
});
191+
192+
return problems;
193+
}
194+
179195
module.exports = {
180196
addDataToSwaggerObject: addDataToSwaggerObject,
181197
swaggerizeObj: swaggerizeObj,
198+
findDeprecated: findDeprecated,
182199
};

0 commit comments

Comments
 (0)