1
- import { parseParamDecorator } from "./utils" ;
2
- import { isStringRecord , isNumberRecord , isBooleanRecord , isEmpty } from "./utils" ;
1
+ import {
2
+ encodeAndConvertPrimitiveVal ,
3
+ ParamDecorator ,
4
+ parseParamDecorator ,
5
+ } from "./utils" ;
6
+ import {
7
+ isStringRecord ,
8
+ isNumberRecord ,
9
+ isBooleanRecord ,
10
+ isEmpty ,
11
+ } from "./utils" ;
3
12
4
13
export const ppMetadataKey = "pathParam" ;
5
14
6
15
export function getSimplePathParams (
7
16
paramName : string ,
8
17
paramValue : any ,
9
- explode : boolean
18
+ explode : boolean ,
19
+ dateTimeFormat ?: string
10
20
) : Map < string , string > {
11
21
const pathParams : Map < string , string > = new Map < string , string > ( ) ;
12
22
const ppVals : string [ ] = [ ] ;
23
+
13
24
if ( Array . isArray ( paramValue ) ) {
14
25
paramValue . forEach ( ( param ) => {
15
- ppVals . push ( String ( param ) ) ;
26
+ ppVals . push ( encodeAndConvertPrimitiveVal ( param , dateTimeFormat ) ) ;
16
27
} ) ;
17
28
pathParams . set ( paramName , ppVals . join ( "," ) ) ;
18
- } else if ( isStringRecord ( paramValue ) || isNumberRecord ( paramValue ) || isBooleanRecord ( paramValue ) ) {
29
+ } else if (
30
+ isStringRecord ( paramValue ) ||
31
+ isNumberRecord ( paramValue ) ||
32
+ isBooleanRecord ( paramValue )
33
+ ) {
19
34
Object . getOwnPropertyNames ( paramValue ) . forEach ( ( paramKey : string ) => {
20
- if ( explode ) ppVals . push ( `${ paramKey } =${ paramValue [ paramKey ] } ` ) ;
21
- else ppVals . push ( `${ paramKey } ,${ paramValue [ paramKey ] } ` ) ;
35
+ const paramFieldValue = encodeAndConvertPrimitiveVal (
36
+ paramValue [ paramKey ] ,
37
+ dateTimeFormat
38
+ ) ;
39
+
40
+ if ( explode ) ppVals . push ( `${ paramKey } =${ paramFieldValue } ` ) ;
41
+ else ppVals . push ( `${ paramKey } ,${ paramFieldValue } ` ) ;
22
42
} ) ;
43
+
23
44
pathParams . set ( paramName , ppVals . join ( "," ) ) ;
24
45
} else if ( paramValue instanceof Object ) {
25
46
Object . getOwnPropertyNames ( paramValue ) . forEach ( ( paramKey : string ) => {
@@ -28,43 +49,35 @@ export function getSimplePathParams(
28
49
paramValue ,
29
50
paramKey
30
51
) ;
52
+
31
53
if ( ppAnn == null ) return ;
54
+
32
55
const ppDecorator : ParamDecorator = parseParamDecorator (
33
56
ppAnn ,
34
57
paramKey ,
35
58
"simple" ,
36
59
explode
37
60
) ;
61
+
38
62
if ( ppDecorator == null ) return ;
39
63
40
- const paramFieldValue = paramValue [ paramKey ] ;
64
+ const paramFieldValue = encodeAndConvertPrimitiveVal (
65
+ paramValue [ paramKey ] ,
66
+ ppDecorator . DateTimeFormat
67
+ ) ;
41
68
42
69
if ( isEmpty ( paramFieldValue ) ) return ;
43
70
else if ( explode )
44
71
ppVals . push ( `${ ppDecorator . ParamName } =${ paramFieldValue } ` ) ;
45
72
else ppVals . push ( `${ ppDecorator . ParamName } ,${ paramFieldValue } ` ) ;
46
73
} ) ;
74
+
47
75
pathParams . set ( paramName , ppVals . join ( "," ) ) ;
48
76
} else {
49
- pathParams . set ( paramName , String ( paramValue ) ) ;
77
+ pathParams . set (
78
+ paramName ,
79
+ encodeAndConvertPrimitiveVal ( paramValue , dateTimeFormat )
80
+ ) ;
50
81
}
51
82
return pathParams ;
52
83
}
53
-
54
- export class ParamDecorator {
55
- Style : string ;
56
- Explode : boolean ;
57
- ParamName : string ;
58
- Serialization ?: string ;
59
- constructor (
60
- Style : string ,
61
- Explode : boolean ,
62
- ParamName : string ,
63
- Serialization ?: string
64
- ) {
65
- this . Style = Style ;
66
- this . Explode = Explode ;
67
- this . ParamName = ParamName ;
68
- this . Serialization = Serialization ;
69
- }
70
- }
0 commit comments