@budibase/server 1.0.98 → 1.0.101

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (237) hide show
  1. package/builder/assets/index.cca3db8c.js +1291 -0
  2. package/builder/assets/{index.7c8961b4.css → index.ea3718aa.css} +2 -2
  3. package/builder/assets/{vendor.a7c6ad0a.js → vendor.8e34a169.js} +1 -1
  4. package/builder/index.html +3 -3
  5. package/coverage/clover.xml +354 -334
  6. package/coverage/coverage-final.json +15 -15
  7. package/coverage/lcov-report/api/controllers/analytics.js.html +1 -1
  8. package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
  9. package/coverage/lcov-report/api/controllers/application.js.html +1 -1
  10. package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
  11. package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
  12. package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
  13. package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
  14. package/coverage/lcov-report/api/controllers/component.js.html +4 -4
  15. package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
  16. package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
  17. package/coverage/lcov-report/api/controllers/index.html +18 -18
  18. package/coverage/lcov-report/api/controllers/integration.js.html +59 -11
  19. package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
  20. package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
  21. package/coverage/lcov-report/api/controllers/migrations.js.html +1 -1
  22. package/coverage/lcov-report/api/controllers/permission.js.html +7 -7
  23. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  24. package/coverage/lcov-report/api/controllers/query/index.js.html +1 -1
  25. package/coverage/lcov-report/api/controllers/query/validation.js.html +2 -2
  26. package/coverage/lcov-report/api/controllers/role.js.html +1 -1
  27. package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
  28. package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
  29. package/coverage/lcov-report/api/controllers/row/index.html +10 -10
  30. package/coverage/lcov-report/api/controllers/row/index.js.html +1 -1
  31. package/coverage/lcov-report/api/controllers/row/internal.js.html +19 -7
  32. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
  33. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +1 -1
  34. package/coverage/lcov-report/api/controllers/row/utils.js.html +6 -6
  35. package/coverage/lcov-report/api/controllers/screen.js.html +1 -1
  36. package/coverage/lcov-report/api/controllers/script.js.html +1 -1
  37. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +1 -1
  38. package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
  39. package/coverage/lcov-report/api/controllers/table/index.html +1 -1
  40. package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
  41. package/coverage/lcov-report/api/controllers/table/internal.js.html +1 -1
  42. package/coverage/lcov-report/api/controllers/table/utils.js.html +1 -1
  43. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  44. package/coverage/lcov-report/api/controllers/user.js.html +1 -1
  45. package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
  46. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  47. package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
  48. package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
  49. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
  50. package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
  51. package/coverage/lcov-report/api/index.html +1 -1
  52. package/coverage/lcov-report/api/index.js.html +1 -1
  53. package/coverage/lcov-report/api/routes/analytics.js.html +3 -3
  54. package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
  55. package/coverage/lcov-report/api/routes/application.js.html +1 -1
  56. package/coverage/lcov-report/api/routes/auth.js.html +1 -1
  57. package/coverage/lcov-report/api/routes/automation.js.html +1 -1
  58. package/coverage/lcov-report/api/routes/backup.js.html +1 -1
  59. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  60. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  63. package/coverage/lcov-report/api/routes/dev.js.html +1 -1
  64. package/coverage/lcov-report/api/routes/index.html +1 -1
  65. package/coverage/lcov-report/api/routes/index.js.html +1 -1
  66. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
  69. package/coverage/lcov-report/api/routes/migrations.js.html +1 -1
  70. package/coverage/lcov-report/api/routes/permission.js.html +1 -1
  71. package/coverage/lcov-report/api/routes/query.js.html +1 -1
  72. package/coverage/lcov-report/api/routes/role.js.html +1 -1
  73. package/coverage/lcov-report/api/routes/routing.js.html +1 -1
  74. package/coverage/lcov-report/api/routes/row.js.html +1 -1
  75. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  76. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  77. package/coverage/lcov-report/api/routes/static.js.html +1 -1
  78. package/coverage/lcov-report/api/routes/table.js.html +2 -2
  79. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  80. package/coverage/lcov-report/api/routes/user.js.html +1 -1
  81. package/coverage/lcov-report/api/routes/utils/index.html +1 -1
  82. package/coverage/lcov-report/api/routes/utils/validators.js.html +1 -1
  83. package/coverage/lcov-report/api/routes/view.js.html +1 -1
  84. package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
  85. package/coverage/lcov-report/automations/actions.js.html +1 -1
  86. package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
  87. package/coverage/lcov-report/automations/bullboard.js.html +1 -1
  88. package/coverage/lcov-report/automations/index.html +12 -12
  89. package/coverage/lcov-report/automations/index.js.html +1 -1
  90. package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
  91. package/coverage/lcov-report/automations/steps/createRow.js.html +1 -1
  92. package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
  93. package/coverage/lcov-report/automations/steps/deleteRow.js.html +1 -1
  94. package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
  95. package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
  96. package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
  97. package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
  98. package/coverage/lcov-report/automations/steps/index.html +1 -1
  99. package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
  100. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
  101. package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
  102. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
  103. package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
  104. package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
  105. package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
  106. package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
  107. package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
  108. package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
  109. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
  110. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  111. package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
  112. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
  113. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
  114. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
  115. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
  116. package/coverage/lcov-report/automations/triggers.js.html +1 -1
  117. package/coverage/lcov-report/automations/utils.js.html +20 -8
  118. package/coverage/lcov-report/constants/index.html +1 -1
  119. package/coverage/lcov-report/constants/index.js.html +1 -1
  120. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  121. package/coverage/lcov-report/constants/screens.js.html +1 -1
  122. package/coverage/lcov-report/db/client.js.html +1 -1
  123. package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
  124. package/coverage/lcov-report/db/index.html +1 -1
  125. package/coverage/lcov-report/db/index.js.html +1 -1
  126. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
  127. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  128. package/coverage/lcov-report/db/linkedRows/index.js.html +10 -10
  129. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +7 -7
  130. package/coverage/lcov-report/db/newid.js.html +2 -2
  131. package/coverage/lcov-report/db/utils.js.html +2 -2
  132. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  133. package/coverage/lcov-report/events/index.html +1 -1
  134. package/coverage/lcov-report/events/index.js.html +1 -1
  135. package/coverage/lcov-report/events/utils.js.html +1 -1
  136. package/coverage/lcov-report/index.html +31 -31
  137. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  138. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  139. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  140. package/coverage/lcov-report/middleware/authorized.js.html +75 -15
  141. package/coverage/lcov-report/middleware/builder.js.html +1 -1
  142. package/coverage/lcov-report/middleware/currentapp.js.html +1 -1
  143. package/coverage/lcov-report/middleware/index.html +15 -15
  144. package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
  145. package/coverage/lcov-report/middleware/publicApi.js.html +1 -1
  146. package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
  147. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  148. package/coverage/lcov-report/middleware/usageQuota.js.html +1 -1
  149. package/coverage/lcov-report/middleware/utils.js.html +1 -1
  150. package/coverage/lcov-report/threads/automation.js.html +1 -1
  151. package/coverage/lcov-report/threads/index.html +1 -1
  152. package/coverage/lcov-report/threads/index.js.html +1 -1
  153. package/coverage/lcov-report/threads/query.js.html +1 -1
  154. package/coverage/lcov-report/threads/utils.js.html +1 -1
  155. package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
  156. package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
  157. package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
  158. package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
  159. package/coverage/lcov-report/utilities/global.js.html +1 -1
  160. package/coverage/lcov-report/utilities/index.html +1 -1
  161. package/coverage/lcov-report/utilities/index.js.html +1 -1
  162. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +1 -1
  163. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  164. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  165. package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
  166. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  167. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +12 -12
  168. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +8 -8
  169. package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
  170. package/coverage/lcov-report/utilities/security.js.html +1 -1
  171. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  172. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  173. package/coverage/lcov-report/utilities/usageQuota/index.js.html +1 -1
  174. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +1 -1
  175. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  176. package/coverage/lcov-report/utilities/users.js.html +1 -1
  177. package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
  178. package/coverage/lcov.info +584 -546
  179. package/dist/api/controllers/integration.js +15 -1
  180. package/dist/api/controllers/permission.js +3 -4
  181. package/dist/api/controllers/query/import/index.js +2 -1
  182. package/dist/api/controllers/query/import/sources/base/index.js +12 -1
  183. package/dist/api/controllers/query/import/sources/curl.js +2 -2
  184. package/dist/api/controllers/query/import/sources/openapi3.js +174 -0
  185. package/dist/api/controllers/query/import/sources/tests/openapi3/data/crud/crud.json +253 -0
  186. package/dist/api/controllers/query/import/sources/tests/openapi3/data/petstore/petstore.json +1225 -0
  187. package/dist/api/controllers/row/internal.js +2 -1
  188. package/dist/api/routes/analytics.js +2 -2
  189. package/dist/api/routes/table.js +1 -1
  190. package/dist/automations/utils.js +3 -1
  191. package/dist/definitions/datasource.js +1 -0
  192. package/dist/environment.js +2 -0
  193. package/dist/integrations/base/sql.js +16 -9
  194. package/dist/integrations/dynamodb.js +3 -1
  195. package/dist/integrations/firebase.js +192 -0
  196. package/dist/integrations/googlesheets.js +17 -1
  197. package/dist/integrations/index.js +4 -1
  198. package/dist/integrations/mysql.js +14 -1
  199. package/dist/integrations/rest.js +2 -1
  200. package/dist/middleware/authorized.js +24 -7
  201. package/dist/package.json +7 -4
  202. package/dist/tsconfig.tsbuildinfo +1 -1
  203. package/package.json +8 -5
  204. package/scripts/dev/manage.js +2 -1
  205. package/specs/openapi.json +23 -3
  206. package/specs/openapi.yaml +20 -4
  207. package/specs/resources/query.js +27 -5
  208. package/src/api/controllers/integration.js +17 -1
  209. package/src/api/controllers/permission.js +3 -3
  210. package/src/api/controllers/query/import/index.ts +2 -1
  211. package/src/api/controllers/query/import/sources/base/index.ts +12 -2
  212. package/src/api/controllers/query/import/sources/curl.ts +2 -2
  213. package/src/api/controllers/query/import/sources/openapi3.ts +205 -0
  214. package/src/api/controllers/query/import/sources/tests/openapi3/data/crud/crud.json +253 -0
  215. package/src/api/controllers/query/import/sources/tests/openapi3/data/crud/crud.yaml +153 -0
  216. package/src/api/controllers/query/import/sources/tests/openapi3/data/petstore/petstore.json +1225 -0
  217. package/src/api/controllers/query/import/sources/tests/openapi3/data/petstore/petstore.yaml +804 -0
  218. package/src/api/controllers/query/import/sources/tests/openapi3/openapi3.spec.js +240 -0
  219. package/src/api/controllers/query/import/tests/index.spec.js +43 -0
  220. package/src/api/controllers/row/internal.js +5 -1
  221. package/src/api/routes/analytics.js +2 -2
  222. package/src/api/routes/table.js +1 -1
  223. package/src/api/routes/tests/misc.spec.js +2 -2
  224. package/src/automations/utils.js +5 -1
  225. package/src/definitions/datasource.ts +2 -5
  226. package/src/definitions/openapi.ts +480 -470
  227. package/src/environment.js +2 -0
  228. package/src/integrations/base/sql.ts +14 -9
  229. package/src/integrations/dynamodb.ts +3 -1
  230. package/src/integrations/firebase.ts +205 -0
  231. package/src/integrations/googlesheets.ts +16 -1
  232. package/src/integrations/index.ts +4 -1
  233. package/src/integrations/mysql.ts +15 -1
  234. package/src/integrations/rest.ts +2 -1
  235. package/src/integrations/tests/sql.spec.js +51 -0
  236. package/src/middleware/authorized.js +26 -6
  237. package/builder/assets/index.2dcb5072.js +0 -1291
