File tree Expand file tree Collapse file tree 2 files changed +45
-2
lines changed
repository/src/decorators Expand file tree Collapse file tree 2 files changed +45
-2
lines changed Original file line number Diff line number Diff line change
1
+ // Copyright IBM Corp. 2018. All Rights Reserved.
2
+ // Node module: @loopback /openapi-v3.
3
+ // This file is licensed under the MIT License.
4
+ // License text available at https://opensource.org/licenses/MIT
5
+
6
+ import { getFilterSchemaFor } from '../..' ;
7
+ import { Entity , model , property } from '@loopback/repository' ;
8
+ import { expect } from '@loopback/testlab' ;
9
+
10
+ describe ( 'filterSchema' , ( ) => {
11
+ @model ( {
12
+ name : 'my-user-model' ,
13
+ } )
14
+ class MyUserModel extends Entity {
15
+ @property ( )
16
+ id : string ;
17
+
18
+ @property ( )
19
+ age : number ;
20
+ }
21
+
22
+ it ( 'generate filter schema' , ( ) => {
23
+ const schema = getFilterSchemaFor ( MyUserModel ) ;
24
+ expect ( MyUserModel . definition . name ) . to . eql ( 'my-user-model' ) ;
25
+ expect ( schema ) . to . eql ( {
26
+ properties : {
27
+ where : { type : 'object' } ,
28
+ fields : { type : 'object' } ,
29
+ offset : { type : 'integer' , minimum : 0 } ,
30
+ limit : { type : 'integer' , minimum : 0 } ,
31
+ skip : { type : 'integer' , minimum : 0 } ,
32
+ order : { type : 'array' , items : { type : 'string' } } ,
33
+ } ,
34
+ } ) ;
35
+ } ) ;
36
+ } ) ;
Original file line number Diff line number Diff line change @@ -68,8 +68,15 @@ export function buildModelDefinition(
68
68
target : Function & { definition ?: ModelDefinition | undefined } ,
69
69
def ?: ModelDefinitionSyntax ,
70
70
) {
71
- // Check if the definition for this class has been built
72
- if ( ! def && target . definition && target . definition . name === target . name ) {
71
+ // Check if the definition for this class has been built (not from the super
72
+ // class)
73
+ const baseClass = Object . getPrototypeOf ( target ) ;
74
+ if (
75
+ ! def &&
76
+ target . definition &&
77
+ baseClass &&
78
+ target . definition !== baseClass . definition
79
+ ) {
73
80
return target . definition ;
74
81
}
75
82
const modelDef = new ModelDefinition ( def || { name : target . name } ) ;
You can’t perform that action at this time.
0 commit comments