1
+ import { readFileSync } from "fs" ;
1
2
import _ from "lodash" ;
2
- import { OpenAPIV3 , OpenAPI } from "openapi-types" ;
3
- import { ConfigToType , DataSourcePlugin } from "openblocks-sdk/dataSource" ;
3
+ import { OpenAPI } from "openapi-types" ;
4
+ import { ConfigToType , DataSourcePlugin , QueryConfig } from "openblocks-sdk/dataSource" ;
5
+ import path from "path" ;
4
6
import { runOpenApi } from "../openApi" ;
5
7
import { parseOpenApi , ParseOpenApiOptions } from "../openApi/parse" ;
6
8
7
- import spec from "./jira.spec.json" ;
9
+ const specJson = readFileSync ( path . join ( __dirname , "./jira.spec.json" ) ) . toString ( ) ;
8
10
9
11
const dataSourceConfig = {
10
12
type : "dataSource" ,
11
13
params : [
14
+ {
15
+ type : "textInput" ,
16
+ key : "serverUrl" ,
17
+ label : "Server URL" ,
18
+ placeholder : "https://your-domain.atlassian.net" ,
19
+ } ,
12
20
{
13
21
type : "groupTitle" ,
14
22
key : "basicAuth" ,
@@ -17,16 +25,16 @@ const dataSourceConfig = {
17
25
{
18
26
type : "textInput" ,
19
27
key : "basicAuth.username" ,
20
- label : "Username " ,
21
- tooltip : "Basic auth username " ,
22
- placeholder : "<Basic Auth Username >" ,
28
+ label : "Account Email " ,
29
+ tooltip : "The email of your atlassian account " ,
30
+ placeholder : "<The email of your atlassian account >" ,
23
31
} ,
24
32
{
25
33
type : "password" ,
26
34
key : "basicAuth.password" ,
27
- label : "Password " ,
35
+ label : "Api Token " ,
28
36
tooltip : "Basic auth password" ,
29
- placeholder : "<Basic Auth Password >" ,
37
+ placeholder : "<API Token >" ,
30
38
} ,
31
39
] ,
32
40
} as const ;
@@ -35,38 +43,44 @@ const parseOptions: ParseOpenApiOptions = {
35
43
actionLabel : ( method : string , path : string , operation : OpenAPI . Operation ) => {
36
44
return _ . upperFirst ( operation . operationId || "" ) ;
37
45
} ,
46
+ actionDescription ( method , path , operation ) {
47
+ return operation . description || "" ;
48
+ } ,
38
49
} ;
39
50
40
51
type DataSourceConfigType = ConfigToType < typeof dataSourceConfig > ;
41
52
53
+ let queryConfig : QueryConfig ;
54
+
42
55
const jiraPlugin : DataSourcePlugin < any , DataSourceConfigType > = {
43
56
id : "jira" ,
44
57
name : "Jira" ,
45
58
icon : "jira.svg" ,
46
59
category : "api" ,
47
60
dataSourceConfig,
48
61
queryConfig : async ( ) => {
49
- const { actions , categories } = await parseOpenApi (
50
- spec as unknown as OpenAPI . Document ,
51
- parseOptions
52
- ) ;
53
- return {
54
- type : "query" ,
55
- label : "Action " ,
56
- categories : {
57
- label : "Category" ,
58
- items : categories ,
59
- } ,
60
- actions ,
61
- } ;
62
+ if ( ! queryConfig ) {
63
+ const { actions , categories } = await parseOpenApi ( JSON . parse ( specJson ) , parseOptions ) ;
64
+ queryConfig = {
65
+ type : "query" ,
66
+ label : "Action" ,
67
+ categories : {
68
+ label : "Category " ,
69
+ items : categories ,
70
+ } ,
71
+ actions ,
72
+ } ;
73
+ }
74
+ return queryConfig ;
62
75
} ,
63
76
run : function ( actionData , dataSourceConfig ) : Promise < any > {
77
+ const spec = JSON . parse ( specJson ) ;
64
78
const runApiDsConfig = {
65
79
url : "" ,
66
- serverURL : "" ,
80
+ serverURL : dataSourceConfig . serverUrl ,
67
81
dynamicParamsConfig : dataSourceConfig ,
68
82
} ;
69
- return runOpenApi ( actionData , runApiDsConfig , spec as unknown as OpenAPIV3 . Document ) ;
83
+ return runOpenApi ( actionData , runApiDsConfig , spec ) ;
70
84
} ,
71
85
} ;
72
86
0 commit comments