@@ -8,11 +8,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ const { cloneDeep } = require("lodash");
11
12
  const { definitions } = require("../../integrations");
13
+ const { getTenantId } = require("@budibase/backend-core/tenancy");
14
+ const { SourceNames } = require("../../definitions/datasource");
15
+ const googlesheets = require("../../integrations/googlesheets");
16
+ const env = require("../../environment");
12
17
  exports.fetch = function (ctx) {
13
18
  return __awaiter(this, void 0, void 0, function* () {
14
19
  ctx.status = 200;
15
- ctx.body = definitions;
20
+ const defs = cloneDeep(definitions);
21
+ // for google sheets integration google verification
22
+ if (env.EXCLUDE_QUOTAS_TENANTS) {
23
+ const excludedTenants = env.EXCLUDE_QUOTAS_TENANTS.split(",");
24
+ const tenantId = getTenantId();
25
+ if (excludedTenants.includes(tenantId)) {
26
+ defs[SourceNames.GOOGLE_SHEETS] = googlesheets.schema;
27
+ }
28
+ }
29
+ ctx.body = defs;
16
30
  });
17
31
  };
18
32
  exports.find = function (ctx) {
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  const { getBuiltinPermissions } = require("@budibase/backend-core/permissions");
12
- const { isBuiltin, getDBRoleID, getExternalRoleID, getBuiltinRoles, } = require("@budibase/backend-core/roles");
12
+ const { isBuiltin, getDBRoleID, getExternalRoleID, getBuiltinRoles, checkForRoleResourceArray, } = require("@budibase/backend-core/roles");
13
13
  const { getRoleParams } = require("../../db/utils");
14
14
  const { CURRENTLY_SUPPORTED_LEVELS, getBasePermissions, } = require("../../utilities/security");
15
15
  const { removeFromArray } = require("../../utilities");
@@ -130,11 +130,10 @@ exports.getResourcePerms = function (ctx) {
130
130
  for (let level of SUPPORTED_LEVELS) {
131
131
  // update the various roleIds in the resource permissions
132
132
  for (let role of roles) {
133
- const rolePerms = role.permissions;
133
+ const rolePerms = checkForRoleResourceArray(role.permissions, resourceId);
134
134
  if (rolePerms &&
135
135
  rolePerms[resourceId] &&
136
- (rolePerms[resourceId] === level ||
137
- rolePerms[resourceId].indexOf(level) !== -1)) {
136
+ rolePerms[resourceId].indexOf(level) !== -1) {
138
137
  permissions[level] = getExternalRoleID(role._id);
139
138
  }
140
139
  }
@@ -13,6 +13,7 @@ exports.RestImporter = void 0;
13
13
  const validation_1 = require("../validation");
14
14
  const utils_1 = require("../../../../db/utils");
15
15
  const openapi2_1 = require("./sources/openapi2");
16
+ const openapi3_1 = require("./sources/openapi3");
16
17
  const curl_1 = require("./sources/curl");
17
18
  // @ts-ignore
18
19
  const context_1 = require("@budibase/backend-core/context");
@@ -71,7 +72,7 @@ class RestImporter {
71
72
  };
72
73
  });
73
74
  this.data = data;
74
- this.sources = [new openapi2_1.OpenAPI2(), new curl_1.Curl()];
75
+ this.sources = [new openapi2_1.OpenAPI2(), new openapi3_1.OpenAPI3(), new curl_1.Curl()];
75
76
  }
