33const util = require ( "../util" ) ;
44const swaggerMethods = require ( "@apidevtools/swagger-methods" ) ;
55const primitiveTypes = [ "array" , "boolean" , "integer" , "number" , "string" ] ;
6- const schemaTypes = [
7- "array" ,
8- "boolean" ,
9- "integer" ,
10- "number" ,
11- "string" ,
12- "object" ,
13- "null" ,
14- undefined ,
15- ] ;
6+ const schemaTypes = [ "array" , "boolean" , "integer" , "number" , "string" , "object" , "null" , undefined ] ;
167
178module . exports = validateSpec ;
189
@@ -65,9 +56,7 @@ function validatePath(api, path, pathId, operationIds) {
6556 if ( operationIds . indexOf ( declaredOperationId ) === - 1 ) {
6657 operationIds . push ( declaredOperationId ) ;
6758 } else {
68- throw new SyntaxError (
69- `Validation failed. Duplicate operation id '${ declaredOperationId } '` ,
70- ) ;
59+ throw new SyntaxError ( `Validation failed. Duplicate operation id '${ declaredOperationId } '` ) ;
7160 }
7261 }
7362 validateParameters ( api , path , pathId , operation , operationId ) ;
@@ -99,20 +88,14 @@ function validateParameters(api, path, pathId, operation, operationId) {
9988 try {
10089 checkForDuplicates ( pathParams ) ;
10190 } catch ( e ) {
102- throw new SyntaxError (
103- e ,
104- `Validation failed. ${ pathId } has duplicate parameters` ,
105- ) ;
91+ throw new SyntaxError ( e , `Validation failed. ${ pathId } has duplicate parameters` ) ;
10692 }
10793
10894 // Check for duplicate operation parameters
10995 try {
11096 checkForDuplicates ( operationParams ) ;
11197 } catch ( e ) {
112- throw new SyntaxError (
113- e ,
114- `Validation failed. ${ operationId } has duplicate parameters` ,
115- ) ;
98+ throw new SyntaxError ( e , `Validation failed. ${ operationId } has duplicate parameters` ) ;
11699 }
117100
118101 // Combine the path and operation parameters,
@@ -203,9 +186,7 @@ function validatePathParameters(params, pathId, operationId) {
203186 }
204187
205188 if ( placeholders . length > 0 ) {
206- throw new SyntaxError (
207- `Validation failed. ${ operationId } is missing path parameter(s) for ${ placeholders } ` ,
208- ) ;
189+ throw new SyntaxError ( `Validation failed. ${ operationId } is missing path parameter(s) for ${ placeholders } ` ) ;
209190 }
210191}
211192
@@ -271,9 +252,7 @@ function checkForDuplicates(params) {
271252 for ( let j = i + 1 ; j < params . length ; j ++ ) {
272253 let inner = params [ j ] ;
273254 if ( outer . name === inner . name && outer . in === inner . in ) {
274- throw new SyntaxError (
275- `Validation failed. Found multiple ${ outer . in } parameters named "${ outer . name } "` ,
276- ) ;
255+ throw new SyntaxError ( `Validation failed. Found multiple ${ outer . in } parameters named "${ outer . name } "` ) ;
277256 }
278257 }
279258 }
@@ -288,9 +267,7 @@ function checkForDuplicates(params) {
288267 */
289268function validateResponse ( code , response , responseId ) {
290269 if ( code !== "default" && ( code < 100 || code > 599 ) ) {
291- throw new SyntaxError (
292- `Validation failed. ${ responseId } has an invalid response code (${ code } )` ,
293- ) ;
270+ throw new SyntaxError ( `Validation failed. ${ responseId } has an invalid response code (${ code } )` ) ;
294271 }
295272
296273 let headers = Object . keys ( response . headers || { } ) ;
@@ -321,15 +298,11 @@ function validateResponse(code, response, responseId) {
321298 */
322299function validateSchema ( schema , schemaId , validTypes ) {
323300 if ( validTypes . indexOf ( schema . type ) === - 1 ) {
324- throw new SyntaxError (
325- `Validation failed. ${ schemaId } has an invalid type (${ schema . type } )` ,
326- ) ;
301+ throw new SyntaxError ( `Validation failed. ${ schemaId } has an invalid type (${ schema . type } )` ) ;
327302 }
328303
329304 if ( schema . type === "array" && ! schema . items ) {
330- throw new SyntaxError (
331- `Validation failed. ${ schemaId } is an array, so it must include an "items" schema` ,
332- ) ;
305+ throw new SyntaxError ( `Validation failed. ${ schemaId } is an array, so it must include an "items" schema` ) ;
333306 }
334307}
335308
0 commit comments