File tree 3 files changed +52
-1
lines changed 3 files changed +52
-1
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ export function defaultResolver(
35
35
tmpModules [ modulePath ] = require ( modulePath ) ;
36
36
}
37
37
38
- const handler = tmpModules [ modulePath ] [ oId ] || tmpModules [ modulePath ] . default ;
38
+ const handler = tmpModules [ modulePath ] [ oId ] || tmpModules [ modulePath ] . default [ oId ] || tmpModules [ modulePath ] . default ;
39
39
40
40
if ( ! handler ) {
41
41
throw Error (
Original file line number Diff line number Diff line change
1
+ import * as express from 'express' ;
2
+ import * as OpenApiValidator from '../src' ;
3
+ import { expect } from 'chai' ;
4
+ import * as request from 'supertest' ;
5
+ import * as path from 'path' ;
6
+
7
+ describe ( 'default export resolver' , ( ) => {
8
+ let server = null ;
9
+ let app = express ( ) ;
10
+
11
+ before ( async ( ) => {
12
+ app . use (
13
+ OpenApiValidator . middleware ( {
14
+ apiSpec : {
15
+ openapi : '3.0.0' ,
16
+ info : { version : '1.0.0' , title : 'test bug OpenApiValidator' } ,
17
+ paths : {
18
+ '/' : {
19
+ get : {
20
+ operationId : 'test#get' ,
21
+ // @ts -ignore
22
+ 'x-eov-operation-handler' : 'routes/default-export-fn' ,
23
+ responses : { 200 : { description : 'homepage' } }
24
+ }
25
+ } ,
26
+ } ,
27
+ } ,
28
+ operationHandlers : path . join ( __dirname , 'resources' ) ,
29
+ } ) ,
30
+ ) ;
31
+
32
+ server = app . listen ( 3000 ) ;
33
+ console . log ( 'server start port 3000' ) ;
34
+ } ) ;
35
+
36
+ after ( async ( ) => server . close ( ) ) ;
37
+
38
+ it ( 'should use default export operation' , async ( ) => {
39
+ return request ( app )
40
+ . get ( `/` )
41
+ . expect ( 200 )
42
+ . then ( ( r ) => {
43
+ expect ( r . body ) . to . have . property ( 'message' ) . that . equals ( "It Works!" ) ;
44
+ } ) ;
45
+ } ) ;
46
+ } ) ;
Original file line number Diff line number Diff line change
1
+ exports . default = {
2
+ 'test#get' : ( req , res ) => {
3
+ res . status ( 200 ) . json ( { message : 'It Works!' } ) ;
4
+ } ,
5
+ } ;
You can’t perform that action at this time.
0 commit comments