@@ -4,6 +4,7 @@ var fs = require('fs');
4
4
var path = require ( 'path' ) ;
5
5
var yaml = require ( 'js-yaml' ) ;
6
6
var coffee = require ( 'coffee-script' ) ;
7
+ var url = require ( 'url' ) ;
7
8
8
9
var doctrine = require ( 'doctrine' ) ;
9
10
var express = require ( 'express' ) ;
@@ -218,7 +219,11 @@ function generate(opt) {
218
219
throw new Error ( '\'swaggerUI\' is required.' ) ;
219
220
}
220
221
221
- if ( opt . basePath ) descriptor . basePath = opt . basePath ;
222
+ if ( ! opt . basePath ) {
223
+ throw new Error ( '\'basePath\' is required.' ) ;
224
+ }
225
+
226
+ descriptor . basePath = opt . basePath ;
222
227
descriptor . apiVersion = ( opt . apiVersion ) ? opt . apiVersion : '1.0' ;
223
228
descriptor . swaggerVersion = ( opt . swaggerVersion ) ? opt . swaggerVersion : '1.0' ;
224
229
descriptor . swaggerURL = ( opt . swaggerURL ) ? opt . swaggerURL : '/swagger' ;
@@ -229,6 +234,7 @@ function generate(opt) {
229
234
opt . swaggerVersion = descriptor . swaggerVersion ;
230
235
opt . swaggerURL = descriptor . swaggerURL ;
231
236
opt . swaggerJSON = descriptor . swaggerJSON ;
237
+ opt . fullSwaggerJSONPath = url . parse ( opt . basePath + opt . swaggerJSON ) . path ;
232
238
233
239
if ( opt . apis ) {
234
240
opt . apis . forEach ( function ( api ) {
@@ -273,7 +279,7 @@ exports.init = function (app, opt) {
273
279
274
280
return function ( req , res , next ) {
275
281
var match , resource , result ;
276
- var regex = new RegExp ( '^' + opt . swaggerJSON + '(\/.*)?$' ) ;
282
+ var regex = new RegExp ( '^' + opt . fullSwaggerJSONPath + '(\/.*)?$' ) ;
277
283
278
284
match = regex . exec ( req . path ) ;
279
285
0 commit comments