@asyncapi/converter 1.4.0 → 1.4.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.
- package/README.md +30 -1
- package/lib/third-version.js +29 -8
- package/package.json +2 -2
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(),
|
|
@@ -297,25 +297,46 @@ function convertParameters(parameters) {
|
|
|
297
297
|
* Does not include extensions from schema.
|
|
298
298
|
*/
|
|
299
299
|
function convertParameter(parameter) {
|
|
300
|
-
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;
|
|
301
301
|
const ref = (_a = parameter['$ref']) !== null && _a !== void 0 ? _a : null;
|
|
302
302
|
if (ref !== null) {
|
|
303
303
|
return {
|
|
304
304
|
$ref: ref
|
|
305
305
|
};
|
|
306
306
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
const
|
|
311
|
-
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);
|
|
312
317
|
//Make sure we keep parameter extensions
|
|
313
318
|
const v2ParameterObjectProperties = ["location", "schema", "description"];
|
|
314
319
|
const v2ParameterObjectExtensions = Object.entries(parameter).filter(([key,]) => {
|
|
315
320
|
return !v2ParameterObjectProperties.includes(key);
|
|
316
321
|
});
|
|
317
322
|
//Return the new v3 parameter object
|
|
318
|
-
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
|
+
}
|
|
319
340
|
}
|
|
320
341
|
/**
|
|
321
342
|
* 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.4.
|
|
3
|
+
"version": "1.4.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.1.
|
|
41
|
+
"@asyncapi/parser": "^2.1.2",
|
|
42
42
|
"js-yaml": "^3.14.1"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|