@asyncapi/converter 1.3.3 → 1.4.1
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.
- package/README.md +30 -1
- package/lib/third-version.js +30 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -96,7 +96,7 @@ try {
|
|
|
96
96
|
|
|
97
97
|
> **NOTE**: This feature is still WIP, and is until the final release of `3.0.0`.
|
|
98
98
|
|
|
99
|
-
Conversion to version `3.x.x` from `2.x.x` has several assumptions that should be
|
|
99
|
+
Conversion to version `3.x.x` from `2.x.x` has several assumptions that should be known before converting:
|
|
100
100
|
|
|
101
101
|
- The input must be valid AsyncAPI document.
|
|
102
102
|
- External references are not resolved and converted, they remain untouched, even if they are incorrect.
|
|
@@ -164,6 +164,35 @@ Conversion to version `3.x.x` from `2.x.x` has several assumptions that should b
|
|
|
164
164
|
## Known missing features
|
|
165
165
|
|
|
166
166
|
* When converting from 1.x to 2.x, Streaming APIs (those using `stream` instead of `topics` or `events`) are converted correctly but information about framing type and delimiter is missing until a [protocolInfo](https://github.com/asyncapi/extensions-catalog/issues/1) for that purpose is created.
|
|
167
|
+
* When converting from 2.x to 3.x, and `parameter.schema` is defined with a reference, it will NOT look into the schema reference and include any relevant keywords for the v3 parameter. It will just create an empty parameter but leave the schema in the components section as is.
|
|
168
|
+
```yaml
|
|
169
|
+
# 2.x.x
|
|
170
|
+
channels:
|
|
171
|
+
"{myParameter}":
|
|
172
|
+
parameters:
|
|
173
|
+
myParameter:
|
|
174
|
+
schema:
|
|
175
|
+
$ref: "#/components/schemas/mySchema"
|
|
176
|
+
components:
|
|
177
|
+
schemas:
|
|
178
|
+
mySchema:
|
|
179
|
+
enum: ["test"]
|
|
180
|
+
default: "test"
|
|
181
|
+
examples: ["test"]
|
|
182
|
+
|
|
183
|
+
# 3.0.0
|
|
184
|
+
channels:
|
|
185
|
+
"{myParameter}":
|
|
186
|
+
parameters:
|
|
187
|
+
myParameter: {}
|
|
188
|
+
|
|
189
|
+
components:
|
|
190
|
+
schemas:
|
|
191
|
+
mySchema:
|
|
192
|
+
enum: ["test"]
|
|
193
|
+
default: "test"
|
|
194
|
+
examples: ["test"]
|
|
195
|
+
```
|
|
167
196
|
|
|
168
197
|
## Development
|
|
169
198
|
|
package/lib/third-version.js
CHANGED
|
@@ -8,7 +8,7 @@ exports.converters = {
|
|
|
8
8
|
function from__2_6_0__to__3_0_0(asyncapi, options) {
|
|
9
9
|
var _a;
|
|
10
10
|
asyncapi.asyncapi = '3.0.0';
|
|
11
|
-
const v2tov3Options = Object.assign({ pointOfView: 'application', useChannelIdExtension: true, convertServerComponents: true, convertChannelComponents: true }, ((_a = options.v2tov3) !== null && _a !== void 0 ? _a : {}));
|
|
11
|
+
const v2tov3Options = Object.assign({ pointOfView: 'application', useChannelIdExtension: true, convertServerComponents: true, convertChannelComponents: true, failOnParameterReference: false }, ((_a = options.v2tov3) !== null && _a !== void 0 ? _a : {}));
|
|
12
12
|
v2tov3Options.idGenerator = v2tov3Options.idGenerator || idGeneratorFactory(v2tov3Options);
|
|
13
13
|
const context = {
|
|
14
14
|
refs: new Map(),
|
|
@@ -241,6 +241,7 @@ function convertMessages(data) {
|
|
|
241
241
|
const messages = Object.assign({}, data.messages);
|
|
242
242
|
// Convert schema formats to union schemas
|
|
243
243
|
Object.entries(messages).forEach(([_, message]) => {
|
|
244
|
+
delete message.messageId;
|
|
244
245
|
if (message.schemaFormat !== undefined) {
|
|
245
246
|
const payloadSchema = message.payload;
|
|
246
247
|
message.payload = {
|
|
@@ -296,25 +297,46 @@ function convertParameters(parameters) {
|
|
|
296
297
|
* Does not include extensions from schema.
|
|
297
298
|
*/
|
|
298
299
|
function convertParameter(parameter) {
|
|
299
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
300
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
300
301
|
const ref = (_a = parameter['$ref']) !== null && _a !== void 0 ? _a : null;
|
|
301
302
|
if (ref !== null) {
|
|
302
303
|
return {
|
|
303
304
|
$ref: ref
|
|
304
305
|
};
|
|
305
306
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
const
|
|
310
|
-
const
|
|
307
|
+
if ((_b = parameter.schema) === null || _b === void 0 ? void 0 : _b.$ref) {
|
|
308
|
+
console.warn('Could not convert parameter object because the `.schema` property was a reference.\nThis have to be changed manually if you want any of the properties included. For now your parameter is an empty object after conversion. The reference was ' + ((_c = parameter.schema) === null || _c === void 0 ? void 0 : _c.$ref));
|
|
309
|
+
}
|
|
310
|
+
const enumValues = (_e = (_d = parameter.schema) === null || _d === void 0 ? void 0 : _d.enum) !== null && _e !== void 0 ? _e : null;
|
|
311
|
+
const constValue = (_g = (_f = parameter.schema) === null || _f === void 0 ? void 0 : _f.const) !== null && _g !== void 0 ? _g : null;
|
|
312
|
+
const defaultValues = (_j = (_h = parameter.schema) === null || _h === void 0 ? void 0 : _h.default) !== null && _j !== void 0 ? _j : null;
|
|
313
|
+
const description = (_m = (_k = parameter.description) !== null && _k !== void 0 ? _k : (_l = parameter.schema) === null || _l === void 0 ? void 0 : _l.description) !== null && _m !== void 0 ? _m : null;
|
|
314
|
+
const examples = (_p = (_o = parameter.schema) === null || _o === void 0 ? void 0 : _o.examples) !== null && _p !== void 0 ? _p : null;
|
|
315
|
+
const location = (_q = parameter.location) !== null && _q !== void 0 ? _q : null;
|
|
316
|
+
reportUnsupportedParameterValues(parameter.schema);
|
|
311
317
|
//Make sure we keep parameter extensions
|
|
312
318
|
const v2ParameterObjectProperties = ["location", "schema", "description"];
|
|
313
319
|
const v2ParameterObjectExtensions = Object.entries(parameter).filter(([key,]) => {
|
|
314
320
|
return !v2ParameterObjectProperties.includes(key);
|
|
315
321
|
});
|
|
316
322
|
//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 });
|
|
323
|
+
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, v2ParameterObjectExtensions), (enumValues === null ? null : { enum: enumValues })), (constValue === null ? null : { enum: [constValue] })), (defaultValues === null ? null : { default: defaultValues })), (description === null ? null : { description })), (examples === null ? null : { examples })), (location === null ? null : { location }));
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* This function makes sure we complain if a parameter schema uses now unsupported properties
|
|
327
|
+
*/
|
|
328
|
+
function reportUnsupportedParameterValues(schema) {
|
|
329
|
+
if (schema === undefined)
|
|
330
|
+
return;
|
|
331
|
+
const excessProperties = Object.entries(schema).filter((([propertyName,]) => {
|
|
332
|
+
return !['$ref', 'enum', 'const', 'default', 'examples', 'description'].includes(propertyName);
|
|
333
|
+
}));
|
|
334
|
+
if (excessProperties.length > 0) {
|
|
335
|
+
const listOfProperties = excessProperties.map(([propertyName, property]) => {
|
|
336
|
+
return `- schema.${propertyName} with value: ${JSON.stringify(property)} are no longer supported`;
|
|
337
|
+
});
|
|
338
|
+
console.warn(`Found properties in parameter schema that are no longer supported. Conversion completes with empty parameter object.\n${listOfProperties.join('\n')}`);
|
|
339
|
+
}
|
|
318
340
|
}
|
|
319
341
|
/**
|
|
320
342
|
* Convert `channels`, `servers` and `securitySchemes` in components.
|