@@ -5,31 +5,14 @@ import { OpenAPIV3, OpenAPI } from "openapi-types";
55import { ConfigToType , DataSourcePlugin } from "openblocks-sdk/dataSource" ;
66import { runOpenApi } from "../openApi" ;
77import { parseOpenApi , ParseOpenApiOptions } from "../openApi/parse" ;
8+ import { readFileSync } from "fs" ;
9+ import { parse } from "yaml" ;
810
9- const spec = readYaml ( path . join ( __dirname , "./stripe.spec.yaml" ) ) ;
11+ const yamlContent = readFileSync ( path . join ( __dirname , "./stripe.spec.yaml" ) , "utf-8" ) ;
1012
1113const dataSourceConfig = {
1214 type : "dataSource" ,
1315 params : [
14- {
15- type : "groupTitle" ,
16- key : "basicAuth" ,
17- label : "HTTP Basic Auth" ,
18- } ,
19- {
20- type : "textInput" ,
21- key : "basicAuth.username" ,
22- label : "Username" ,
23- tooltip : "Basic auth username" ,
24- placeholder : "<Basic Auth Username>" ,
25- } ,
26- {
27- type : "password" ,
28- key : "basicAuth.password" ,
29- label : "Password" ,
30- tooltip : "Basic auth password" ,
31- placeholder : "<Basic Auth Password>" ,
32- } ,
3316 {
3417 type : "groupTitle" ,
3518 key : "bearerAuth" ,
@@ -38,9 +21,9 @@ const dataSourceConfig = {
3821 {
3922 type : "password" ,
4023 key : "bearerAuth.value" ,
41- label : "Token " ,
42- tooltip : "Bearer HTTP authentication. Allowed headers-- Authorization: Bearer <api_key> " ,
43- placeholder : "Bearer HTTP authentication. Allowed headers-- Authorization: Bearer <api_key >" ,
24+ label : "Secret Key " ,
25+ tooltip : "You can gen a Secret Key [here](https://dashboard.stripe.com/test/apikeys) " ,
26+ placeholder : "<Secret Key >" ,
4427 } ,
4528 ] ,
4629} as const ;
@@ -60,12 +43,13 @@ const stripePlugin: DataSourcePlugin<any, DataSourceConfigType> = {
6043 category : "api" ,
6144 dataSourceConfig,
6245 queryConfig : async ( ) => {
63- const { actions, categories } = await parseOpenApi ( spec , parseOptions ) ;
46+ const spec = parse ( yamlContent ) ;
47+ const { actions, categories } = await parseOpenApi ( spec as OpenAPI . Document , parseOptions ) ;
6448 return {
6549 type : "query" ,
6650 label : "Action" ,
6751 categories : {
68- label : "Category " ,
52+ label : "Resources " ,
6953 items : categories ,
7054 } ,
7155 actions,
@@ -77,6 +61,9 @@ const stripePlugin: DataSourcePlugin<any, DataSourceConfigType> = {
7761 serverURL : "" ,
7862 dynamicParamsConfig : dataSourceConfig ,
7963 } ;
64+ // always use a new spec object
65+ // because of this bug: https://github.com/APIDevTools/json-schema-ref-parser/issues/271
66+ const spec = parse ( yamlContent ) ;
8067 return runOpenApi ( actionData , runApiDsConfig , spec as OpenAPIV3 . Document ) ;
8168 } ,
8269} ;
0 commit comments