File tree Expand file tree Collapse file tree 2 files changed +34
-8
lines changed Expand file tree Collapse file tree 2 files changed +34
-8
lines changed Original file line number Diff line number Diff line change @@ -89,13 +89,15 @@ export class RoutingTable {
89
89
registerRoute ( route : RouteEntry ) {
90
90
// TODO(bajtos) handle the case where opSpec.parameters contains $ref
91
91
// See https://github.com/strongloop/loopback-next/issues/435
92
- debug (
93
- 'Registering route %s %s -> %s(%s)' ,
94
- route . verb ,
95
- route . path ,
96
- route . describe ( ) ,
97
- describeOperationParameters ( route . spec ) ,
98
- ) ;
92
+ if ( debug . enabled ) {
93
+ debug (
94
+ 'Registering route %s %s -> %s(%s)' ,
95
+ route . verb ,
96
+ route . path ,
97
+ route . describe ( ) ,
98
+ describeOperationParameters ( route . spec ) ,
99
+ ) ;
100
+ }
99
101
this . _routes . push ( route ) ;
100
102
}
101
103
@@ -322,6 +324,6 @@ export class ControllerRoute extends BaseRoute {
322
324
323
325
function describeOperationParameters ( opSpec : OperationObject ) {
324
326
return ( ( opSpec . parameters as ParameterObject [ ] ) || [ ] )
325
- . map ( p => p . name )
327
+ . map ( p => ( p && p . name ) || '' )
326
328
. join ( ', ' ) ;
327
329
}
Original file line number Diff line number Diff line change 8
8
parseRequestUrl ,
9
9
RoutingTable ,
10
10
ControllerRoute ,
11
+ getControllerSpec ,
12
+ param ,
13
+ get ,
11
14
} from '../../..' ;
12
15
import { expect , ShotRequestOptions , ShotRequest } from '@loopback/testlab' ;
13
16
import { anOpenApiSpec } from '@loopback/openapi-spec-builder' ;
@@ -30,6 +33,27 @@ describe('RoutingTable', () => {
30
33
) ;
31
34
} ) ;
32
35
36
+ it ( 'does not fail if some of the parameters are not decorated' , ( ) => {
37
+ class TestController {
38
+ @get ( '/greet' )
39
+ greet ( prefix : string , @param . query . string ( 'message' ) message : string ) {
40
+ return prefix + ': ' + message ;
41
+ }
42
+ }
43
+ const spec = getControllerSpec ( TestController ) ;
44
+ const table = new RoutingTable ( ) ;
45
+ table . registerController ( TestController , spec ) ;
46
+ const paths = table . describeApiPaths ( ) ;
47
+ const params = paths [ '/greet' ] [ 'get' ] . parameters ;
48
+ expect ( params ) . to . have . property ( 'length' , 2 ) ;
49
+ expect ( params [ 0 ] ) . to . be . undefined ( ) ;
50
+ expect ( params [ 1 ] ) . to . have . properties ( {
51
+ name : 'message' ,
52
+ in : 'query' ,
53
+ type : 'string' ,
54
+ } ) ;
55
+ } ) ;
56
+
33
57
it ( 'finds simple "GET /hello" endpoint' , ( ) => {
34
58
const spec = anOpenApiSpec ( )
35
59
. withOperationReturningString ( 'get' , '/hello' , 'greet' )
You can’t perform that action at this time.
0 commit comments