@budibase/server 1.0.91-alpha.3 → 1.0.91

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 (201) hide show
  1. package/builder/assets/{index.fc731251.js → index.afc77e6b.js} +185 -185
  2. package/builder/index.html +1 -1
  3. package/coverage/clover.xml +5 -5
  4. package/coverage/coverage-final.json +3 -3
  5. package/coverage/lcov-report/api/controllers/analytics.js.html +1 -1
  6. package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
  7. package/coverage/lcov-report/api/controllers/application.js.html +1 -1
  8. package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
  9. package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
  10. package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
  11. package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
  12. package/coverage/lcov-report/api/controllers/component.js.html +1 -1
  13. package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
  14. package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
  15. package/coverage/lcov-report/api/controllers/index.html +1 -1
  16. package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
  17. package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
  18. package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
  19. package/coverage/lcov-report/api/controllers/migrations.js.html +1 -1
  20. package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
  21. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  22. package/coverage/lcov-report/api/controllers/query/index.js.html +1 -1
  23. package/coverage/lcov-report/api/controllers/query/validation.js.html +2 -2
  24. package/coverage/lcov-report/api/controllers/role.js.html +1 -1
  25. package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
  26. package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
  27. package/coverage/lcov-report/api/controllers/row/index.html +1 -1
  28. package/coverage/lcov-report/api/controllers/row/index.js.html +1 -1
  29. package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
  30. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
  31. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +1 -1
  32. package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
  33. package/coverage/lcov-report/api/controllers/screen.js.html +1 -1
  34. package/coverage/lcov-report/api/controllers/script.js.html +1 -1
  35. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +1 -1
  36. package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
  37. package/coverage/lcov-report/api/controllers/table/index.html +1 -1
  38. package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
  39. package/coverage/lcov-report/api/controllers/table/internal.js.html +1 -1
  40. package/coverage/lcov-report/api/controllers/table/utils.js.html +1 -1
  41. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  42. package/coverage/lcov-report/api/controllers/user.js.html +1 -1
  43. package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
  44. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  45. package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
  46. package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
  47. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
  48. package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
  49. package/coverage/lcov-report/api/index.html +1 -1
  50. package/coverage/lcov-report/api/index.js.html +1 -1
  51. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  52. package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
  53. package/coverage/lcov-report/api/routes/application.js.html +1 -1
  54. package/coverage/lcov-report/api/routes/auth.js.html +1 -1
  55. package/coverage/lcov-report/api/routes/automation.js.html +1 -1
  56. package/coverage/lcov-report/api/routes/backup.js.html +1 -1
  57. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  58. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  59. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  60. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/dev.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/index.html +1 -1
  63. package/coverage/lcov-report/api/routes/index.js.html +1 -1
  64. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  65. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  66. package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/migrations.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/permission.js.html +1 -1
  69. package/coverage/lcov-report/api/routes/query.js.html +1 -1
  70. package/coverage/lcov-report/api/routes/role.js.html +1 -1
  71. package/coverage/lcov-report/api/routes/routing.js.html +1 -1
  72. package/coverage/lcov-report/api/routes/row.js.html +1 -1
  73. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  74. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  75. package/coverage/lcov-report/api/routes/static.js.html +1 -1
  76. package/coverage/lcov-report/api/routes/table.js.html +1 -1
  77. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  78. package/coverage/lcov-report/api/routes/user.js.html +1 -1
  79. package/coverage/lcov-report/api/routes/utils/index.html +1 -1
  80. package/coverage/lcov-report/api/routes/utils/validators.js.html +1 -1
  81. package/coverage/lcov-report/api/routes/view.js.html +1 -1
  82. package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
  83. package/coverage/lcov-report/automations/actions.js.html +1 -1
  84. package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
  85. package/coverage/lcov-report/automations/bullboard.js.html +1 -1
  86. package/coverage/lcov-report/automations/index.html +1 -1
  87. package/coverage/lcov-report/automations/index.js.html +1 -1
  88. package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
  89. package/coverage/lcov-report/automations/steps/createRow.js.html +1 -1
  90. package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
  91. package/coverage/lcov-report/automations/steps/deleteRow.js.html +1 -1
  92. package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
  93. package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
  94. package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
  95. package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
  96. package/coverage/lcov-report/automations/steps/index.html +1 -1
  97. package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
  98. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
  99. package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
  100. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
  101. package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
  102. package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
  103. package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
  104. package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
  105. package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
  106. package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
  107. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
  108. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  109. package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
  110. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
  111. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
  112. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
  113. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
  114. package/coverage/lcov-report/automations/triggers.js.html +1 -1
  115. package/coverage/lcov-report/automations/utils.js.html +1 -1
  116. package/coverage/lcov-report/constants/index.html +1 -1
  117. package/coverage/lcov-report/constants/index.js.html +1 -1
  118. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  119. package/coverage/lcov-report/constants/screens.js.html +1 -1
  120. package/coverage/lcov-report/db/client.js.html +1 -1
  121. package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
  122. package/coverage/lcov-report/db/index.html +1 -1
  123. package/coverage/lcov-report/db/index.js.html +1 -1
  124. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
  125. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  126. package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
  127. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
  128. package/coverage/lcov-report/db/newid.js.html +2 -2
  129. package/coverage/lcov-report/db/utils.js.html +2 -2
  130. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  131. package/coverage/lcov-report/events/index.html +1 -1
  132. package/coverage/lcov-report/events/index.js.html +1 -1
  133. package/coverage/lcov-report/events/utils.js.html +1 -1
  134. package/coverage/lcov-report/index.html +1 -1
  135. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  136. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  137. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  138. package/coverage/lcov-report/middleware/authorized.js.html +1 -1
  139. package/coverage/lcov-report/middleware/builder.js.html +1 -1
  140. package/coverage/lcov-report/middleware/currentapp.js.html +1 -1
  141. package/coverage/lcov-report/middleware/index.html +1 -1
  142. package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
  143. package/coverage/lcov-report/middleware/publicApi.js.html +1 -1
  144. package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
  145. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  146. package/coverage/lcov-report/middleware/usageQuota.js.html +1 -1
  147. package/coverage/lcov-report/middleware/utils.js.html +1 -1
  148. package/coverage/lcov-report/threads/automation.js.html +1 -1
  149. package/coverage/lcov-report/threads/index.html +1 -1
  150. package/coverage/lcov-report/threads/index.js.html +1 -1
  151. package/coverage/lcov-report/threads/query.js.html +1 -1
  152. package/coverage/lcov-report/threads/utils.js.html +1 -1
  153. package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
  154. package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
  155. package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
  156. package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
  157. package/coverage/lcov-report/utilities/global.js.html +1 -1
  158. package/coverage/lcov-report/utilities/index.html +1 -1
  159. package/coverage/lcov-report/utilities/index.js.html +1 -1
  160. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +1 -1
  161. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  162. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  163. package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
  164. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  165. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
  166. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
  167. package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
  168. package/coverage/lcov-report/utilities/security.js.html +1 -1
  169. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  170. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  171. package/coverage/lcov-report/utilities/usageQuota/index.js.html +1 -1
  172. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +1 -1
  173. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  174. package/coverage/lcov-report/utilities/users.js.html +1 -1
  175. package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
  176. package/coverage/lcov.info +6 -6
  177. package/dist/api/controllers/query/import/index.js +1 -2
  178. package/dist/api/controllers/query/import/sources/base/index.js +1 -12
  179. package/dist/api/controllers/query/import/sources/curl.js +2 -2
  180. package/dist/definitions/datasource.js +0 -1
  181. package/dist/integrations/index.js +0 -3
  182. package/dist/package.json +4 -5
  183. package/dist/tsconfig.tsbuildinfo +1 -1
  184. package/package.json +5 -6
  185. package/src/api/controllers/query/import/index.ts +1 -2
  186. package/src/api/controllers/query/import/sources/base/index.ts +2 -12
  187. package/src/api/controllers/query/import/sources/curl.ts +2 -2
  188. package/src/api/controllers/query/import/tests/index.spec.js +0 -43
  189. package/src/definitions/datasource.ts +0 -1
  190. package/src/integrations/index.ts +0 -3
  191. package/dist/api/controllers/query/import/sources/openapi3.js +0 -174
  192. package/dist/api/controllers/query/import/sources/tests/openapi3/data/crud/crud.json +0 -253
  193. package/dist/api/controllers/query/import/sources/tests/openapi3/data/petstore/petstore.json +0 -1225
  194. package/dist/integrations/firebase.js +0 -192
  195. package/src/api/controllers/query/import/sources/openapi3.ts +0 -205
  196. package/src/api/controllers/query/import/sources/tests/openapi3/data/crud/crud.json +0 -253
  197. package/src/api/controllers/query/import/sources/tests/openapi3/data/crud/crud.yaml +0 -153
  198. package/src/api/controllers/query/import/sources/tests/openapi3/data/petstore/petstore.json +0 -1225
  199. package/src/api/controllers/query/import/sources/tests/openapi3/data/petstore/petstore.yaml +0 -804
  200. package/src/api/controllers/query/import/sources/tests/openapi3/openapi3.spec.js +0 -240
  201. package/src/integrations/firebase.ts +0 -205
