@asyncapi/converter 1.5.1 → 1.6.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 +64 -16
- package/lib/convert.d.ts +3 -1
- package/lib/convert.js +12 -4
- package/lib/interfaces.d.ts +5 -0
- package/lib/openapi.d.ts +8 -1
- package/lib/openapi.js +2 -1
- package/lib/postman-collection.d.ts +2 -0
- package/lib/postman-collection.js +14 -0
- package/lib/utils.d.ts +1 -1
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Convert [AsyncAPI](https://asyncapi.com) documents older to newer versions and you can also convert OpenAPI documents to AsyncAPI documents.
|
|
4
4
|
|
|
5
5
|
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
6
|
-
[](#contributors-)
|
|
7
7
|
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
8
8
|
|
|
9
9
|
<!-- toc is generated with GitHub Actions do not remove toc markers -->
|
|
@@ -17,8 +17,10 @@ Convert [AsyncAPI](https://asyncapi.com) documents older to newer versions and y
|
|
|
17
17
|
* [In TS](#in-ts)
|
|
18
18
|
- [Conversion 2.x.x to 3.x.x](#conversion-2xx-to-3xx)
|
|
19
19
|
- [Known missing features](#known-missing-features)
|
|
20
|
-
|
|
20
|
+
- [OpenAPI 3.0 to AsyncAPI 3.0 Conversion](#openapi-30-to-asyncapi-30-conversion)
|
|
21
21
|
+ [Limitations](#limitations)
|
|
22
|
+
* [Postman Collection to AsyncAPI conversion](#postman-collection-to-asyncapi-conversion)
|
|
23
|
+
+ [Limitations](#limitations-1)
|
|
22
24
|
- [Development](#development)
|
|
23
25
|
- [Contribution](#contribution)
|
|
24
26
|
- [Contributors ✨](#contributors-%E2%9C%A8)
|
|
@@ -196,7 +198,7 @@ Conversion to version `3.x.x` from `2.x.x` has several assumptions that should b
|
|
|
196
198
|
examples: ["test"]
|
|
197
199
|
```
|
|
198
200
|
|
|
199
|
-
|
|
201
|
+
## OpenAPI 3.0 to AsyncAPI 3.0 Conversion
|
|
200
202
|
|
|
201
203
|
The converter now supports transformation from OpenAPI 3.0 to AsyncAPI 3.0. This feature enables easy transition of existing OpenAPI 3.0 documents to AsyncAPI 3.0.
|
|
202
204
|
|
|
@@ -239,6 +241,48 @@ The perspective option can be set to either 'server' (default) or 'client'.
|
|
|
239
241
|
|
|
240
242
|
- External to internal references: The converter does not support scenarios where an external schema file references internal components of the OpenAPI document. In such cases, manual adjustment of the converted document may be necessary.
|
|
241
243
|
|
|
244
|
+
### Postman Collection to AsyncAPI conversion
|
|
245
|
+
|
|
246
|
+
The converter now also supports conversion from postman collection to AsyncAPI 3.0. This feature enables easy transition of existing postman collection to any AsyncAPI 3.0 documents.
|
|
247
|
+
|
|
248
|
+
To use this new conversion feature:
|
|
249
|
+
|
|
250
|
+
```js
|
|
251
|
+
const fs = require('fs');
|
|
252
|
+
const { convertPostman } = require('@asyncapi/converter')
|
|
253
|
+
try {
|
|
254
|
+
const postman = fs.readFileSync('postman-collection.yml', 'utf-8')
|
|
255
|
+
const asyncapi = convertPostman(postman, '3.0.0');
|
|
256
|
+
console.log(asyncapi);
|
|
257
|
+
} catch (e) {
|
|
258
|
+
console.error(e);
|
|
259
|
+
}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
When converting from postman collection to AsyncAPI you can now specify the perspective of the conversion using the `perspective` option. This allows you to choose whether the conversion should be from an application or client point of view
|
|
263
|
+
|
|
264
|
+
```js
|
|
265
|
+
const { convertPostman } = require('@asyncapi/converter')
|
|
266
|
+
try {
|
|
267
|
+
const postman = fs.readFileSync('postman-collection.yml', 'utf-8')
|
|
268
|
+
const asyncapi = convertPostman(postman, '3.0.0', { perspective: 'client' });
|
|
269
|
+
console.log(asyncapi);
|
|
270
|
+
} catch (e) {
|
|
271
|
+
console.error(e);
|
|
272
|
+
}
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
The perspective option can be set to either 'server' (default) or 'client'.
|
|
276
|
+
|
|
277
|
+
- With `server` perspective: `action` becomes `receive`
|
|
278
|
+
|
|
279
|
+
- With `client` perspective: `action` becomes `send`
|
|
280
|
+
|
|
281
|
+
#### Limitations
|
|
282
|
+
|
|
283
|
+
- External to internal references: The converter does not support scenarios where an external schema file references internal components of the OpenAPI document. In such cases, manual adjustment of the converted document may be necessary.
|
|
284
|
+
|
|
285
|
+
|
|
242
286
|
## Development
|
|
243
287
|
|
|
244
288
|
1. Setup project by installing dependencies `npm install`
|
|
@@ -257,18 +301,22 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
257
301
|
<!-- prettier-ignore-start -->
|
|
258
302
|
<!-- markdownlint-disable -->
|
|
259
303
|
<table>
|
|
260
|
-
<
|
|
261
|
-
<
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
<
|
|
271
|
-
|
|
304
|
+
<tbody>
|
|
305
|
+
<tr>
|
|
306
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/magicmatatjahu"><img src="https://avatars.githubusercontent.com/u/20404945?v=4?s=100" width="100px;" alt="Maciej Urbańczyk"/><br /><sub><b>Maciej Urbańczyk</b></sub></a><br /><a href="#maintenance-magicmatatjahu" title="Maintenance">🚧</a> <a href="https://github.com/asyncapi/converter-js/commits?author=magicmatatjahu" title="Code">💻</a> <a href="https://github.com/asyncapi/converter-js/issues?q=author%3Amagicmatatjahu" title="Bug reports">🐛</a> <a href="https://github.com/asyncapi/converter-js/pulls?q=is%3Apr+reviewed-by%3Amagicmatatjahu" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/asyncapi/converter-js/commits?author=magicmatatjahu" title="Tests">⚠️</a> <a href="https://github.com/asyncapi/converter-js/commits?author=magicmatatjahu" title="Documentation">📖</a></td>
|
|
307
|
+
<td align="center" valign="top" width="14.28%"><a href="http://www.fmvilas.com/"><img src="https://avatars.githubusercontent.com/u/242119?v=4?s=100" width="100px;" alt="Fran Méndez"/><br /><sub><b>Fran Méndez</b></sub></a><br /><a href="#maintenance-fmvilas" title="Maintenance">🚧</a> <a href="https://github.com/asyncapi/converter-js/commits?author=fmvilas" title="Code">💻</a> <a href="https://github.com/asyncapi/converter-js/issues?q=author%3Afmvilas" title="Bug reports">🐛</a> <a href="https://github.com/asyncapi/converter-js/pulls?q=is%3Apr+reviewed-by%3Afmvilas" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/asyncapi/converter-js/commits?author=fmvilas" title="Tests">⚠️</a> <a href="https://github.com/asyncapi/converter-js/commits?author=fmvilas" title="Documentation">📖</a></td>
|
|
308
|
+
<td align="center" valign="top" width="14.28%"><a href="https://www.brainfart.dev/"><img src="https://avatars.githubusercontent.com/u/6995927?v=4?s=100" width="100px;" alt="Lukasz Gornicki"/><br /><sub><b>Lukasz Gornicki</b></sub></a><br /><a href="#maintenance-derberg" title="Maintenance">🚧</a> <a href="https://github.com/asyncapi/converter-js/commits?author=derberg" title="Code">💻</a> <a href="https://github.com/asyncapi/converter-js/issues?q=author%3Aderberg" title="Bug reports">🐛</a> <a href="https://github.com/asyncapi/converter-js/pulls?q=is%3Apr+reviewed-by%3Aderberg" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/asyncapi/converter-js/commits?author=derberg" title="Tests">⚠️</a> <a href="https://github.com/asyncapi/converter-js/commits?author=derberg" title="Documentation">📖</a> <a href="#infra-derberg" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
|
|
309
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/germanschnyder"><img src="https://avatars.githubusercontent.com/u/1844525?v=4?s=100" width="100px;" alt="Germán Schnyder"/><br /><sub><b>Germán Schnyder</b></sub></a><br /><a href="https://github.com/asyncapi/converter-js/commits?author=germanschnyder" title="Code">💻</a> <a href="https://github.com/asyncapi/converter-js/commits?author=germanschnyder" title="Tests">⚠️</a></td>
|
|
310
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/bszwarc"><img src="https://avatars.githubusercontent.com/u/17266942?v=4?s=100" width="100px;" alt="Barbara Czyż"/><br /><sub><b>Barbara Czyż</b></sub></a><br /><a href="#infra-bszwarc" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
|
|
311
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/depimomo"><img src="https://avatars.githubusercontent.com/u/12368942?v=4?s=100" width="100px;" alt="depimomo"/><br /><sub><b>depimomo</b></sub></a><br /><a href="https://github.com/asyncapi/converter-js/commits?author=depimomo" title="Code">💻</a></td>
|
|
312
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/crypto-cmd"><img src="https://avatars.githubusercontent.com/u/54287503?v=4?s=100" width="100px;" alt="Orville Daley"/><br /><sub><b>Orville Daley</b></sub></a><br /><a href="https://github.com/asyncapi/converter-js/commits?author=crypto-cmd" title="Code">💻</a></td>
|
|
313
|
+
</tr>
|
|
314
|
+
<tr>
|
|
315
|
+
<td align="center" valign="top" width="14.28%"><a href="https://www.arctype.co/"><img src="https://avatars.githubusercontent.com/u/549273?v=4?s=100" width="100px;" alt="Ryan R Sundberg"/><br /><sub><b>Ryan R Sundberg</b></sub></a><br /><a href="https://github.com/asyncapi/converter-js/commits?author=sundbry" title="Code">💻</a></td>
|
|
316
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ItshMoh"><img src="https://avatars.githubusercontent.com/u/121867882?v=4?s=100" width="100px;" alt="Mohan Kumar"/><br /><sub><b>Mohan Kumar</b></sub></a><br /><a href="https://github.com/asyncapi/converter-js/commits?author=ItshMoh" title="Code">💻</a> <a href="https://github.com/asyncapi/converter-js/commits?author=ItshMoh" title="Tests">⚠️</a> <a href="https://github.com/asyncapi/converter-js/commits?author=ItshMoh" title="Documentation">📖</a> <a href="#example-ItshMoh" title="Examples">💡</a></td>
|
|
317
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Gmin2"><img src="https://avatars.githubusercontent.com/u/127925465?v=4?s=100" width="100px;" alt="Mintu Gogoi"/><br /><sub><b>Mintu Gogoi</b></sub></a><br /><a href="https://github.com/asyncapi/converter-js/commits?author=Gmin2" title="Code">💻</a> <a href="https://github.com/asyncapi/converter-js/commits?author=Gmin2" title="Documentation">📖</a> <a href="#example-Gmin2" title="Examples">💡</a> <a href="https://github.com/asyncapi/converter-js/commits?author=Gmin2" title="Tests">⚠️</a></td>
|
|
318
|
+
</tr>
|
|
319
|
+
</tbody>
|
|
272
320
|
</table>
|
|
273
321
|
|
|
274
322
|
<!-- markdownlint-restore -->
|
|
@@ -276,4 +324,4 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
276
324
|
|
|
277
325
|
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
|
278
326
|
|
|
279
|
-
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
|
|
327
|
+
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
|
package/lib/convert.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import type { AsyncAPIDocument, AsyncAPIConvertVersion, OpenAPIConvertVersion, ConvertOptions, OpenAPIDocument, OpenAPIToAsyncAPIOptions } from './interfaces';
|
|
1
|
+
import type { AsyncAPIDocument, AsyncAPIConvertVersion, OpenAPIConvertVersion, ConvertOptions, OpenAPIDocument, OpenAPIToAsyncAPIOptions, PostmanToAsyncAPIOptions } from './interfaces';
|
|
2
2
|
export declare function convert(input: string, version: AsyncAPIConvertVersion, options?: ConvertOptions): string;
|
|
3
3
|
export declare function convert(input: AsyncAPIDocument, version: AsyncAPIConvertVersion, options?: ConvertOptions): AsyncAPIDocument;
|
|
4
4
|
export declare function convertOpenAPI(input: string, version: OpenAPIConvertVersion, options?: OpenAPIToAsyncAPIOptions): string;
|
|
5
5
|
export declare function convertOpenAPI(input: OpenAPIDocument, version: OpenAPIConvertVersion, options?: OpenAPIToAsyncAPIOptions): AsyncAPIDocument;
|
|
6
|
+
export declare function convertPostman(input: string, version: OpenAPIConvertVersion, options?: PostmanToAsyncAPIOptions): string;
|
|
7
|
+
export declare function convertPostman(input: Record<string, any>, version: OpenAPIConvertVersion, options?: PostmanToAsyncAPIOptions): AsyncAPIDocument;
|
package/lib/convert.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertOpenAPI = exports.convert = void 0;
|
|
3
|
+
exports.convertPostman = exports.convertOpenAPI = exports.convert = void 0;
|
|
4
4
|
const js_yaml_1 = require("js-yaml");
|
|
5
5
|
const first_version_1 = require("./first-version");
|
|
6
6
|
const second_version_1 = require("./second-version");
|
|
7
7
|
const third_version_1 = require("./third-version");
|
|
8
8
|
const openapi_1 = require("./openapi");
|
|
9
|
+
const postman_collection_1 = require("./postman-collection");
|
|
9
10
|
const utils_1 = require("./utils");
|
|
10
11
|
/**
|
|
11
12
|
* Value for key (version) represents the function which converts specification from previous version to the given as key.
|
|
@@ -14,9 +15,6 @@ const asyncAPIconverters = Object.assign(Object.assign(Object.assign({}, first_v
|
|
|
14
15
|
const conversionVersions = Object.keys(asyncAPIconverters);
|
|
15
16
|
function convert(input, version, options = {}) {
|
|
16
17
|
const { format, document } = (0, utils_1.serializeInput)(input);
|
|
17
|
-
if ('openapi' in document) {
|
|
18
|
-
throw new Error('Cannot convert OpenAPI document. Use convertOpenAPI function instead.');
|
|
19
|
-
}
|
|
20
18
|
const asyncapiVersion = document.asyncapi;
|
|
21
19
|
let fromVersion = conversionVersions.indexOf(asyncapiVersion);
|
|
22
20
|
const toVersion = conversionVersions.indexOf(version);
|
|
@@ -57,3 +55,13 @@ function convertOpenAPI(input, version, options = {}) {
|
|
|
57
55
|
return convertedAsyncAPI;
|
|
58
56
|
}
|
|
59
57
|
exports.convertOpenAPI = convertOpenAPI;
|
|
58
|
+
function convertPostman(input, version, options = {}) {
|
|
59
|
+
const { format, document } = (0, utils_1.serializeInput)(input);
|
|
60
|
+
const postmantoAsyncapiConverter = postman_collection_1.converters[version];
|
|
61
|
+
const convertedAsyncAPI = postmantoAsyncapiConverter(document, options);
|
|
62
|
+
if (format === "yaml") {
|
|
63
|
+
return (0, js_yaml_1.dump)(convertedAsyncAPI, { skipInvalid: true });
|
|
64
|
+
}
|
|
65
|
+
return convertedAsyncAPI;
|
|
66
|
+
}
|
|
67
|
+
exports.convertPostman = convertPostman;
|
package/lib/interfaces.d.ts
CHANGED
|
@@ -29,9 +29,14 @@ export declare type OpenAPIToAsyncAPIOptions = {
|
|
|
29
29
|
export declare type ConvertOptions = {
|
|
30
30
|
v2tov3?: ConvertV2ToV3Options;
|
|
31
31
|
openAPIToAsyncAPI?: OpenAPIToAsyncAPIOptions;
|
|
32
|
+
postmanToAsyncAPI?: PostmanToAsyncAPIOptions;
|
|
33
|
+
};
|
|
34
|
+
export declare type PostmanToAsyncAPIOptions = {
|
|
35
|
+
perspective?: 'client' | 'server';
|
|
32
36
|
};
|
|
33
37
|
/**
|
|
34
38
|
* PRIVATE TYPES
|
|
35
39
|
*/
|
|
36
40
|
export declare type ConvertFunction = (asyncapi: AsyncAPIDocument, options: ConvertOptions) => AsyncAPIDocument;
|
|
37
41
|
export declare type ConvertOpenAPIFunction = (openapi: OpenAPIDocument, options: OpenAPIToAsyncAPIOptions) => AsyncAPIDocument;
|
|
42
|
+
export declare type ConvertPostmanFunction = (postman: any, options: PostmanToAsyncAPIOptions) => AsyncAPIDocument;
|
package/lib/openapi.d.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
import { ConvertOpenAPIFunction } from "./interfaces";
|
|
1
|
+
import { AsyncAPIDocument, ConvertOpenAPIFunction, OpenAPIToAsyncAPIOptions, OpenAPIDocument } from "./interfaces";
|
|
2
2
|
export declare const converters: Record<string, ConvertOpenAPIFunction>;
|
|
3
|
+
/**
|
|
4
|
+
* Converts an OpenAPI document to an AsyncAPI document.
|
|
5
|
+
* @param {OpenAPIDocument} openapi - The OpenAPI document to convert.
|
|
6
|
+
* @param {ConvertOptions} options - Conversion options.
|
|
7
|
+
* @returns {AsyncAPIDocument} The converted AsyncAPI document.
|
|
8
|
+
*/
|
|
9
|
+
export declare function from_openapi_to_asyncapi(openapi: OpenAPIDocument, options?: OpenAPIToAsyncAPIOptions): AsyncAPIDocument;
|
package/lib/openapi.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.converters = void 0;
|
|
3
|
+
exports.from_openapi_to_asyncapi = exports.converters = void 0;
|
|
4
4
|
const utils_1 = require("./utils");
|
|
5
5
|
exports.converters = {
|
|
6
6
|
'3.0.0': from_openapi_to_asyncapi,
|
|
@@ -27,6 +27,7 @@ function from_openapi_to_asyncapi(openapi, options = {}) {
|
|
|
27
27
|
(0, utils_1.removeEmptyObjects)(asyncapi);
|
|
28
28
|
return (0, utils_1.sortObjectKeys)(asyncapi, ['asyncapi', 'info', 'defaultContentType', 'servers', 'channels', 'operations', 'components']);
|
|
29
29
|
}
|
|
30
|
+
exports.from_openapi_to_asyncapi = from_openapi_to_asyncapi;
|
|
30
31
|
/**
|
|
31
32
|
* Converts openAPI info objects to asyncAPI info objects.
|
|
32
33
|
* @param info - The openAPI info object to convert.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.converters = void 0;
|
|
4
|
+
const postman2openapi_1 = require("postman2openapi");
|
|
5
|
+
const openapi_1 = require("./openapi");
|
|
6
|
+
exports.converters = {
|
|
7
|
+
'3.0.0': from_postman_to_asyncapi
|
|
8
|
+
};
|
|
9
|
+
function from_postman_to_asyncapi(postman, options = {}) {
|
|
10
|
+
const perspective = options.perspective;
|
|
11
|
+
const openapi = (0, postman2openapi_1.transpile)(postman);
|
|
12
|
+
const asyncapi = (0, openapi_1.from_openapi_to_asyncapi)(openapi, { perspective: perspective });
|
|
13
|
+
return asyncapi;
|
|
14
|
+
}
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AsyncAPIDocument, OpenAPIDocument } from "./interfaces";
|
|
2
|
-
export declare function serializeInput(document: string | AsyncAPIDocument | OpenAPIDocument): {
|
|
2
|
+
export declare function serializeInput(document: string | AsyncAPIDocument | OpenAPIDocument | Record<string, any>): {
|
|
3
3
|
format: 'json' | 'yaml';
|
|
4
4
|
document: AsyncAPIDocument | OpenAPIDocument;
|
|
5
5
|
} | never;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asyncapi/converter",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "Convert AsyncAPI documents from older to newer versions.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -39,7 +39,9 @@
|
|
|
39
39
|
"license": "Apache-2.0",
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@asyncapi/parser": "^3.1.0",
|
|
42
|
-
"js-yaml": "^3.14.1"
|
|
42
|
+
"js-yaml": "^3.14.1",
|
|
43
|
+
"path": "^0.12.7",
|
|
44
|
+
"postman2openapi": "^1.2.1"
|
|
43
45
|
},
|
|
44
46
|
"devDependencies": {
|
|
45
47
|
"@jest/types": "^27.5.1",
|