@asyncapi/converter 1.7.0 → 2.0.0
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 +0 -44
- package/lib/convert.d.ts +1 -3
- package/lib/convert.js +1 -12
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -2
- package/lib/interfaces.d.ts +0 -5
- package/package.json +2 -3
- package/lib/postman-collection.d.ts +0 -2
- package/lib/postman-collection.js +0 -14
package/README.md
CHANGED
|
@@ -19,8 +19,6 @@ Convert [AsyncAPI](https://asyncapi.com) documents older to newer versions and y
|
|
|
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)
|
|
24
22
|
- [Development](#development)
|
|
25
23
|
- [Contribution](#contribution)
|
|
26
24
|
- [Contributors ✨](#contributors-%E2%9C%A8)
|
|
@@ -241,48 +239,6 @@ The perspective option can be set to either 'server' (default) or 'client'.
|
|
|
241
239
|
|
|
242
240
|
- 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.
|
|
243
241
|
|
|
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
|
-
|
|
286
242
|
## Development
|
|
287
243
|
|
|
288
244
|
1. Setup project by installing dependencies `npm install`
|
package/lib/convert.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import type { AsyncAPIDocument, AsyncAPIConvertVersion, OpenAPIConvertVersion, ConvertOptions, OpenAPIDocument, OpenAPIToAsyncAPIOptions
|
|
1
|
+
import type { AsyncAPIDocument, AsyncAPIConvertVersion, OpenAPIConvertVersion, ConvertOptions, OpenAPIDocument, OpenAPIToAsyncAPIOptions } 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,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
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");
|
|
10
9
|
const utils_1 = require("./utils");
|
|
11
10
|
/**
|
|
12
11
|
* Value for key (version) represents the function which converts specification from previous version to the given as key.
|
|
@@ -55,13 +54,3 @@ function convertOpenAPI(input, version, options = {}) {
|
|
|
55
54
|
return convertedAsyncAPI;
|
|
56
55
|
}
|
|
57
56
|
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/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { convert, convertOpenAPI
|
|
1
|
+
export { convert, convertOpenAPI } from './convert';
|
|
2
2
|
export type { AsyncAPIDocument, AsyncAPIConvertVersion, OpenAPIConvertVersion, ConvertOptions } from './interfaces';
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.convertOpenAPI = exports.convert = void 0;
|
|
4
4
|
var convert_1 = require("./convert");
|
|
5
5
|
Object.defineProperty(exports, "convert", { enumerable: true, get: function () { return convert_1.convert; } });
|
|
6
6
|
Object.defineProperty(exports, "convertOpenAPI", { enumerable: true, get: function () { return convert_1.convertOpenAPI; } });
|
|
7
|
-
Object.defineProperty(exports, "convertPostman", { enumerable: true, get: function () { return convert_1.convertPostman; } });
|
package/lib/interfaces.d.ts
CHANGED
|
@@ -29,14 +29,9 @@ 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';
|
|
36
32
|
};
|
|
37
33
|
/**
|
|
38
34
|
* PRIVATE TYPES
|
|
39
35
|
*/
|
|
40
36
|
export declare type ConvertFunction = (asyncapi: AsyncAPIDocument, options: ConvertOptions) => AsyncAPIDocument;
|
|
41
37
|
export declare type ConvertOpenAPIFunction = (openapi: OpenAPIDocument, options: OpenAPIToAsyncAPIOptions) => AsyncAPIDocument;
|
|
42
|
-
export declare type ConvertPostmanFunction = (postman: any, options: PostmanToAsyncAPIOptions) => AsyncAPIDocument;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asyncapi/converter",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Convert AsyncAPI documents from older to newer versions.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -40,8 +40,7 @@
|
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@asyncapi/parser": "^3.1.0",
|
|
42
42
|
"js-yaml": "^3.14.1",
|
|
43
|
-
"path": "^0.12.7"
|
|
44
|
-
"postman2openapi": "^1.2.1"
|
|
43
|
+
"path": "^0.12.7"
|
|
45
44
|
},
|
|
46
45
|
"devDependencies": {
|
|
47
46
|
"@jest/types": "^27.5.1",
|
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
}
|