@@ -1,192 +0,0 @@
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
- const datasource_1 = require("../definitions/datasource");
13
- const firestore_1 = require("@google-cloud/firestore");
14
- var Firebase;
15
- (function (Firebase) {
16
- const SCHEMA = {
17
- docs: "https://firebase.google.com/docs/firestore/quickstart",
18
- friendlyName: "Firestore",
19
- description: "Cloud Firestore is a flexible, scalable database for mobile, web, and server development from Firebase and Google Cloud.",
20
- datasource: {
21
- email: {
22
- type: datasource_1.DatasourceFieldTypes.STRING,
23
- required: true,
24
- },
25
- privateKey: {
26
- type: datasource_1.DatasourceFieldTypes.STRING,
27
- required: true,
28
- },
29
- projectId: {
30
- type: datasource_1.DatasourceFieldTypes.STRING,
31
- required: true,
32
- },
33
- serviceAccount: {
34
- type: datasource_1.DatasourceFieldTypes.JSON,
35
- required: false,
36
- },
37
- },
38
- query: {
39
- create: {
40
- type: datasource_1.QueryTypes.JSON,
41
- },
42
- read: {
43
- type: datasource_1.QueryTypes.JSON,
44
- },
45
- update: {
46
- type: datasource_1.QueryTypes.JSON,
47
- },
48
- delete: {
49
- type: datasource_1.QueryTypes.JSON,
50
- },
51
- },
52
- extra: {
53
- collection: {
54
- displayName: "Collection",
55
- type: datasource_1.DatasourceFieldTypes.STRING,
56
- required: true,
57
- },
58
- filterField: {
59
- displayName: "Filter field",
60
- type: datasource_1.DatasourceFieldTypes.STRING,
61
- required: false,
62
- },
63
- filter: {
64
- displayName: "Filter comparison",
65
- type: datasource_1.DatasourceFieldTypes.LIST,
66
- required: false,
67
- data: {
68
- read: [
69
- "==",
70
- "<",
71
- "<=",
72
- "==",
73
- "!=",
74
- ">=",
75
- ">",
76
- "array-contains",
77
- "in",
78
- "not-in",
79
- "array-contains-any",
80
- ],
81
- },
82
- },
83
- filterValue: {
84
- displayName: "Filter value",
85
- type: datasource_1.DatasourceFieldTypes.STRING,
86
- required: false,
87
- },
88
- },
89
- };
90
- class FirebaseIntegration {
91
- constructor(config) {
92
- this.config = config;
93
- if (config.serviceAccount) {
94
- const serviceAccount = JSON.parse(config.serviceAccount);
95
- this.db = new firestore_1.Firestore({
96
- projectId: serviceAccount.project_id,
97
- credentials: {
98
- client_email: serviceAccount.client_email,
99
- private_key: serviceAccount.private_key,
100
- },
101
- });
102
- }
103
- else {
104
- this.db = new firestore_1.Firestore({
105
- projectId: config.projectId,
106
- credentials: {
107
- client_email: config.email,
108
- private_key: config.privateKey,
109
- },
110
- });
111
- }
112
- }
113
- create(query) {
114
- return __awaiter(this, void 0, void 0, function* () {
115
- try {
116
- const documentReference = this.db
117
- .collection(query.extra.collection)
118
- .doc();
119
- yield documentReference.set(Object.assign(Object.assign({}, query.json), { id: documentReference.id }));
120
- const snapshot = yield documentReference.get();
121
- return snapshot.data();
122
- }
123
- catch (err) {
124
- console.error("Error writing to Firestore", err);
125
- throw err;
126
- }
127
- });
128
- }
129
- read(query) {
130
- return __awaiter(this, void 0, void 0, function* () {
131
- try {
132
- let snapshot;
133
- const collectionRef = this.db.collection(query.extra.collection);
134
- if (query.extra.filterField &&
135
- query.extra.filter &&
136
- query.extra.filterValue) {
137
- snapshot = yield collectionRef
138
- .where(query.extra.filterField, query.extra.filter, query.extra.filterValue)
139
- .get();
140
- }
141
- else {
142
- snapshot = yield collectionRef.get();
143
- }
144
- const result = [];
145
- snapshot.forEach(doc => result.push(doc.data()));
146
- return result;
147
- }
148
- catch (err) {
149
- console.error("Error querying Firestore", err);
150
- throw err;
151
- }
152
- });
153
- }
154
- update(query) {
155
- return __awaiter(this, void 0, void 0, function* () {
156
- try {
157
- yield this.db
158
- .collection(query.extra.collection)
159
- .doc(query.json.id)
160
- .update(query.json);
161
- return (yield this.db
162
- .collection(query.extra.collection)
163
- .doc(query.json.id)
164
- .get()).data();
165
- }
166
- catch (err) {
167
- console.error("Error writing to firebase", err);
168
- throw err;
169
- }
170
- });
171
- }
172
- delete(query) {
173
- return __awaiter(this, void 0, void 0, function* () {
174
- try {
175
- yield this.db
176
- .collection(query.extra.collection)
177
- .doc(query.json.id)
178
- .delete();
179
- return true;
180
- }
181
- catch (err) {
182
- console.error("Error writing to mongodb", err);
183
- throw err;
184
- }
185
- });
186
- }
187
- }
188
- module.exports = {
189
- schema: SCHEMA,
190
- integration: FirebaseIntegration,
191
- };
192
- })(Firebase || (Firebase = {}));
@@ -1,205 +0,0 @@
1
- import { ImportInfo } from "./base"
2
- import { Query, QueryParameter } from "../../../../../definitions/datasource"
3
- import { OpenAPIV3 } from "openapi-types"
4
- import { OpenAPISource } from "./base/openapi"
5
- import { URL } from "url"
6
-
7
- const parameterNotRef = (
8
- param: OpenAPIV3.ParameterObject | OpenAPIV3.ReferenceObject
9
- ): param is OpenAPIV3.ParameterObject => {
10
- // all refs are deferenced by parser library
11
- return true
12
- }
13
-
14
- const requestBodyNotRef = (
15
- param: OpenAPIV3.RequestBodyObject | OpenAPIV3.ReferenceObject | undefined
16
- ): param is OpenAPIV3.RequestBodyObject => {
17
- // all refs are deferenced by parser library
18
- return param !== undefined
19
- }
20
-
21
- const schemaNotRef = (
22
- param: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject | undefined
23
- ): param is OpenAPIV3.SchemaObject => {
24
- // all refs are deferenced by parser library
25
- return param !== undefined
26
- }
27
-
28
- const isOpenAPI3 = (document: any): document is OpenAPIV3.Document => {
29
- return document.openapi.includes("3.0")
30
- }
31
-
32
- const methods: string[] = Object.values(OpenAPIV3.HttpMethods)
33
-
34
- const isOperation = (
35
- key: string,
36
- pathItem: any
37
- ): pathItem is OpenAPIV3.OperationObject => {
38
- return methods.includes(key)
39
- }
40
-
41
- const isParameter = (
42
- key: string,
43
- pathItem: any
44
- ): pathItem is OpenAPIV3.ParameterObject => {
45
- return !isOperation(key, pathItem)
46
- }
47
-
48
- const getRequestBody = (operation: OpenAPIV3.OperationObject) => {
49
- if (requestBodyNotRef(operation.requestBody)) {
50
- const request: OpenAPIV3.RequestBodyObject = operation.requestBody
51
- const supportedMimeTypes = getMimeTypes(operation)
52
- if (supportedMimeTypes.length > 0) {
53
- const mimeType = supportedMimeTypes[0]
54
-
55
- // try get example from request
56
- const content = request.content[mimeType]
57
- if (content.example) {
58
- return content.example
59
- }
60
-
61
- // try get example from schema
62
- if (schemaNotRef(content.schema)) {
63
- const schema = content.schema
64
- if (schema.example) {
65
- return schema.example
66
- }
67
- }
68
- }
69
- }
70
- return undefined
71
- }
72
-
73
- const getMimeTypes = (operation: OpenAPIV3.OperationObject): string[] => {
74
- if (requestBodyNotRef(operation.requestBody)) {
75
- const request: OpenAPIV3.RequestBodyObject = operation.requestBody
76
- return Object.keys(request.content)
77
- }
78
- return []
79
- }
80
-
81
- /**
82
- * OpenAPI Version 3.0
83
- * https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md
84
- */
85
- export class OpenAPI3 extends OpenAPISource {
86
- document!: OpenAPIV3.Document
87
-
88
- isSupported = async (data: string): Promise<boolean> => {
89
- try {
90
- const document: any = await this.parseData(data)
91
- if (isOpenAPI3(document)) {
92
- this.document = document
93
- return true
94
- } else {
95
- return false
96
- }
97
- } catch (err) {
98
- return false
99
- }
100
- }
101
-
102
- getInfo = async (): Promise<ImportInfo> => {
103
- const name = this.document.info.title || "OpenAPI Import"
104
- return {
105
- name,
106
- }
107
- }
108
-
109
- getQueries = async (datasourceId: string): Promise<Query[]> => {
110
- let url: string | URL | undefined
111
- if (this.document.servers?.length) {
112
- url = this.document.servers[0].url
113
- try {
114
- url = new URL(url)
115
- } catch (err) {
116
- // unable to construct url, e.g. with variables
117
- // proceed with string form of url
118
- }
119
- }
120
-
121
- const queries: Query[] = []
122
-
123
- for (let [path, pathItemObject] of Object.entries(this.document.paths)) {
124
- // parameters that apply to every operation in the path
125
- let pathParams: OpenAPIV3.ParameterObject[] = []
126
-
127
- // pathItemObject can be undefined
128
- if (!pathItemObject) {
129
- continue
130
- }
131
-
132
- for (let [key, opOrParams] of Object.entries(pathItemObject)) {
133
- if (isParameter(key, opOrParams)) {
134
- const pathParameters = opOrParams as OpenAPIV3.ParameterObject[]
135
- pathParams.push(...pathParameters)
136
- continue
137
- }
138
- // can not be a parameter, must be an operation
139
- const operation = opOrParams as OpenAPIV3.OperationObject
140
-
141
- const methodName = key
142
- const name = operation.operationId || path
143
- let queryString = ""
144
- const headers: any = {}
145
- let requestBody = getRequestBody(operation)
146
- const parameters: QueryParameter[] = []
147
- const mimeTypes = getMimeTypes(operation)
148
-
149
- if (mimeTypes.length > 0) {
150
- headers["Content-Type"] = mimeTypes[0]
151
- }
152
-
153
- // combine the path parameters with the operation parameters
154
- const operationParams = operation.parameters || []
155
- const allParams = [...pathParams, ...operationParams]
156
-
157
- for (let param of allParams) {
158
- if (parameterNotRef(param)) {
159
- switch (param.in) {
160
- case "query":
161
- let prefix = ""
162
- if (queryString) {
163
- prefix = "&"
164
- }
165
- queryString = `${queryString}${prefix}${param.name}={{${param.name}}}`
166
- break
167
- case "header":
168
- headers[param.name] = `{{${param.name}}}`
169
- break
170
- case "path":
171
- // do nothing: param is already in the path
172
- break
173
- case "formData":
174
- // future enhancement
175
- break
176
- }
177
-
178
- // add the parameter if it can be bound in our config
179
- if (["query", "header", "path"].includes(param.in)) {
180
- parameters.push({
181
- name: param.name,
182
- default: "",
183
- })
184
- }
185
- }
186
- }
187
-
188
- const query = this.constructQuery(
189
- datasourceId,
190
- name,
191
- methodName,
192
- path,
193
- url,
194
- queryString,
195
- headers,
196
- parameters,
197
- requestBody
198
- )
199
- queries.push(query)
200
- }
201
- }
202
-
203
- return queries
204
- }
205
- }
@@ -1,253 +0,0 @@
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
- }