@backstage/plugin-catalog-backend-module-openapi 0.2.16-next.0 → 0.2.16-next.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/CHANGELOG.md +9 -0
- package/dist/lib/bundle.cjs.js +25 -1
- package/dist/lib/bundle.cjs.js.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @backstage/plugin-catalog-backend-module-openapi
|
|
2
2
|
|
|
3
|
+
## 0.2.16-next.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a5bcb2a: fix wrong dereferencing for AsyncApi 3 documents
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @backstage/plugin-catalog-node@1.20.0-next.1
|
|
10
|
+
- @backstage/backend-plugin-api@1.5.0-next.1
|
|
11
|
+
|
|
3
12
|
## 0.2.16-next.0
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/dist/lib/bundle.cjs.js
CHANGED
|
@@ -32,6 +32,18 @@ const getProtocol = (refPath) => {
|
|
|
32
32
|
}
|
|
33
33
|
return void 0;
|
|
34
34
|
};
|
|
35
|
+
const asyncApiV3PreservedPaths = [
|
|
36
|
+
/#\/channels\/.*\/servers/,
|
|
37
|
+
/#\/operations\/.*\/channel/,
|
|
38
|
+
/#\/operations\/.*\/messages/,
|
|
39
|
+
/#\/operations\/.*\/reply\/channel/,
|
|
40
|
+
/#\/operations\/.*\/reply\/messages/,
|
|
41
|
+
/#\/components\/channels\/.*\/servers/,
|
|
42
|
+
/#\/components\/operations\/.*\/channel/,
|
|
43
|
+
/#\/components\/operations\/.*\/messages/,
|
|
44
|
+
/#\/components\/operations\/.*\/reply\/channel/,
|
|
45
|
+
/#\/components\/operations\/.*\/reply\/messages/
|
|
46
|
+
];
|
|
35
47
|
async function bundleFileWithRefs(fileWithRefs, baseUrl, read, resolveUrl) {
|
|
36
48
|
const fileUrlReaderResolver = {
|
|
37
49
|
canRead: (file) => {
|
|
@@ -39,7 +51,7 @@ async function bundleFileWithRefs(fileWithRefs, baseUrl, read, resolveUrl) {
|
|
|
39
51
|
return protocol === void 0 || protocol === "file";
|
|
40
52
|
},
|
|
41
53
|
read: async (file) => {
|
|
42
|
-
const relativePath = path__namespace.relative(".", file.url);
|
|
54
|
+
const relativePath = path__namespace.relative(".", file.url).replace(/\\/g, "/");
|
|
43
55
|
const url = resolveUrl(relativePath, baseUrl);
|
|
44
56
|
return await read(url);
|
|
45
57
|
}
|
|
@@ -61,6 +73,18 @@ async function bundleFileWithRefs(fileWithRefs, baseUrl, read, resolveUrl) {
|
|
|
61
73
|
}
|
|
62
74
|
};
|
|
63
75
|
const fileObject = yaml.parse(fileWithRefs);
|
|
76
|
+
if (fileObject.asyncapi) {
|
|
77
|
+
const version = parseInt(fileObject.asyncapi, 10);
|
|
78
|
+
if (version === 3) {
|
|
79
|
+
options.bundle = {
|
|
80
|
+
excludedPathMatcher: (refPath) => {
|
|
81
|
+
return asyncApiV3PreservedPaths.some(
|
|
82
|
+
(pattern) => pattern.test(refPath)
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
64
88
|
const bundledObject = await jsonSchemaRefParser.$RefParser.bundle(fileObject, options);
|
|
65
89
|
return yaml.stringify(bundledObject);
|
|
66
90
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundle.cjs.js","sources":["../../src/lib/bundle.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n $RefParser,\n ParserOptions,\n ResolverOptions,\n} from '@apidevtools/json-schema-ref-parser';\nimport { parse, stringify } from 'yaml';\nimport * as path from 'path';\n\nconst protocolPattern = /^(\\w{2,}):\\/\\//i;\nconst getProtocol = (refPath: string) => {\n const match = protocolPattern.exec(refPath);\n if (match) {\n return match[1].toLowerCase();\n }\n return undefined;\n};\n\nexport type BundlerRead = (url: string) => Promise<Buffer>;\n\nexport type BundlerResolveUrl = (url: string, base: string) => string;\n\nexport async function bundleFileWithRefs(\n fileWithRefs: string,\n baseUrl: string,\n read: BundlerRead,\n resolveUrl: BundlerResolveUrl,\n): Promise<string> {\n const fileUrlReaderResolver: ResolverOptions = {\n canRead: file => {\n const protocol = getProtocol(file.url);\n return protocol === undefined || protocol === 'file';\n },\n read: async file => {\n const relativePath = path.relative('.', file.url);\n const url = resolveUrl(relativePath, baseUrl);\n return await read(url);\n },\n };\n const httpUrlReaderResolver: ResolverOptions = {\n canRead: ref => {\n const protocol = getProtocol(ref.url);\n return protocol === 'http' || protocol === 'https';\n },\n read: async ref => {\n const url = resolveUrl(ref.url, baseUrl);\n return await read(url);\n },\n };\n
|
|
1
|
+
{"version":3,"file":"bundle.cjs.js","sources":["../../src/lib/bundle.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n $RefParser,\n ParserOptions,\n ResolverOptions,\n} from '@apidevtools/json-schema-ref-parser';\nimport { parse, stringify } from 'yaml';\nimport * as path from 'path';\n\nconst protocolPattern = /^(\\w{2,}):\\/\\//i;\nconst getProtocol = (refPath: string) => {\n const match = protocolPattern.exec(refPath);\n if (match) {\n return match[1].toLowerCase();\n }\n return undefined;\n};\n\nexport type BundlerRead = (url: string) => Promise<Buffer>;\n\nexport type BundlerResolveUrl = (url: string, base: string) => string;\n\n// Preserved references paths for AsyncAPI v3 documents\nconst asyncApiV3PreservedPaths = [\n /#\\/channels\\/.*\\/servers/,\n /#\\/operations\\/.*\\/channel/,\n /#\\/operations\\/.*\\/messages/,\n /#\\/operations\\/.*\\/reply\\/channel/,\n /#\\/operations\\/.*\\/reply\\/messages/,\n /#\\/components\\/channels\\/.*\\/servers/,\n /#\\/components\\/operations\\/.*\\/channel/,\n /#\\/components\\/operations\\/.*\\/messages/,\n /#\\/components\\/operations\\/.*\\/reply\\/channel/,\n /#\\/components\\/operations\\/.*\\/reply\\/messages/,\n];\n\nexport async function bundleFileWithRefs(\n fileWithRefs: string,\n baseUrl: string,\n read: BundlerRead,\n resolveUrl: BundlerResolveUrl,\n): Promise<string> {\n const fileUrlReaderResolver: ResolverOptions = {\n canRead: file => {\n const protocol = getProtocol(file.url);\n return protocol === undefined || protocol === 'file';\n },\n read: async file => {\n const relativePath = path.relative('.', file.url).replace(/\\\\/g, '/');\n const url = resolveUrl(relativePath, baseUrl);\n return await read(url);\n },\n };\n const httpUrlReaderResolver: ResolverOptions = {\n canRead: ref => {\n const protocol = getProtocol(ref.url);\n return protocol === 'http' || protocol === 'https';\n },\n read: async ref => {\n const url = resolveUrl(ref.url, baseUrl);\n return await read(url);\n },\n };\n const options: ParserOptions = {\n resolve: {\n file: fileUrlReaderResolver,\n http: httpUrlReaderResolver,\n },\n };\n\n const fileObject = parse(fileWithRefs);\n\n if (fileObject.asyncapi) {\n const version = parseInt(fileObject.asyncapi, 10);\n\n if (version === 3) {\n options.bundle = {\n excludedPathMatcher: (refPath: string): any => {\n return asyncApiV3PreservedPaths.some(pattern =>\n pattern.test(refPath),\n );\n },\n };\n }\n }\n\n const bundledObject = await $RefParser.bundle(file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;AACd,MAAA,MAAM,QAAA,GAAW,WAAA,CAAY,GAAA,CAAI,GAAG,CAAA;AACpC,MAAA,OAAO,QAAA,KAAa,UAAU,QAAA,KAAa,OAAA;AAAA,IAC7C,CAAA;AAAA,IACA,IAAA,EAAM,OAAM,GAAA,KAAO;AACjB,MAAA,MAAM,GAAA,GAAM,UAAA,CAAW,GAAA,CAAI,GAAA,EAAK,OAAO,CAAA;AACvC,MAAA,OAAO,MAAM,KAAK,GAAG,CAAA;AAAA,IACvB;AAAA,GACF;AACA,EAAA,MAAM,OAAA,GAAyB;AAAA,IAC7B,OAAA,EAAS;AAAA,MACP,IAAA,EAAM,qBAAA;AAAA,MACN,IAAA,EAAM;AAAA;AACR,GACF;AAEA,EAAA,MAAM,UAAA,GAAaC,WAAM,YAAY,CAAA;AAErC,EAAA,IAAI,WAAW,QAAA,EAAU;AACvB,IAAA,MAAM,OAAA,GAAU,QAAA,CAAS,UAAA,CAAW,QAAA,EAAU,EAAE,CAAA;AAEhD,IAAA,IAAI,YAAY,CAAA,EAAG;AACjB,MAAA,OAAA,CAAQ,MAAA,GAAS;AAAA,QACf,mBAAA,EAAqB,CAAC,OAAA,KAAyB;AAC7C,UAAA,OAAO,wBAAA,CAAyB,IAAA;AAAA,YAAK,CAAA,OAAA,KACnC,OAAA,CAAQ,IAAA,CAAK,OAAO;AAAA,WACtB;AAAA,QACF;AAAA,OACF;AAAA,IACF;AAAA,EACF;AAEA,EAAA,MAAM,aAAA,GAAgB,MAAMC,8BAAA,CAAW,MAAA,CAAO,YAAY,OAAO,CAAA;AACjE,EAAA,OAAOC,eAAU,aAAa,CAAA;AAChC;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-catalog-backend-module-openapi",
|
|
3
|
-
"version": "0.2.16-next.
|
|
3
|
+
"version": "0.2.16-next.1",
|
|
4
4
|
"description": "A Backstage catalog backend module that helps with OpenAPI specifications",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "backend-plugin-module",
|
|
@@ -40,18 +40,18 @@
|
|
|
40
40
|
"test": "backstage-cli package test"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@apidevtools/json-schema-ref-parser": "^
|
|
44
|
-
"@backstage/backend-plugin-api": "1.
|
|
43
|
+
"@apidevtools/json-schema-ref-parser": "^14.2.1",
|
|
44
|
+
"@backstage/backend-plugin-api": "1.5.0-next.1",
|
|
45
45
|
"@backstage/catalog-model": "1.7.6-next.0",
|
|
46
46
|
"@backstage/integration": "1.18.2-next.0",
|
|
47
47
|
"@backstage/plugin-catalog-common": "1.1.7-next.0",
|
|
48
|
-
"@backstage/plugin-catalog-node": "1.
|
|
48
|
+
"@backstage/plugin-catalog-node": "1.20.0-next.1",
|
|
49
49
|
"@backstage/types": "1.2.2",
|
|
50
50
|
"yaml": "^2.1.1"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@backstage/backend-test-utils": "1.10.0-next.
|
|
54
|
-
"@backstage/cli": "0.34.5-next.
|
|
53
|
+
"@backstage/backend-test-utils": "1.10.0-next.1",
|
|
54
|
+
"@backstage/cli": "0.34.5-next.1",
|
|
55
55
|
"openapi-types": "^12.0.0"
|
|
56
56
|
},
|
|
57
57
|
"typesVersions": {
|