@backstage/plugin-catalog-backend-module-openapi 0.2.23-next.0 → 0.2.23
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 +19 -0
- package/dist/lib/bundle.cjs.js +13 -26
- package/dist/lib/bundle.cjs.js.map +1 -1
- package/package.json +10 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @backstage/plugin-catalog-backend-module-openapi
|
|
2
2
|
|
|
3
|
+
## 0.2.23
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- cf4b34b: Fixed resolution of relative `$ref` paths in OpenAPI and AsyncAPI specs by using the original reference string and parent document URL from the ref parser, instead of computing paths relative to the process working directory. This fixes a regression where cross-directory refs like `./../../common/specs/common.yaml` and nested refs at depth > 1 would resolve incorrectly.
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @backstage/integration@2.0.3
|
|
10
|
+
- @backstage/backend-plugin-api@1.9.2
|
|
11
|
+
- @backstage/plugin-catalog-node@2.2.2
|
|
12
|
+
|
|
13
|
+
## 0.2.23-next.1
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- cf4b34b: Fixed resolution of relative `$ref` paths in OpenAPI and AsyncAPI specs by using the original reference string and parent document URL from the ref parser, instead of computing paths relative to the process working directory. This fixes a regression where cross-directory refs like `./../../common/specs/common.yaml` and nested refs at depth > 1 would resolve incorrectly.
|
|
18
|
+
- Updated dependencies
|
|
19
|
+
- @backstage/integration@2.0.3-next.1
|
|
20
|
+
- @backstage/backend-plugin-api@1.9.2-next.1
|
|
21
|
+
|
|
3
22
|
## 0.2.23-next.0
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/dist/lib/bundle.cjs.js
CHANGED
|
@@ -1,28 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var jsonSchemaRefParser = require('@apidevtools/json-schema-ref-parser');
|
|
4
3
|
var yaml = require('yaml');
|
|
5
|
-
var path = require('node:path');
|
|
6
|
-
|
|
7
|
-
function _interopNamespaceCompat(e) {
|
|
8
|
-
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
9
|
-
var n = Object.create(null);
|
|
10
|
-
if (e) {
|
|
11
|
-
Object.keys(e).forEach(function (k) {
|
|
12
|
-
if (k !== 'default') {
|
|
13
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: function () { return e[k]; }
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
n.default = e;
|
|
22
|
-
return Object.freeze(n);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
var path__namespace = /*#__PURE__*/_interopNamespaceCompat(path);
|
|
26
4
|
|
|
27
5
|
const protocolPattern = /^(\w{2,}):\/\//i;
|
|
28
6
|
const getProtocol = (refPath) => {
|
|
@@ -45,14 +23,18 @@ const asyncApiV3PreservedPaths = [
|
|
|
45
23
|
/#\/components\/operations\/.*\/reply\/messages/
|
|
46
24
|
];
|
|
47
25
|
async function bundleFileWithRefs(fileWithRefs, baseUrl, read, resolveUrl) {
|
|
26
|
+
const resolvedUrlMap = /* @__PURE__ */ new Map();
|
|
48
27
|
const fileUrlReaderResolver = {
|
|
49
28
|
canRead: (file) => {
|
|
50
29
|
const protocol = getProtocol(file.url);
|
|
51
30
|
return protocol === void 0 || protocol === "file";
|
|
52
31
|
},
|
|
53
32
|
read: async (file) => {
|
|
54
|
-
const
|
|
55
|
-
const
|
|
33
|
+
const ref = file.reference ?? file.url;
|
|
34
|
+
const parentBaseUrl = file.baseUrl?.split("#")[0];
|
|
35
|
+
const parentUrl = parentBaseUrl ? resolvedUrlMap.get(parentBaseUrl) ?? baseUrl : baseUrl;
|
|
36
|
+
const url = resolveUrl(ref, parentUrl);
|
|
37
|
+
resolvedUrlMap.set(file.url, url);
|
|
56
38
|
return await read(url);
|
|
57
39
|
}
|
|
58
40
|
};
|
|
@@ -62,7 +44,11 @@ async function bundleFileWithRefs(fileWithRefs, baseUrl, read, resolveUrl) {
|
|
|
62
44
|
return protocol === "http" || protocol === "https";
|
|
63
45
|
},
|
|
64
46
|
read: async (ref) => {
|
|
65
|
-
const
|
|
47
|
+
const reference = ref.reference ?? ref.url;
|
|
48
|
+
const parentBaseUrl = ref.baseUrl?.split("#")[0];
|
|
49
|
+
const parentUrl = parentBaseUrl ? resolvedUrlMap.get(parentBaseUrl) ?? baseUrl : baseUrl;
|
|
50
|
+
const url = resolveUrl(reference, parentUrl);
|
|
51
|
+
resolvedUrlMap.set(ref.url, url);
|
|
66
52
|
return await read(url);
|
|
67
53
|
}
|
|
68
54
|
};
|
|
@@ -85,7 +71,8 @@ async function bundleFileWithRefs(fileWithRefs, baseUrl, read, resolveUrl) {
|
|
|
85
71
|
};
|
|
86
72
|
}
|
|
87
73
|
}
|
|
88
|
-
const
|
|
74
|
+
const { $RefParser } = await import('@apidevtools/json-schema-ref-parser');
|
|
75
|
+
const bundledObject = await $RefParser.bundle(fileObject, options);
|
|
89
76
|
return yaml.stringify(bundledObject);
|
|
90
77
|
}
|
|
91
78
|
|
|
@@ -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
|
|
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 type {\n ParserOptions,\n ResolverOptions,\n} from '@apidevtools/json-schema-ref-parser';\nimport { parse, stringify } from 'yaml';\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 // file.baseUrl from the parser is a filesystem path, not an SCM URL. For\n // nested refs (depth > 1) we need the parent's SCM URL to resolve against,\n // so we track the translation from each read file's internal URL to the\n // SCM URL we computed for it.\n const resolvedUrlMap = new Map<string, string>();\n\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 ref = file.reference ?? file.url;\n const parentBaseUrl = file.baseUrl?.split('#')[0];\n const parentUrl = parentBaseUrl\n ? resolvedUrlMap.get(parentBaseUrl) ?? baseUrl\n : baseUrl;\n const url = resolveUrl(ref, parentUrl);\n resolvedUrlMap.set(file.url, url);\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 reference = ref.reference ?? ref.url;\n const parentBaseUrl = ref.baseUrl?.split('#')[0];\n const parentUrl = parentBaseUrl\n ? resolvedUrlMap.get(parentBaseUrl) ?? baseUrl\n : baseUrl;\n const url = resolveUrl(reference, parentUrl);\n resolvedUrlMap.set(ref.url, url);\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 const { $RefParser } = await import('@apidevtools/json-schema-ref-parser');\n const bundledObject = await $RefParser.bundle(fileObject, options);\n return stringify(bundledObject);\n}\n"],"names":["parse","stringify"],"mappings":";;;;AAqBA,MAAM,eAAA,GAAkB,iBAAA;AACxB,MAAM,WAAA,GAAc,CAAC,OAAA,KAAoB;AACvC,EAAA,MAAM,KAAA,GAAQ,eAAA,CAAgB,IAAA,CAAK,OAAO,CAAA;AAC1C,EAAA,IAAI,KAAA,EAAO;AACT,IAAA,OAAO,KAAA,CAAM,CAAC,CAAA,CAAE,WAAA,EAAY;AAAA,EAC9B;AACA,EAAA,OAAO,MAAA;AACT,CAAA;AAOA,MAAM,wBAAA,GA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ChC;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-catalog-backend-module-openapi",
|
|
3
|
-
"version": "0.2.23
|
|
3
|
+
"version": "0.2.23",
|
|
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.9.2
|
|
45
|
-
"@backstage/catalog-model": "1.9.0",
|
|
46
|
-
"@backstage/integration": "2.0.3
|
|
47
|
-
"@backstage/plugin-catalog-common": "1.1.10",
|
|
48
|
-
"@backstage/plugin-catalog-node": "2.2.2
|
|
49
|
-
"@backstage/types": "1.2.2",
|
|
43
|
+
"@apidevtools/json-schema-ref-parser": "^15.3.5",
|
|
44
|
+
"@backstage/backend-plugin-api": "^1.9.2",
|
|
45
|
+
"@backstage/catalog-model": "^1.9.0",
|
|
46
|
+
"@backstage/integration": "^2.0.3",
|
|
47
|
+
"@backstage/plugin-catalog-common": "^1.1.10",
|
|
48
|
+
"@backstage/plugin-catalog-node": "^2.2.2",
|
|
49
|
+
"@backstage/types": "^1.2.2",
|
|
50
50
|
"yaml": "^2.1.1"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@backstage/backend-test-utils": "1.11.4
|
|
54
|
-
"@backstage/cli": "0.36.3
|
|
53
|
+
"@backstage/backend-test-utils": "^1.11.4",
|
|
54
|
+
"@backstage/cli": "^0.36.3",
|
|
55
55
|
"openapi-types": "^12.0.0"
|
|
56
56
|
},
|
|
57
57
|
"typesVersions": {
|