@@ -8,13 +8,18 @@ import spec from "./sendGrid.spec.json";
8
8
9
9
const dataSourceConfig = {
10
10
type : "dataSource" ,
11
- params : [ ] ,
11
+ params : [
12
+ {
13
+ "type" : "password" ,
14
+ "key" : "Authorization.value" ,
15
+ "label" : "API Key" ,
16
+ "tooltip" : "[Documentation](https://docs.sendgrid.com/ui/account-and-settings/api-keys#creating-an-api-key)"
17
+ }
18
+ ]
12
19
} as const ;
13
20
14
21
const parseOptions : ParseOpenApiOptions = {
15
- actionLabel : ( method : string , path : string , operation : OpenAPI . Operation ) => {
16
- return _ . upperFirst ( operation . operationId || "" ) ;
17
- } ,
22
+ actionLabel : ( method : string , path : string , operation : OpenAPI . Operation ) => operation . operationId ?. replace ( '_' , ' ' ) || "" ,
18
23
} ;
19
24
20
25
type DataSourceConfigType = ConfigToType < typeof dataSourceConfig > ;
@@ -26,15 +31,12 @@ const sendGridPlugin: DataSourcePlugin<any, DataSourceConfigType> = {
26
31
category : "api" ,
27
32
dataSourceConfig,
28
33
queryConfig : async ( ) => {
29
- const { actions, categories } = await parseOpenApi (
30
- spec as unknown as OpenAPI . Document ,
31
- parseOptions
32
- ) ;
34
+ const { actions, categories } = await parseOpenApi ( spec as unknown as OpenAPI . Document , parseOptions ) ;
33
35
return {
34
36
type : "query" ,
35
37
label : "Action" ,
36
38
categories : {
37
- label : "Category " ,
39
+ label : "Resources " ,
38
40
items : categories ,
39
41
} ,
40
42
actions,
@@ -43,10 +45,13 @@ const sendGridPlugin: DataSourcePlugin<any, DataSourceConfigType> = {
43
45
run : function ( actionData , dataSourceConfig ) : Promise < any > {
44
46
const runApiDsConfig = {
45
47
url : "" ,
46
- serverURL : "" ,
47
- dynamicParamsConfig : dataSourceConfig ,
48
+ serverURL : "https://api.sendgrid.com/v3" ,
49
+ dynamicParamsConfig : {
50
+ ...dataSourceConfig ,
51
+ 'Authorization.value' : 'Bearer ' + dataSourceConfig [ 'Authorization.value' ]
52
+ } ,
48
53
} ;
49
- return runOpenApi ( actionData , runApiDsConfig , spec as unknown as OpenAPIV3 . Document ) ;
54
+ return runOpenApi ( actionData , runApiDsConfig , spec as OpenAPIV3 . Document ) ;
50
55
} ,
51
56
} ;
52
57
0 commit comments