File tree 2 files changed +41
-3
lines changed
2 files changed +41
-3
lines changed Original file line number Diff line number Diff line change @@ -11,12 +11,20 @@ const finalizeSpecificationObject = require('./helpers/finalizeSpecificationObje
11
11
* @returns {object } Output specification
12
12
*/
13
13
module . exports = ( options ) => {
14
+ if ( ! options ) {
15
+ throw new Error ( `Missing or invalid input: 'options' is required` ) ;
16
+ }
17
+
14
18
if ( ! options . swaggerDefinition && ! options . definition ) {
15
19
throw new Error (
16
- 'Provided swaggerDefinition or definition attributes are incorrect.'
20
+ `Missing or invalid input: 'options.swaggerDefinition' or 'options.definition' is required`
21
+ ) ;
22
+ }
23
+
24
+ if ( ! options . apis || ! Array . isArray ( options . apis ) ) {
25
+ throw new Error (
26
+ `Missing or invalid input: 'options.apis' is required and it should be an array.`
17
27
) ;
18
- } else if ( ! options . apis ) {
19
- throw new Error ( 'Provided apis attribute are incorrect.' ) ;
20
28
}
21
29
22
30
try {
Original file line number Diff line number Diff line change @@ -2,6 +2,36 @@ const path = require('path');
2
2
const swaggerJsdoc = require ( '../lib' ) ;
3
3
4
4
describe ( 'swagger-jsdoc library' , ( ) => {
5
+ describe ( 'Error handling' , ( ) => {
6
+ it ( 'should require options input' , ( ) => {
7
+ expect ( ( ) => {
8
+ swaggerJsdoc ( ) ;
9
+ } ) . toThrow ( `Missing or invalid input: 'options' is required` ) ;
10
+ } ) ;
11
+
12
+ it ( 'should require a definition input' , ( ) => {
13
+ expect ( ( ) => {
14
+ swaggerJsdoc ( { } ) ;
15
+ } ) . toThrow (
16
+ `Missing or invalid input: 'options.swaggerDefinition' or 'options.definition' is required`
17
+ ) ;
18
+ } ) ;
19
+
20
+ it ( 'should require an api files input' , ( ) => {
21
+ expect ( ( ) => {
22
+ swaggerJsdoc ( { definition : { } } ) ;
23
+ } ) . toThrow (
24
+ `Missing or invalid input: 'options.apis' is required and it should be an array.`
25
+ ) ;
26
+
27
+ expect ( ( ) => {
28
+ swaggerJsdoc ( { definition : { } , apis : { } } ) ;
29
+ } ) . toThrow (
30
+ `Missing or invalid input: 'options.apis' is required and it should be an array.`
31
+ ) ;
32
+ } ) ;
33
+ } ) ;
34
+
5
35
describe ( 'Specification v2: Swagger' , ( ) => {
6
36
it ( 'should support multiple paths' , ( ) => {
7
37
let testObject = {
You can’t perform that action at this time.
0 commit comments