@asyncapi/converter 1.3.0 → 1.3.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.
@@ -109,6 +109,10 @@ function convertChannelObjects(channels, asyncapi, options, context, inComponent
109
109
  if (Array.isArray(servers)) {
110
110
  channel.servers = servers.map((serverName) => (0, utils_1.createRefObject)('servers', serverName));
111
111
  }
112
+ //Change parameter formats
113
+ if ((0, utils_1.isPlainObject)(channel.parameters)) {
114
+ channel.parameters = convertParameters(channel.parameters);
115
+ }
112
116
  const operations = {};
113
117
  // serialize publish and subscribe Operation Objects to standalone object
114
118
  const publishMessages = toStandaloneOperation({ kind: 'publish', channel, asyncapi, operations, context, inComponents, channelId, channelAddress, options, oldPath });
@@ -270,6 +274,47 @@ function convertComponents(asyncapi, options, context) {
270
274
  messages: components.messages
271
275
  });
272
276
  }
277
+ if ((0, utils_1.isPlainObject)(components.parameters)) {
278
+ components.parameters = convertParameters(components.parameters);
279
+ }
280
+ }
281
+ /**
282
+ * Convert all parameters to the new v3 format
283
+ */
284
+ function convertParameters(parameters) {
285
+ const newParameters = {};
286
+ Object.entries(parameters).forEach(([name, parameter]) => {
287
+ newParameters[name] = convertParameter(parameter);
288
+ });
289
+ return newParameters;
290
+ }
291
+ /**
292
+ * Convert the old v2 parameter object to v3.
293
+ *
294
+ * Ensure that extensions and references are all kept as is.
295
+ *
296
+ * Does not include extensions from schema.
297
+ */
298
+ function convertParameter(parameter) {
299
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
300
+ const ref = (_a = parameter['$ref']) !== null && _a !== void 0 ? _a : null;
301
+ if (ref !== null) {
302
+ return {
303
+ $ref: ref
304
+ };
305
+ }
306
+ const enumValues = (_c = (_b = parameter.schema) === null || _b === void 0 ? void 0 : _b.enum) !== null && _c !== void 0 ? _c : null;
307
+ const defaultValues = (_e = (_d = parameter.schema) === null || _d === void 0 ? void 0 : _d.default) !== null && _e !== void 0 ? _e : null;
308
+ const description = (_h = (_f = parameter.description) !== null && _f !== void 0 ? _f : (_g = parameter.schema) === null || _g === void 0 ? void 0 : _g.description) !== null && _h !== void 0 ? _h : null;
309
+ const examples = (_k = (_j = parameter.schema) === null || _j === void 0 ? void 0 : _j.examples) !== null && _k !== void 0 ? _k : null;
310
+ const location = (_l = parameter.location) !== null && _l !== void 0 ? _l : null;
311
+ //Make sure we keep parameter extensions
312
+ const v2ParameterObjectProperties = ["location", "schema", "description"];
313
+ const v2ParameterObjectExtensions = Object.entries(parameter).filter(([key,]) => {
314
+ return !v2ParameterObjectProperties.includes(key);
315
+ });
316
+ //Return the new v3 parameter object
317
+ return Object.assign(Object.assign({}, v2ParameterObjectExtensions), enumValues === null ? null : { enum: enumValues }, defaultValues === null ? null : { default: defaultValues }, description === null ? null : { description }, examples === null ? null : { examples }, location === null ? null : { location });
273
318
  }
274
319
  /**
275
320
  * Convert `channels`, `servers` and `securitySchemes` in components.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asyncapi/converter",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "Convert AsyncAPI documents from older to newer versions.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -38,7 +38,7 @@
38
38
  "author": "Fran Mendez <fmvilas@gmail.com> (fmvilas.com)",
39
39
  "license": "Apache-2.0",
40
40
  "dependencies": {
41
- "@asyncapi/parser": "^2.0.0-next-major.11",
41
+ "@asyncapi/parser": "^2.1.0",
42
42
  "js-yaml": "^3.14.1"
43
43
  },
44
44
  "devDependencies": {