@onlineapps/conn-orch-api-mapper 1.0.1 → 1.0.2

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/ApiMapper.js +68 -22
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onlineapps/conn-orch-api-mapper",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "API mapping connector for OA Drive - maps cookbook operations to HTTP endpoints",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/ApiMapper.js CHANGED
@@ -184,42 +184,88 @@ class ApiMapper {
184
184
  }
185
185
 
186
186
  /**
187
- * Parse OpenAPI specification to extract operations
187
+ * Parse OpenAPI specification or operations.json to extract operations
188
188
  * @private
189
- * @param {Object} spec - OpenAPI specification
189
+ * @param {Object} spec - OpenAPI specification or operations.json format
190
190
  * @returns {Object} Operations map
191
191
  */
192
192
  _parseOpenApiSpec(spec) {
193
193
  const operations = {};
194
194
 
195
- if (!spec || !spec.paths) {
195
+ if (!spec || typeof spec !== 'object') {
196
196
  return operations;
197
197
  }
198
198
 
199
- // Extract all operations from OpenAPI paths
200
- Object.entries(spec.paths).forEach(([path, pathItem]) => {
201
- Object.entries(pathItem).forEach(([method, operation]) => {
202
- if (['get', 'post', 'put', 'patch', 'delete'].includes(method)) {
203
- const operationId = operation.operationId ||
204
- `${method}_${path.replace(/[^a-zA-Z0-9]/g, '_')}`;
205
-
206
- operations[operationId] = {
207
- method: method.toUpperCase(),
208
- path,
209
- parameters: operation.parameters || [],
210
- requestBody: operation.requestBody,
211
- responses: operation.responses,
212
- summary: operation.summary,
213
- description: operation.description
214
- };
215
- }
199
+ // Check if this is operations.json format (has "operations" key at root)
200
+ if (spec.operations && typeof spec.operations === 'object') {
201
+ // Parse operations.json format
202
+ Object.entries(spec.operations).forEach(([operationId, operation]) => {
203
+ operations[operationId] = {
204
+ method: (operation.method || 'POST').toUpperCase(),
205
+ path: operation.endpoint || `/${operationId}`,
206
+ parameters: operation.input ? this._convertOperationsJsonInputToOpenApi(operation.input) : [],
207
+ requestBody: operation.input ? { content: { 'application/json': { schema: { type: 'object', properties: operation.input } } } } : undefined,
208
+ responses: operation.output ? { '200': { description: 'Success', content: { 'application/json': { schema: { type: 'object', properties: operation.output } } } } } : { '200': { description: 'Success' } },
209
+ summary: operation.description,
210
+ description: operation.description
211
+ };
216
212
  });
217
- });
213
+ this.logger?.info(`Parsed ${Object.keys(operations).length} operations from operations.json format`);
214
+ return operations;
215
+ }
218
216
 
219
- this.logger.info(`Parsed ${Object.keys(operations).length} operations from OpenAPI spec`);
217
+ // Extract all operations from OpenAPI paths (original OpenAPI format)
218
+ if (spec.paths) {
219
+ Object.entries(spec.paths).forEach(([path, pathItem]) => {
220
+ Object.entries(pathItem).forEach(([method, operation]) => {
221
+ if (['get', 'post', 'put', 'patch', 'delete'].includes(method)) {
222
+ const operationId = operation.operationId ||
223
+ `${method}_${path.replace(/[^a-zA-Z0-9]/g, '_')}`;
224
+
225
+ operations[operationId] = {
226
+ method: method.toUpperCase(),
227
+ path,
228
+ parameters: operation.parameters || [],
229
+ requestBody: operation.requestBody,
230
+ responses: operation.responses,
231
+ summary: operation.summary,
232
+ description: operation.description
233
+ };
234
+ }
235
+ });
236
+ });
237
+ }
238
+
239
+ this.logger?.info(`Parsed ${Object.keys(operations).length} operations from OpenAPI spec`);
220
240
  return operations;
221
241
  }
222
242
 
243
+ /**
244
+ * Convert operations.json input format to OpenAPI parameters
245
+ * @private
246
+ * @param {Object} input - operations.json input schema
247
+ * @returns {Array} OpenAPI parameters array
248
+ */
249
+ _convertOperationsJsonInputToOpenApi(input) {
250
+ const parameters = [];
251
+ Object.entries(input).forEach(([name, schema]) => {
252
+ parameters.push({
253
+ name,
254
+ in: 'body', // operations.json uses body parameters
255
+ required: schema.required !== false,
256
+ schema: {
257
+ type: schema.type || 'string',
258
+ description: schema.description,
259
+ minLength: schema.minLength,
260
+ maxLength: schema.maxLength,
261
+ enum: schema.enum,
262
+ default: schema.default
263
+ }
264
+ });
265
+ });
266
+ return parameters;
267
+ }
268
+
223
269
  /**
224
270
  * Resolve variables in input using context
225
271
  * @private