@ama-openapi/redocly-plugin 13.5.0-prerelease.20 → 13.5.0-prerelease.21
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 +6 -0
- package/package.json +7 -7
- package/src/plugin.d.mts.map +1 -1
- package/src/plugin.mjs +18 -1
- package/src/plugin.mjs.map +1 -1
- package/src/plugins/decorators/common/replace-refs/replace-refs.decorator.d.mts +46 -0
- package/src/plugins/decorators/common/replace-refs/replace-refs.decorator.d.mts.map +1 -0
- package/src/plugins/decorators/common/replace-refs/replace-refs.decorator.mjs +55 -0
- package/src/plugins/decorators/common/replace-refs/replace-refs.decorator.mjs.map +1 -0
- package/src/plugins/decorators/oas3/remove-unused-components/remove-unused-components.decorator.d.mts +12 -0
- package/src/plugins/decorators/oas3/remove-unused-components/remove-unused-components.decorator.d.mts.map +1 -0
- package/src/plugins/decorators/oas3/remove-unused-components/remove-unused-components.decorator.mjs +103 -0
- package/src/plugins/decorators/oas3/remove-unused-components/remove-unused-components.decorator.mjs.map +1 -0
- package/src/plugins/meta/retrieve-dependency.meta.d.mts.map +1 -1
- package/src/plugins/meta/retrieve-dependency.meta.mjs +4 -3
- package/src/plugins/meta/retrieve-dependency.meta.mjs.map +1 -1
package/README.md
CHANGED
|
@@ -106,6 +106,12 @@ The following environment variables are supported:
|
|
|
106
106
|
| `AMA_OPENAPI_REDOCLY_VERBOSE` | Display debug level logs | `false` |
|
|
107
107
|
| `AMA_OPENAPI_REDOCLY_QUIET` | Suppress all output| `false` |
|
|
108
108
|
|
|
109
|
+
## Additional custom decorators
|
|
110
|
+
|
|
111
|
+
The plugin offer additional [Redocly decorator](https://redocly.com/docs/cli/decorators) which can be selected and configured in [Redocly configuration](https://redocly.com/docs/cli/rules/configure-rules).
|
|
112
|
+
|
|
113
|
+
The full list of available decorators, along with their options, is provided in the [dedicated documentation](https://github.com/AmadeusITGroup/otter/blob/main/docs/redocly/DECORATORS.md).
|
|
114
|
+
|
|
109
115
|
## Integration
|
|
110
116
|
|
|
111
117
|
This Redocly Plugin is designed to work with the following tools:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ama-openapi/redocly-plugin",
|
|
3
|
-
"version": "13.5.0-prerelease.
|
|
3
|
+
"version": "13.5.0-prerelease.21",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -30,13 +30,13 @@
|
|
|
30
30
|
"postbuild": "patch-package-json-main"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@ama-openapi/core": "~13.5.0-prerelease.
|
|
33
|
+
"@ama-openapi/core": "~13.5.0-prerelease.21",
|
|
34
34
|
"dotenv": "~17.2.3",
|
|
35
35
|
"tslib": "^2.6.2",
|
|
36
36
|
"yargs": "~18.0.0"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@o3r/telemetry": "~13.5.0-prerelease.
|
|
39
|
+
"@o3r/telemetry": "~13.5.0-prerelease.21",
|
|
40
40
|
"@redocly/openapi-core": "^2.11.0"
|
|
41
41
|
},
|
|
42
42
|
"peerDependenciesMeta": {
|
|
@@ -54,10 +54,10 @@
|
|
|
54
54
|
"@nx/eslint-plugin": "~21.6.0",
|
|
55
55
|
"@nx/jest": "~21.6.0",
|
|
56
56
|
"@nx/js": "~21.6.0",
|
|
57
|
-
"@o3r/build-helpers": "~13.5.0-prerelease.
|
|
58
|
-
"@o3r/eslint-plugin": "~13.5.0-prerelease.
|
|
59
|
-
"@o3r/telemetry": "~13.5.0-prerelease.
|
|
60
|
-
"@o3r/test-helpers": "~13.5.0-prerelease.
|
|
57
|
+
"@o3r/build-helpers": "~13.5.0-prerelease.21",
|
|
58
|
+
"@o3r/eslint-plugin": "~13.5.0-prerelease.21",
|
|
59
|
+
"@o3r/telemetry": "~13.5.0-prerelease.21",
|
|
60
|
+
"@o3r/test-helpers": "~13.5.0-prerelease.21",
|
|
61
61
|
"@redocly/openapi-core": "~2.11.0",
|
|
62
62
|
"@stylistic/eslint-plugin": "~5.6.0",
|
|
63
63
|
"@types/jest": "~29.5.2",
|
package/src/plugin.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.mts","sourceRoot":"","sources":["../../src/plugin.mts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,MAAM,EACZ,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin.d.mts","sourceRoot":"","sources":["../../src/plugin.mts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,MAAM,EACZ,MAAM,uBAAuB,CAAC;AAe/B,OAAO,EAEL,KAAK,yBAAyB,EAC/B,MAAM,6CAA6C,CAAC;AAIrD,qCAAqC;AACrC,MAAM,WAAW,uBAAwB,SAAQ,OAAO,CAAC,yBAAyB,CAAC;CAClF;AAED;;;GAGG;AACH,eAAO,MAAM,gBAAgB,GAAU,UAAU,uBAAuB,KAAG,OAAO,CAAC,MAAM,CAiCxF,CAAC"}
|
package/src/plugin.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { config, } from 'dotenv';
|
|
2
2
|
import { ENVIRONMENT_VARIABLE_PREFIX, } from './constants.mjs';
|
|
3
|
+
import { DECORATOR_ID_REDIRECT_REF, redirectRefsDecorator, } from './plugins/decorators/common/replace-refs/replace-refs.decorator.mjs';
|
|
4
|
+
import { DECORATOR_ID_REMOVE_UNUSED_COMPONENT, removeUnusedComponentsDecorator, } from './plugins/decorators/oas3/remove-unused-components/remove-unused-components.decorator.mjs';
|
|
3
5
|
import { retrieveDependency, } from './plugins/meta/retrieve-dependency.meta.mjs';
|
|
4
6
|
const DEFAULT_OPTIONS = 'error';
|
|
5
7
|
/**
|
|
@@ -15,7 +17,22 @@ export const amaOpenapiPlugin = async (options) => {
|
|
|
15
17
|
continueOnError: continueOnError ? continueOnError === 'true' : options?.continueOnError ?? false
|
|
16
18
|
});
|
|
17
19
|
return {
|
|
18
|
-
id: 'ama-openapi'
|
|
20
|
+
id: 'ama-openapi',
|
|
21
|
+
decorators: {
|
|
22
|
+
oas2: {
|
|
23
|
+
[DECORATOR_ID_REDIRECT_REF]: redirectRefsDecorator
|
|
24
|
+
},
|
|
25
|
+
oas3: {
|
|
26
|
+
[DECORATOR_ID_REDIRECT_REF]: redirectRefsDecorator,
|
|
27
|
+
[DECORATOR_ID_REMOVE_UNUSED_COMPONENT]: removeUnusedComponentsDecorator
|
|
28
|
+
},
|
|
29
|
+
async2: {
|
|
30
|
+
[DECORATOR_ID_REDIRECT_REF]: redirectRefsDecorator
|
|
31
|
+
},
|
|
32
|
+
async3: {
|
|
33
|
+
[DECORATOR_ID_REDIRECT_REF]: redirectRefsDecorator
|
|
34
|
+
}
|
|
35
|
+
}
|
|
19
36
|
};
|
|
20
37
|
};
|
|
21
38
|
//# sourceMappingURL=plugin.mjs.map
|
package/src/plugin.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.mjs","sourceRoot":"","sources":["../../src/plugin.mts"],"names":[],"mappings":"AAMA,OAAO,EACL,MAAM,GACP,MAAM,QAAQ,CAAC;AAChB,OAAO,EACL,2BAA2B,GAC5B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,kBAAkB,GAEnB,MAAM,6CAA6C,CAAC;AAErD,MAAM,eAAe,GAAa,OAAO,CAAC;AAM1C;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EAAE,OAAiC,EAAmB,EAAE;IAC3F,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAExC,MAAM,EACJ,CAAC,GAAG,2BAA2B,UAAU,CAAC,EAAE,OAAO,EACnD,CAAC,GAAG,2BAA2B,QAAQ,CAAC,EAAE,KAAK,EAC/C,CAAC,GAAG,2BAA2B,oBA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,OAAO,CAAC,GAAG,CAAC;IAEhB,MAAM,kBAAkB,CAAC;QACvB,QAAQ,EAAE,OAAO,KAAK,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,QAAQ,IAAI,eAAe,CAAC;QAC/E,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,KAAK,IAAI,KAAK;QACzD,eAAe,EAAE,eAAe,CAAC,CAAC,CAAC,eAAe,KAAK,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,eAAe,IAAI,KAAK;KAClG,CAAC,CAAC;IAEH,OAAO;QACL,EAAE,EAAE,aAAa;QACjB,UAAU,EAAE;YACV,IAAI,EAAE;gBACJ,CAAC,yBAAyB,CAAC,EAAE,qBAAqB;aACnD;YACD,IAAI,EAAE;gBACJ,CAAC,yBAAyB,CAAC,EAAE,qBAAqB;gBAClD,CAAC,oCAAoC,CAAC,EAAE,+BAA+B;aACxE;YACD,MAAM,EAAE;gBACN,CAAC,yBAAyB,CAAC,EAAE,qBAAqB;aACnD;YACD,MAAM,EAAE;gBACN,CAAC,yBAAyB,CAAC,EAAE,qBAAqB;aACnD;SACF;KACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Async2Preprocessor, Async3Preprocessor, Oas2Preprocessor, Oas3Preprocessor } from '@redocly/openapi-core';
|
|
2
|
+
type Preprocessor = Oas2Preprocessor & Oas3Preprocessor & Async2Preprocessor & Async3Preprocessor;
|
|
3
|
+
interface RedirectCriteria {
|
|
4
|
+
/** Pattern, or one of the listed patterns, the $ref url should match to apply the redirection */
|
|
5
|
+
includeRefPatterns?: string | string[];
|
|
6
|
+
/** Pattern, or one of the listed patterns, the $ref url should not match to apply the redirection */
|
|
7
|
+
excludeRefPatterns?: string | string[];
|
|
8
|
+
/** Detect if a specific `x-vendor` tag is present beside of the reference */
|
|
9
|
+
hasTag?: string;
|
|
10
|
+
}
|
|
11
|
+
/** Rule to redirect the reference matching the criteria in the final specification */
|
|
12
|
+
export interface RedirectRule extends RedirectCriteria {
|
|
13
|
+
/** Redirect the reference to a define URL */
|
|
14
|
+
redirectUrl: string;
|
|
15
|
+
/** Determine the final inner path should be kept */
|
|
16
|
+
keepFinalInnerPath?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/** Options for the RedirectRefs custom decorator */
|
|
19
|
+
export interface RedirectRefDecoratorOptions {
|
|
20
|
+
/** Rules to be apply to the specification references */
|
|
21
|
+
rules?: RedirectRule[];
|
|
22
|
+
}
|
|
23
|
+
/** Name of the redirectRef custom decorator */
|
|
24
|
+
export declare const DECORATOR_ID_REDIRECT_REF = "redirect-ref";
|
|
25
|
+
/**
|
|
26
|
+
* Custom decorator to redirect the references in the final specification
|
|
27
|
+
* @example Redirect specific model to external URL
|
|
28
|
+
* ```yaml
|
|
29
|
+
* plugins:
|
|
30
|
+
* - '@ama-openapi/redocly-plugin'
|
|
31
|
+
*
|
|
32
|
+
* apis:
|
|
33
|
+
* mySpec:
|
|
34
|
+
* root: apis/mySpec.json
|
|
35
|
+
* decorators:
|
|
36
|
+
* ama-openapi/redirect-ref:
|
|
37
|
+
* rules:
|
|
38
|
+
* - redirectUrl: "https://my-spec.website.com/"
|
|
39
|
+
* keepFinalInnerPath: true
|
|
40
|
+
* matchingRefPattern: "my-models/.*"
|
|
41
|
+
* ```
|
|
42
|
+
* @param options
|
|
43
|
+
*/
|
|
44
|
+
export declare const redirectRefsDecorator: Preprocessor;
|
|
45
|
+
export {};
|
|
46
|
+
//# sourceMappingURL=replace-refs.decorator.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replace-refs.decorator.d.mts","sourceRoot":"","sources":["../../../../../../src/plugins/decorators/common/replace-refs/replace-refs.decorator.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAE/B,KAAK,YAAY,GAAG,gBAAgB,GAAG,gBAAgB,GAAG,kBAAkB,GAAG,kBAAkB,CAAC;AAElG,UAAU,gBAAgB;IACxB,iGAAiG;IACjG,kBAAkB,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACvC,qGAAqG;IACrG,kBAAkB,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACvC,6EAA6E;IAC7E,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,sFAAsF;AACtF,MAAM,WAAW,YAAa,SAAQ,gBAAgB;IACpD,6CAA6C;IAC7C,WAAW,EAAE,MAAM,CAAC;IACpB,oDAAoD;IACpD,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,oDAAoD;AACpD,MAAM,WAAW,2BAA2B;IAC1C,wDAAwD;IACxD,KAAK,CAAC,EAAE,YAAY,EAAE,CAAC;CACxB;AAED,+CAA+C;AAC/C,eAAO,MAAM,yBAAyB,iBAAiB,CAAC;AAQxD;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,qBAAqB,EAAE,YA+BnC,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** Name of the redirectRef custom decorator */
|
|
2
|
+
export const DECORATOR_ID_REDIRECT_REF = 'redirect-ref';
|
|
3
|
+
const regExpify = (patterns) => patterns
|
|
4
|
+
? (Array.isArray(patterns) ? patterns : [patterns])
|
|
5
|
+
.map((pattern) => new RegExp(pattern))
|
|
6
|
+
: undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Custom decorator to redirect the references in the final specification
|
|
9
|
+
* @example Redirect specific model to external URL
|
|
10
|
+
* ```yaml
|
|
11
|
+
* plugins:
|
|
12
|
+
* - '@ama-openapi/redocly-plugin'
|
|
13
|
+
*
|
|
14
|
+
* apis:
|
|
15
|
+
* mySpec:
|
|
16
|
+
* root: apis/mySpec.json
|
|
17
|
+
* decorators:
|
|
18
|
+
* ama-openapi/redirect-ref:
|
|
19
|
+
* rules:
|
|
20
|
+
* - redirectUrl: "https://my-spec.website.com/"
|
|
21
|
+
* keepFinalInnerPath: true
|
|
22
|
+
* matchingRefPattern: "my-models/.*"
|
|
23
|
+
* ```
|
|
24
|
+
* @param options
|
|
25
|
+
*/
|
|
26
|
+
export const redirectRefsDecorator = (options) => {
|
|
27
|
+
const rules = options.rules?.map((rule) => {
|
|
28
|
+
return {
|
|
29
|
+
...rule,
|
|
30
|
+
include: regExpify(rule.includeRefPatterns),
|
|
31
|
+
exclude: regExpify(rule.excludeRefPatterns)
|
|
32
|
+
};
|
|
33
|
+
}) ?? [];
|
|
34
|
+
const toRedirectMap = new Map();
|
|
35
|
+
return {
|
|
36
|
+
ref: {
|
|
37
|
+
enter: (node, { parent, location }) => {
|
|
38
|
+
const matchingRule = rules.find(({ include, exclude, hasTag }) => ([include, exclude, hasTag].some((item) => !!item))
|
|
39
|
+
&& (!include || include.some((regExp) => node.$ref.match(regExp)))
|
|
40
|
+
&& (!exclude || !exclude.some((regExp) => node.$ref.match(regExp)))
|
|
41
|
+
&& (!hasTag || Object.values(parent).some((obj) => obj && typeof obj === 'object' && typeof obj[hasTag] !== 'undefined' && !!obj[hasTag])));
|
|
42
|
+
if (matchingRule) {
|
|
43
|
+
toRedirectMap.set(location.absolutePointer, matchingRule);
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
leave: (node, { location }) => {
|
|
47
|
+
const toRedirect = toRedirectMap.get(location.absolutePointer);
|
|
48
|
+
if (toRedirect) {
|
|
49
|
+
node.$ref = toRedirect.redirectUrl + (toRedirect.keepFinalInnerPath ? node.$ref : '');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=replace-refs.decorator.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replace-refs.decorator.mjs","s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ED_COMPONENT = "remove-unused-component";
|
|
4
|
+
/**
|
|
5
|
+
* This decorator remove the components not referred in the bundled specification
|
|
6
|
+
*
|
|
7
|
+
* Note:
|
|
8
|
+
* The purpose of this plugin is to support inter dependencies not supported currently by the Redocly built-in `remove-unused-components`.
|
|
9
|
+
* This plugin will be deprecated in favor to the built-in plugin when issue https://github.com/Redocly/redocly-cli/issues/1783 is fixed
|
|
10
|
+
*/
|
|
11
|
+
export declare const removeUnusedComponentsDecorator: Oas3Preprocessor;
|
|
12
|
+
//# sourceMappingURL=remove-unused-components.decorator.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove-unused-components.decorator.d.mts","sourceRoot":"","sources":["../../../../../../src/plugins/decorators/oas3/remove-unused-components/remove-unused-components.decorator.mts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,gBAAgB,EAEtB,MAAM,uBAAuB,CAAC;AAE/B,0DAA0D;AAC1D,eAAO,MAAM,oCAAoC,4BAA4B,CAAC;AAE9E;;;;;;GAMG;AACH,eAAO,MAAM,+BAA+B,EAAE,gBA+F7C,CAAC"}
|
package/src/plugins/decorators/oas3/remove-unused-components/remove-unused-components.decorator.mjs
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { logger, } from '@redocly/openapi-core';
|
|
2
|
+
/** Name of the removeUnusedComponents custom decorator */
|
|
3
|
+
export const DECORATOR_ID_REMOVE_UNUSED_COMPONENT = 'remove-unused-component';
|
|
4
|
+
/**
|
|
5
|
+
* This decorator remove the components not referred in the bundled specification
|
|
6
|
+
*
|
|
7
|
+
* Note:
|
|
8
|
+
* The purpose of this plugin is to support inter dependencies not supported currently by the Redocly built-in `remove-unused-components`.
|
|
9
|
+
* This plugin will be deprecated in favor to the built-in plugin when issue https://github.com/Redocly/redocly-cli/issues/1783 is fixed
|
|
10
|
+
*/
|
|
11
|
+
export const removeUnusedComponentsDecorator = () => {
|
|
12
|
+
const refMaps = new Map();
|
|
13
|
+
const registerComponent = (node, ctx) => {
|
|
14
|
+
const rec = (obj) => {
|
|
15
|
+
if (obj && typeof obj === 'object' && obj.$ref && !ctx.location.absolutePointer.endsWith(obj.$ref)) {
|
|
16
|
+
if (refMaps.has(obj.$ref)) {
|
|
17
|
+
const refs = refMaps.get(obj.$ref);
|
|
18
|
+
if (!refs.includes(ctx.location.absolutePointer)) {
|
|
19
|
+
return refMaps.set(obj.$ref, [...refs, ctx.location.absolutePointer]);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
return refMaps.set(obj.$ref, [ctx.location.absolutePointer]);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (typeof obj === 'object') {
|
|
27
|
+
if (Array.isArray(obj)) {
|
|
28
|
+
obj.forEach((item) => rec(item));
|
|
29
|
+
}
|
|
30
|
+
else if (obj) {
|
|
31
|
+
Object.values(obj).forEach((value) => rec(value));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
rec(node);
|
|
36
|
+
};
|
|
37
|
+
return {
|
|
38
|
+
Paths: {
|
|
39
|
+
leave: registerComponent
|
|
40
|
+
},
|
|
41
|
+
NamedSchemas: {
|
|
42
|
+
Schema: registerComponent
|
|
43
|
+
},
|
|
44
|
+
NamedParameters: {
|
|
45
|
+
Parameter: registerComponent
|
|
46
|
+
},
|
|
47
|
+
NamedResponses: {
|
|
48
|
+
Response: registerComponent
|
|
49
|
+
},
|
|
50
|
+
NamedExamples: {
|
|
51
|
+
Example: registerComponent
|
|
52
|
+
},
|
|
53
|
+
NamedRequestBodies: {
|
|
54
|
+
RequestBody: registerComponent
|
|
55
|
+
},
|
|
56
|
+
NamedHeaders: {
|
|
57
|
+
Header: registerComponent
|
|
58
|
+
},
|
|
59
|
+
Components: {
|
|
60
|
+
leave: (node, ctx) => {
|
|
61
|
+
const removeUnusedSchemas = () => {
|
|
62
|
+
if (!node.schemas) {
|
|
63
|
+
return 0;
|
|
64
|
+
}
|
|
65
|
+
const toRemoveSchemaNames = Object.keys(node.schemas)
|
|
66
|
+
.filter((name) => !refMaps.has(`#/components/schemas/${name}`));
|
|
67
|
+
toRemoveSchemaNames
|
|
68
|
+
.forEach((name) => {
|
|
69
|
+
delete node.schemas[name];
|
|
70
|
+
const elementRef = `${ctx.location.absolutePointer}/schemas/${name}`;
|
|
71
|
+
refMaps.forEach((locations, ref) => {
|
|
72
|
+
if (locations.includes(elementRef)) {
|
|
73
|
+
locations = locations.filter((location) => location !== elementRef);
|
|
74
|
+
if (locations.length === 0) {
|
|
75
|
+
refMaps.delete(ref);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
refMaps.set(ref, locations);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
return toRemoveSchemaNames.length > 0 ? toRemoveSchemaNames.length + removeUnusedSchemas() : 0;
|
|
84
|
+
};
|
|
85
|
+
const removedCount = removeUnusedSchemas();
|
|
86
|
+
if (node.schemas && Object.keys(node.schemas).length === 0) {
|
|
87
|
+
delete node.schemas;
|
|
88
|
+
}
|
|
89
|
+
if (removedCount > 0) {
|
|
90
|
+
logger.info(`Removed ${removedCount} unused components`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
Root: {
|
|
95
|
+
leave: (root) => {
|
|
96
|
+
if (root.components && Object.keys(root.components).length === 0) {
|
|
97
|
+
delete root.components;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
//# sourceMappingURL=remove-unused-components.decorator.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove-unused-components.decorator.mjs","sourceRoot":"","sources":["../../../../../../src/plugins/decorators/oas3/remove-unused-components/remove-unused-components.decorator.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,GAGP,MAAM,uBAAuB,CAAC;AAE/B,0DAA0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H,CAAC;SACF;KACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retrieve-dependency.meta.d.mts","sourceRoot":"","sources":["../../../../src/plugins/meta/retrieve-dependency.meta.mts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,0BAA0B,EAC/B,KAAK,QAAQ,EAEd,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"retrieve-dependency.meta.d.mts","sourceRoot":"","sources":["../../../../src/plugins/meta/retrieve-dependency.meta.mts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,0BAA0B,EAC/B,KAAK,QAAQ,EAEd,MAAM,mBAAmB,CAAC;AAK3B;;GAEG;AACH,MAAM,WAAW,yBAA0B,SAAQ,0BAA0B;IAC3E;;;OAGG;IACH,QAAQ,EAAE,QAAQ,CAAC;IAEnB,0BAA0B;IAC1B,KAAK,EAAE,OAAO,CAAC;IAEf,8CAA8C;IAC9C,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAAU,SAAS,yBAAyB,kBAY1E,CAAC"}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { getLogger, installDependencies,
|
|
2
2
|
// eslint-disable-next-line import/no-unresolved -- Cannot resolve mjs file in current setup (see #3738)
|
|
3
3
|
} from '@ama-openapi/core';
|
|
4
|
+
import { logger, } from '@redocly/openapi-core';
|
|
4
5
|
/**
|
|
5
6
|
* Retrieve dependencies according to manifest files.
|
|
6
7
|
* Refer to {@link InstallDependencies} for more information
|
|
7
8
|
* @param options
|
|
8
9
|
*/
|
|
9
10
|
export const retrieveDependency = async (options) => {
|
|
10
|
-
const
|
|
11
|
+
const amaLogger = options.quiet ? undefined : getLogger(options.logLevel, logger);
|
|
11
12
|
try {
|
|
12
|
-
await installDependencies(process.cwd(), { ...options, logger });
|
|
13
|
+
await installDependencies(process.cwd(), { ...options, logger: amaLogger });
|
|
13
14
|
}
|
|
14
15
|
catch (e) {
|
|
15
16
|
if (options?.continueOnError) {
|
|
16
|
-
|
|
17
|
+
amaLogger?.error(e);
|
|
17
18
|
}
|
|
18
19
|
else {
|
|
19
20
|
throw e;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retrieve-dependency.meta.mjs","sourceRoot":"","sources":["../../../../src/plugins/meta/retrieve-dependency.meta.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,mBAAmB;AAGnB,wGAAwG;EACzG,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"retrieve-dependency.meta.mjs","sourceRoot":"","sources":["../../../../src/plugins/meta/retrieve-dependency.meta.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,mBAAmB;AAGnB,wGAAwG;EACzG,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,MAAM,GACP,MAAM,uBAAuB,CAAC;AAmB/B;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EAAE,OAAkC,EAAE,EAAE;IAC7E,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAElF,IAAI,CAAC;QACH,MAAM,mBAAmB,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;IAC9E,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,IAAI,OAAO,EAAE,eAAe,EAAE,CAAC;YAC7B,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;QACtB,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC;AACH,CAAC,CAAC"}
|