@@ -2,35 +2,46 @@ import { BODY_TYPE_KEY, MetadataHelper, QUERY_TYPE_KEY } from './deps.ts';
2
2
import { Constructor } from './mod.ts' ;
3
3
import { Swagger } from "./swagger.ts" ;
4
4
5
- export const API_PROPERTY = 'api-property' ;
6
-
7
- export const ApiProperty = ( property ?: Swagger . Schema ) =>
8
- (
5
+ type DecoratorFunction = (
9
6
// deno-lint-ignore ban-types
10
7
target : Object ,
11
- propertyKey : string | symbol ,
12
- ) => {
13
- MetadataHelper . setMetadata ( API_PROPERTY , property ?? null , target , propertyKey ) ;
14
- } ;
8
+ propertyKey ?: string | symbol ,
9
+ descriptor ?: PropertyDescriptor ,
10
+ ) => void ;
11
+
12
+ export const API_PROPERTY = 'api-property' ;
13
+
14
+ export function ApiProperty ( property ?: Swagger . Schema ) : DecoratorFunction {
15
+ return (
16
+ // deno-lint-ignore ban-types
17
+ target : Object ,
18
+ propertyKey ?: string | symbol ,
19
+ descriptor ?: PropertyDescriptor ,
20
+ ) => {
21
+ MetadataHelper . setMetadata ( API_PROPERTY , property ?? null , target , propertyKey ) ;
22
+ } ;
23
+ }
15
24
16
25
export const OPTIONAL_KEY = 'optional' ;
17
26
18
- export const Optional = ( ) =>
19
- (
20
- // deno-lint-ignore ban-types
21
- target : Object ,
22
- propertyKey : string | symbol ,
23
- ) => {
24
- MetadataHelper . setMetadata ( OPTIONAL_KEY , true , target , propertyKey ) ;
25
- } ;
27
+ export function Optional ( ) : DecoratorFunction {
28
+ return (
29
+ // deno-lint-ignore ban-types
30
+ target : Object ,
31
+ propertyKey ?: string | symbol ,
32
+ descriptor ?: PropertyDescriptor ,
33
+ ) => {
34
+ MetadataHelper . setMetadata ( OPTIONAL_KEY , true , target , propertyKey ) ;
35
+ } ;
36
+ }
26
37
27
38
export const RETURNED_TYPE_KEY = 'returntype' ;
28
39
29
- export const ReturnedType = ( returnedType : unknown , isArray ?: boolean ) =>
30
- (
40
+ export function ReturnedType ( returnedType : unknown , isArray ?: boolean ) : DecoratorFunction {
41
+ return (
31
42
target : Object ,
32
- propertyKey : string | symbol ,
33
- descriptor : any ,
43
+ propertyKey ? : string | symbol ,
44
+ descriptor ? : any ,
34
45
) => {
35
46
MetadataHelper . setMetadata (
36
47
RETURNED_TYPE_KEY ,
@@ -42,27 +53,32 @@ export const ReturnedType = (returnedType: unknown, isArray?: boolean) =>
42
53
propertyKey ,
43
54
) ;
44
55
} ;
56
+ }
45
57
46
- export const BodyType = ( type : Constructor ) =>
47
- (
48
- target : Object ,
49
- propertyKey : string | symbol ,
50
- ) => {
51
- MetadataHelper . setMetadata ( BODY_TYPE_KEY , type , target , propertyKey ) ;
52
- } ;
58
+ export function BodyType ( type : Constructor ) : DecoratorFunction {
59
+ return (
60
+ target : Object ,
61
+ propertyKey ?: string | symbol ,
62
+ descriptor ?: PropertyDescriptor ,
63
+ ) => {
64
+ MetadataHelper . setMetadata ( BODY_TYPE_KEY , type , target , propertyKey ) ;
65
+ } ;
66
+ }
53
67
54
- export const QueryType = ( type : Constructor ) =>
55
- (
68
+ export function QueryType ( type : Constructor ) : DecoratorFunction {
69
+ return (
56
70
target : Object ,
57
- propertyKey : string | symbol ,
71
+ propertyKey ?: string | symbol ,
72
+ descriptor ?: PropertyDescriptor ,
58
73
) => {
59
74
MetadataHelper . setMetadata ( QUERY_TYPE_KEY , type , target , propertyKey ) ;
60
75
} ;
76
+ }
61
77
62
78
export const TAGS_KEY = 'tags' ;
63
79
64
- export const Tag = ( tagName : string ) =>
65
- (
80
+ export function Tag ( tagName : string ) : DecoratorFunction {
81
+ return (
66
82
target : Object ,
67
83
propertyKey ?: string | symbol ,
68
84
descriptor ?: PropertyDescriptor ,
@@ -73,17 +89,18 @@ export const Tag = (tagName: string) =>
73
89
MetadataHelper . setMetadata ( TAGS_KEY , tagName , target ) ;
74
90
}
75
91
} ;
92
+ }
76
93
77
94
export const API_SECURITY = 'api-security' ;
78
95
export const API_SECURITY_DATA = 'api-security-data' ;
79
96
80
- export const ApiBasicAuth = ( ) => ApiSecurity ( 'basic' )
81
- export const ApiBearerAuth = ( ) => ApiSecurity ( 'bearer' )
82
- export const ApiCookieAuth = ( ) => ApiSecurity ( 'cookie' )
83
- export const ApiOAuth2 = ( data : string [ ] ) => ApiSecurity ( 'oauth2' , data )
97
+ export function ApiBasicAuth ( ) : DecoratorFunction { return ApiSecurity ( 'basic' ) }
98
+ export function ApiBearerAuth ( ) : DecoratorFunction { return ApiSecurity ( 'bearer' ) }
99
+ export function ApiCookieAuth ( ) : DecoratorFunction { return ApiSecurity ( 'cookie' ) }
100
+ export function ApiOAuth2 ( data : string [ ] ) : DecoratorFunction { return ApiSecurity ( 'oauth2' , data ) }
84
101
85
- export const ApiSecurity = ( name : string , data : string [ ] = [ ] ) =>
86
- (
102
+ export function ApiSecurity ( name : string , data : string [ ] = [ ] ) : DecoratorFunction {
103
+ return (
87
104
// deno-lint-ignore ban-types
88
105
target : Object ,
89
106
propertyKey ?: string | symbol ,
@@ -98,4 +115,5 @@ export const ApiSecurity = (name: string, data: string[] = []) =>
98
115
[ name ] : data
99
116
} , target ) ;
100
117
}
101
- } ;
118
+ } ;
119
+ }
0 commit comments