1
1
'use strict' ;
2
2
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
-
15
3
/**
16
4
* Adds the tags property to a swagger object.
17
5
* @function
@@ -77,15 +65,19 @@ function swaggerizeObj(swaggerObject) {
77
65
}
78
66
79
67
/**
80
- * List of deprecated property names .
68
+ * List of deprecated or wrong swagger schema properties in singular .
81
69
* @function
82
70
* @returns {array } The list of deprecated property names.
83
71
*/
84
- function _getDeprecatePropertyNames ( ) {
72
+ function _getSwaggerSchemaWrongProperties ( ) {
85
73
return [
74
+ 'consume' ,
75
+ 'produce' ,
76
+ 'path' ,
86
77
'tag' ,
87
78
'definition' ,
88
79
'securityDefinition' ,
80
+ 'scheme' ,
89
81
'response' ,
90
82
'parameter' ,
91
83
] ;
@@ -97,9 +89,9 @@ function _getDeprecatePropertyNames() {
97
89
* @param {string } propertyName - The swagger property name to check.
98
90
* @returns {string } The updated propertyName if neccessary.
99
91
*/
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 ) {
103
95
// Returns the corrected property name.
104
96
return propertyName + 's' ;
105
97
}
@@ -115,6 +107,14 @@ function _getSwaggerKey(propertyName) {
115
107
*/
116
108
function _organizeSwaggerProperties ( swaggerObject , pathObject , propertyName ) {
117
109
var simpleProperties = [
110
+ 'consume' ,
111
+ 'consumes' ,
112
+ 'produce' ,
113
+ 'produces' ,
114
+ 'path' ,
115
+ 'paths' ,
116
+ 'schema' ,
117
+ 'schemas' ,
118
118
'securityDefinition' ,
119
119
'securityDefinitions' ,
120
120
'response' ,
@@ -127,7 +127,7 @@ function _organizeSwaggerProperties(swaggerObject, pathObject, propertyName) {
127
127
128
128
// Common properties.
129
129
if ( simpleProperties . indexOf ( propertyName ) !== - 1 ) {
130
- var keyName = _getSwaggerKey ( propertyName ) ;
130
+ var keyName = _correctSwaggerKey ( propertyName ) ;
131
131
var definitionNames = Object
132
132
. getOwnPropertyNames ( pathObject [ propertyName ] ) ;
133
133
for ( var k = 0 ; k < definitionNames . length ; k = k + 1 ) {
@@ -137,7 +137,6 @@ function _organizeSwaggerProperties(swaggerObject, pathObject, propertyName) {
137
137
}
138
138
// Tags.
139
139
} else if ( propertyName === 'tag' || propertyName === 'tags' ) {
140
- _deprecatedPropertyWarning ( propertyName ) ;
141
140
var tag = pathObject [ propertyName ] ;
142
141
_attachTags ( {
143
142
tag : tag ,
@@ -156,7 +155,7 @@ function _organizeSwaggerProperties(swaggerObject, pathObject, propertyName) {
156
155
* Adds the data in to the swagger object.
157
156
* @function
158
157
* @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
160
159
* comments
161
160
*/
162
161
function addDataToSwaggerObject ( swaggerObject , data ) {
@@ -176,7 +175,25 @@ function addDataToSwaggerObject(swaggerObject, data) {
176
175
}
177
176
}
178
177
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
+
179
195
module . exports = {
180
196
addDataToSwaggerObject : addDataToSwaggerObject ,
181
197
swaggerizeObj : swaggerizeObj ,
198
+ findDeprecated : findDeprecated ,
182
199
} ;
0 commit comments