76
77
  }
77
78
  exports.RestImporter = RestImporter;
@@ -17,7 +17,18 @@ class ImportSource {
17
17
  const transformer = "return data";
18
18
  const schema = {};
19
19
  path = this.processPath(path);
20
- path = `${url.origin}/${path}`;
20
+ if (url) {
21
+ if (typeof url === "string") {
22
+ path = `${url}/${path}`;
23
+ }
24
+ else {
25
+ let href = url.href;
26
+ if (href.endsWith("/")) {
27
+ href = href.slice(0, -1);
28
+ }
29
+ path = `${href}/${path}`;
30
+ }
31
+ }
21
32
  queryString = this.processQuery(queryString);
22
33
  const requestBody = JSON.stringify(body, null, 2);
23
34
  const query = {
@@ -79,7 +79,7 @@ class Curl extends base_1.ImportSource {
79
79
  this.getQueries = (datasourceId) => __awaiter(this, void 0, void 0, function* () {
80
80
  const url = this.getUrl();
81
81
  const name = url.pathname;
82
- const path = url.pathname;
82
+ const path = url.origin + url.pathname;
83
83
  const method = this.curl.method;
84
84
  const queryString = url.search;
85
85
  const headers = this.curl.headers;
@@ -88,7 +88,7 @@ class Curl extends base_1.ImportSource {
88
88
  if (cookieHeader) {
89
89
  headers["Cookie"] = cookieHeader;
90
90
  }
91
- const query = this.constructQuery(datasourceId, name, method, path, url, queryString, headers, [], requestBody);
91
+ const query = this.constructQuery(datasourceId, name, method, path, undefined, queryString, headers, [], requestBody);
92
92
  return [query];
93
93
  });
94
94
  }
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.OpenAPI3 = void 0;
13
+ const openapi_types_1 = require("openapi-types");
14
+ const openapi_1 = require("./base/openapi");
15
+ const url_1 = require("url");
16
+ const parameterNotRef = (param) => {
17
+ // all refs are deferenced by parser library
18
+ return true;
19
+ };
20
+ const requestBodyNotRef = (param) => {
21
+ // all refs are deferenced by parser library
22
+ return param !== undefined;
23
+ };
24
+ const schemaNotRef = (param) => {
25
+ // all refs are deferenced by parser library
26
+ return param !== undefined;
27
+ };
28
+ const isOpenAPI3 = (document) => {
29
+ return document.openapi.includes("3.0");
30
+ };
31
+ const methods = Object.values(openapi_types_1.OpenAPIV3.HttpMethods);
32
+ const isOperation = (key, pathItem) => {
33
+ return methods.includes(key);
34
+ };
35
+ const isParameter = (key, pathItem) => {
36
+ return !isOperation(key, pathItem);
37
+ };
38
+ const getRequestBody = (operation) => {
39
+ if (requestBodyNotRef(operation.requestBody)) {
40
+ const request = operation.requestBody;
41
+ const supportedMimeTypes = getMimeTypes(operation);
42
+ if (supportedMimeTypes.length > 0) {
43
+ const mimeType = supportedMimeTypes[0];
44
+ // try get example from request
45
+ const content = request.content[mimeType];
46
+ if (content.example) {
47
+ return content.example;
48
+ }
49
+ // try get example from schema
50
+ if (schemaNotRef(content.schema)) {
51
+ const schema = content.schema;
52
+ if (schema.example) {
53
+ return schema.example;
54
+ }
55
+ }
56
+ }
57
+ }
58
+ return undefined;
59
+ };
60
+ const getMimeTypes = (operation) => {
61
+ if (requestBodyNotRef(operation.requestBody)) {
62
+ const request = operation.requestBody;
63
+ return Object.keys(request.content);
64
+ }
65
+ return [];
66
+ };
67
+ /**
68
+ * OpenAPI Version 3.0
69
+ * https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md
70
+ */
71
+ class OpenAPI3 extends openapi_1.OpenAPISource {
72
+ constructor() {
73
+ super(...arguments);
74
+ this.isSupported = (data) => __awaiter(this, void 0, void 0, function* () {
75
+ try {
76
+ const document = yield this.parseData(data);
77
+ if (isOpenAPI3(document)) {
78
+ this.document = document;
79
+ return true;
80
+ }
81
+ else {
82
+ return false;
83
+ }
84
+ }
85
+ catch (err) {
86
+ return false;
87
+ }
88
+ });
89
+ this.getInfo = () => __awaiter(this, void 0, void 0, function* () {
90
+ const name = this.document.info.title || "OpenAPI Import";
91
+ return {
92
+ name,
93
+ };
94
+ });
95
+ this.getQueries = (datasourceId) => __awaiter(this, void 0, void 0, function* () {
96
+ var _a;
97
+ let url;
98
+ if ((_a = this.document.servers) === null || _a === void 0 ? void 0 : _a.length) {
99
+ url = this.document.servers[0].url;
100
+ try {
101
+ url = new url_1.URL(url);
102
+ }
103
+ catch (err) {
104
+ // unable to construct url, e.g. with variables
105
+ // proceed with string form of url
106
+ }
107
+ }
108
+ const queries = [];
109
+ for (let [path, pathItemObject] of Object.entries(this.document.paths)) {
110
+ // parameters that apply to every operation in the path
111
+ let pathParams = [];
112
+ // pathItemObject can be undefined
113
+ if (!pathItemObject) {
114
+ continue;
115
+ }
116
+ for (let [key, opOrParams] of Object.entries(pathItemObject)) {
117
+ if (isParameter(key, opOrParams)) {
118
+ const pathParameters = opOrParams;
119
+ pathParams.push(...pathParameters);
120
+ continue;
121
+ }
122
+ // can not be a parameter, must be an operation
123
+ const operation = opOrParams;
124
+ const methodName = key;
125
+ const name = operation.operationId || path;
126
+ let queryString = "";
127
+ const headers = {};
128
+ let requestBody = getRequestBody(operation);
129
+ const parameters = [];
130
+ const mimeTypes = getMimeTypes(operation);
131
+ if (mimeTypes.length > 0) {
132
+ headers["Content-Type"] = mimeTypes[0];
133
+ }
134
+ // combine the path parameters with the operation parameters
135
+ const operationParams = operation.parameters || [];
136
+ const allParams = [...pathParams, ...operationParams];
137
+ for (let param of allParams) {
138
+ if (parameterNotRef(param)) {
139
+ switch (param.in) {
140
+ case "query":
141
+ let prefix = "";
142
+ if (queryString) {
143
+ prefix = "&";
144
+ }
145
+ queryString = `${queryString}${prefix}${param.name}={{${param.name}}}`;
146
+ break;
147
+ case "header":
148
+ headers[param.name] = `{{${param.name}}}`;
149
+ break;
150
+ case "path":
151
+ // do nothing: param is already in the path
152
+ break;
153
+ case "formData":
154
+ // future enhancement
155
+ break;
156
+ }
157
+ // add the parameter if it can be bound in our config
158
+ if (["query", "header", "path"].includes(param.in)) {
159
+ parameters.push({
160
+ name: param.name,
161
+ default: "",
162
+ });
163
+ }
164
+ }
165
+ }
166
+ const query = this.constructQuery(datasourceId, name, methodName, path, url, queryString, headers, parameters, requestBody);
167
+ queries.push(query);
168
+ }
169
+ }
170
+ return queries;
171
+ });
172
+ }
173
+ }
174
+ exports.OpenAPI3 = OpenAPI3;
@@ -0,0 +1,253 @@
1
+ {
2
+ "openapi": "3.0.2",
3
+ "info": {
4
+ "description": "A basic swagger file",
5
+ "version": "1.0.0",
6
+ "title": "CRUD"
7
+ },
8
+ "servers": [
9
+ {
10
+ "url": "http://example.com"
11
+ }
12
+ ],
13
+ "tags": [
14
+ {
15
+ "name": "entity"
16
+ }
17
+ ],
18
+ "paths": {
19
+ "/entities": {
20
+ "post": {
21
+ "tags": [
22
+ "entity"
23
+ ],
24
+ "operationId": "createEntity",
25
+ "requestBody": {
26
+ "content": {
27
+ "application/json": {
28
+ "schema": {
29
+ "$ref": "#/components/schemas/CreateEntity"
30
+ }
31
+ }
32
+ }
33
+ },
34
+ "responses": {
35
+ "200": {
36
+ "description": "successful operation",
37
+ "content": {
38
+ "application/json": {
39
+ "schema": {
40
+ "$ref": "#/components/schemas/Entity"
41
+ }
42
+ }
43
+ }
44
+ }
45
+ }
46
+ },
47
+ "get": {
48
+ "tags": [
49
+ "entity"
50
+ ],
51
+ "operationId": "getEntities",
52
+ "parameters": [
53
+ {
54
+ "$ref": "#/components/parameters/PageParameter"
55
+ },
56
+ {
57
+ "$ref": "#/components/parameters/SizeParameter"
58
+ }
59
+ ],
60
+ "responses": {
61
+ "200": {
62
+ "description": "successful operation",
63
+ "content": {
64
+ "application/json": {
65
+ "schema": {
66
+ "$ref": "#/components/schemas/Entities"
67
+ }
68
+ }
69
+ }
70
+ }
71
+ }
72
+ }
73
+ },
74
+ "/entities/{entityId}": {
75
+ "parameters": [
76
+ {
77
+ "$ref": "#/components/parameters/EntityIdParameter"
78
+ }
79
+ ],
80
+ "get": {
81
+ "tags": [
82
+ "entity"
83
+ ],
84
+ "operationId": "getEntity",
85
+ "responses": {
86
+ "200": {
87
+ "description": "successful operation",
88
+ "content": {
89
+ "application/json": {
90
+ "schema": {
91
+ "$ref": "#/components/schemas/Entity"
92
+ }
93
+ }
94
+ }
95
+ }
96
+ }
97
+ },
98
+ "put": {
99
+ "tags": [
100
+ "entity"
101
+ ],
102
+ "operationId": "updateEntity",
103
+ "requestBody": {
104
+ "content": {
105
+ "application/json": {
106
+ "schema": {
107
+ "$ref": "#/components/schemas/Entity"
108
+ }
109
+ }
110
+ }
111
+ },
112
+ "responses": {
113
+ "200": {
114
+ "description": "successful operation",
115
+ "content": {
116
+ "application/json": {
117
+ "schema": {
118
+ "$ref": "#/components/schemas/Entity"
119
+ }
120
+ }
121
+ }
122
+ }
123
+ }
124
+ },
125
+ "patch": {
126
+ "tags": [
127
+ "entity"
128
+ ],
129
+ "operationId": "patchEntity",
130
+ "requestBody": {
131
+ "content": {
132
+ "application/json": {
133
+ "schema": {
134
+ "$ref": "#/components/schemas/Entity"
135
+ }
136
+ }
137
+ }
138
+ },
139
+ "responses": {
140
+ "200": {
141
+ "description": "successful operation",
142
+ "content": {
143
+ "application/json": {
144
+ "schema": {
145
+ "$ref": "#/components/schemas/Entity"
146
+ }
147
+ }
148
+ }
149
+ }
150
+ }
151
+ },
152
+ "delete": {
153
+ "tags": [
154
+ "entity"
155
+ ],
156
+ "parameters": [
157
+ {
158
+ "$ref": "#/components/parameters/APIKeyParameter"
159
+ }
160
+ ],
161
+ "operationId": "deleteEntity",
162
+ "responses": {
163
+ "204": {
164
+ "description": "successful operation"
165
+ }
166
+ }
167
+ }
168
+ }
169
+ },
170
+ "components": {
171
+ "parameters": {
172
+ "EntityIdParameter": {
173
+ "schema": {
174
+ "type": "integer",
175
+ "format": "int64"
176
+ },
177
+ "name": "entityId",
178
+ "in": "path",
179
+ "required": true
180
+ },
181
+ "PageParameter": {
182
+ "schema": {
183
+ "type": "integer",
184
+ "format": "int32"
185
+ },
186
+ "name": "page",
187
+ "in": "query",
188
+ "required": false
189
+ },
190
+ "SizeParameter": {
191
+ "schema": {
192
+ "type": "integer",
193
+ "format": "int32"
194
+ },
195
+ "name": "size",
196
+ "in": "query",
197
+ "required": false
198
+ },
199
+ "APIKeyParameter": {
200
+ "schema": {
201
+ "type": "string"
202
+ },
203
+ "name": "x-api-key",
204
+ "in": "header",
205
+ "required": false
206
+ }
207
+ },
208
+ "schemas": {
209
+ "CreateEntity": {
210
+ "type": "object",
211
+ "properties": {
212
+ "name": {
213
+ "type": "string"
214
+ },
215
+ "type": {
216
+ "type": "string"
217
+ }
218
+ },
219
+ "example": {
220
+ "name": "name",
221
+ "type": "type"
222
+ }
223
+ },
224
+ "Entity": {
225
+ "allOf": [
226
+ {
227
+ "type": "object",
228
+ "properties": {
229
+ "id": {
230
+ "type": "integer",
231
+ "format": "int64"
232
+ }
233
+ }
234
+ },
235
+ {
236
+ "$ref": "#/components/schemas/CreateEntity"
237
+ }
238
+ ],
239
+ "example": {
240
+ "id": 1,
241
+ "name": "name",
242
+ "type": "type"
243
+ }
244
+ },
245
+ "Entities" : {
246
+ "type": "array",
247
+ "items": {
248
+ "$ref": "#/components/schemas/Entity"
249
+ }
250
+ }
251
+ }
252
+ }
253
+ }