@ama-openapi/redocly-plugin 14.3.0-rc.5 → 14.4.0-prerelease.3
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/package.json +7 -7
- package/src/plugin.d.mts.map +1 -1
- package/src/plugin.mjs +5 -0
- package/src/plugin.mjs.map +1 -1
- package/src/plugins/decorators/common/enforce-discriminator-mandatory/enforce-discriminator-mandatory.decorator.d.mts +31 -0
- package/src/plugins/decorators/common/enforce-discriminator-mandatory/enforce-discriminator-mandatory.decorator.d.mts.map +1 -0
- package/src/plugins/decorators/common/enforce-discriminator-mandatory/enforce-discriminator-mandatory.decorator.mjs +52 -0
- package/src/plugins/decorators/common/enforce-discriminator-mandatory/enforce-discriminator-mandatory.decorator.mjs.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ama-openapi/redocly-plugin",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.4.0-prerelease.3",
|
|
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": "~14.
|
|
33
|
+
"@ama-openapi/core": "~14.4.0-prerelease.3",
|
|
34
34
|
"dotenv": "~17.3.0",
|
|
35
35
|
"tslib": "^2.6.2",
|
|
36
36
|
"yargs": "~18.0.0"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@o3r/telemetry": "~14.
|
|
39
|
+
"@o3r/telemetry": "~14.4.0-prerelease.3",
|
|
40
40
|
"@redocly/openapi-core": "^2.11.0"
|
|
41
41
|
},
|
|
42
42
|
"peerDependenciesMeta": {
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
"@nx/eslint-plugin": "~22.7.0",
|
|
53
53
|
"@nx/js": "~22.7.0",
|
|
54
54
|
"@nx/vitest": "~22.7.0",
|
|
55
|
-
"@o3r/build-helpers": "~14.
|
|
56
|
-
"@o3r/eslint-plugin": "~14.
|
|
57
|
-
"@o3r/telemetry": "~14.
|
|
58
|
-
"@o3r/test-helpers": "~14.
|
|
55
|
+
"@o3r/build-helpers": "~14.4.0-prerelease.3",
|
|
56
|
+
"@o3r/eslint-plugin": "~14.4.0-prerelease.3",
|
|
57
|
+
"@o3r/telemetry": "~14.4.0-prerelease.3",
|
|
58
|
+
"@o3r/test-helpers": "~14.4.0-prerelease.3",
|
|
59
59
|
"@redocly/openapi-core": "~2.25.0",
|
|
60
60
|
"@stylistic/eslint-plugin": "~5.10.0",
|
|
61
61
|
"@types/minimist": "^1.2.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;AAmB/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,CAqCxF,CAAC"}
|
package/src/plugin.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { config, } from 'dotenv';
|
|
2
2
|
import { ENVIRONMENT_VARIABLE_PREFIX, } from './constants.mjs';
|
|
3
|
+
import { DECORATOR_ID_ENFORCE_DISCRIMINATOR_MANDATORY, enforceDiscriminatorMandatoryDecorator, } from './plugins/decorators/common/enforce-discriminator-mandatory/enforce-discriminator-mandatory.decorator.mjs';
|
|
3
4
|
import { DECORATOR_ID_REDIRECT_REF, redirectRefsDecorator, } from './plugins/decorators/common/replace-refs/replace-refs.decorator.mjs';
|
|
4
5
|
import { DECORATOR_ID_REMOVE_UNUSED_COMPONENTS, removeUnusedComponentsDecorator, } from './plugins/decorators/oas3/remove-unused-components/remove-unused-components.decorator.mjs';
|
|
5
6
|
import { retrieveDependency, } from './plugins/meta/retrieve-dependency.meta.mjs';
|
|
@@ -20,16 +21,20 @@ export const amaOpenapiPlugin = async (options) => {
|
|
|
20
21
|
id: 'ama-openapi',
|
|
21
22
|
decorators: {
|
|
22
23
|
oas2: {
|
|
24
|
+
[DECORATOR_ID_ENFORCE_DISCRIMINATOR_MANDATORY]: enforceDiscriminatorMandatoryDecorator,
|
|
23
25
|
[DECORATOR_ID_REDIRECT_REF]: redirectRefsDecorator
|
|
24
26
|
},
|
|
25
27
|
oas3: {
|
|
28
|
+
[DECORATOR_ID_ENFORCE_DISCRIMINATOR_MANDATORY]: enforceDiscriminatorMandatoryDecorator,
|
|
26
29
|
[DECORATOR_ID_REDIRECT_REF]: redirectRefsDecorator,
|
|
27
30
|
[DECORATOR_ID_REMOVE_UNUSED_COMPONENTS]: removeUnusedComponentsDecorator
|
|
28
31
|
},
|
|
29
32
|
async2: {
|
|
33
|
+
[DECORATOR_ID_ENFORCE_DISCRIMINATOR_MANDATORY]: enforceDiscriminatorMandatoryDecorator,
|
|
30
34
|
[DECORATOR_ID_REDIRECT_REF]: redirectRefsDecorator
|
|
31
35
|
},
|
|
32
36
|
async3: {
|
|
37
|
+
[DECORATOR_ID_ENFORCE_DISCRIMINATOR_MANDATORY]: enforceDiscriminatorMandatoryDecorator,
|
|
33
38
|
[DECORATOR_ID_REDIRECT_REF]: redirectRefsDecorator
|
|
34
39
|
}
|
|
35
40
|
}
|
package/src/plugin.mjs.map
CHANGED
|
@@ -1 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AAM,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,4CAA4C,CAAC,EAAE,sCAAsC;gBACtF,CAAC,yBAAyB,CAAC,EAAE,qBAAqB;aACnD;YACD,IAAI,EAAE;gBACJ,CAAC,4CAA4C,CAAC,EAAE,sCAAsC;gBACtF,CAAC,yBAAyB,CAAC,EAAE,qBAAqB;gBAClD,CAAC,qCAAqC,CAAC,EAAE,+BAA+B;aACzE;YACD,MAAM,EAAE;gBACN,CAAC,4CAA4C,CAAC,EAAE,sCAAsC;gBACtF,CAAC,yBAAyB,CAAC,EAAE,qBAAqB;aACnD;YACD,MAAM,EAAE;gBACN,CAAC,4CAA4C,CAAC,EAAE,sCAAsC;gBACtF,CAAC,yBAAyB,CAAC,EAAE,qBAAqB;aACnD;SACF;KACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Async2Preprocessor, Async3Preprocessor, Oas2Preprocessor, Oas3Preprocessor } from '@redocly/openapi-core';
|
|
2
|
+
type Preprocessor = Oas2Preprocessor & Oas3Preprocessor & Async2Preprocessor & Async3Preprocessor;
|
|
3
|
+
/** Name of the enforce-discriminator-mandatory custom decorator */
|
|
4
|
+
export declare const DECORATOR_ID_ENFORCE_DISCRIMINATOR_MANDATORY = "enforce-discriminator-mandatory";
|
|
5
|
+
/** Options for the enforce-discriminator-mandatory custom decorator */
|
|
6
|
+
export interface EnforceDiscriminatorMandatoryDecoratorOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Optional flag to indicate if the discriminator property was added to the required array
|
|
9
|
+
* @default false
|
|
10
|
+
*/
|
|
11
|
+
flagAddedDiscriminator?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Custom decorator to enforce that discriminator fields are required in OpenAPI schemas.
|
|
15
|
+
* This decorator works with OAS 2.0, 3.0, and 3.1 specifications.
|
|
16
|
+
* @param options
|
|
17
|
+
* @example Basic usage in redocly.yaml
|
|
18
|
+
* ```yaml
|
|
19
|
+
* plugins:
|
|
20
|
+
* - '@ama-openapi/redocly-plugin'
|
|
21
|
+
*
|
|
22
|
+
* apis:
|
|
23
|
+
* mySpec:
|
|
24
|
+
* root: apis/mySpec.json
|
|
25
|
+
* decorators:
|
|
26
|
+
* ama-openapi/enforce-discriminator-mandatory: on
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare const enforceDiscriminatorMandatoryDecorator: Preprocessor;
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=enforce-discriminator-mandatory.decorator.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enforce-discriminator-mandatory.decorator.d.mts","sourceRoot":"","sources":["../../../../../../src/plugins/decorators/common/enforce-discriminator-mandatory/enforce-discriminator-mandatory.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,mEAAmE;AACnE,eAAO,MAAM,4CAA4C,oCAAoC,CAAC;AAK9F,uEAAuE;AACvE,MAAM,WAAW,6CAA6C;IAC5D;;;OAGG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,sCAAsC,EAAE,YAkCpD,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** Name of the enforce-discriminator-mandatory custom decorator */
|
|
2
|
+
export const DECORATOR_ID_ENFORCE_DISCRIMINATOR_MANDATORY = 'enforce-discriminator-mandatory';
|
|
3
|
+
/** Flag to indicate if the discriminator property was added to the required array */
|
|
4
|
+
const X_FLAG_ADDED_DISCRIMINATOR = 'x-added-required-discriminator';
|
|
5
|
+
/**
|
|
6
|
+
* Custom decorator to enforce that discriminator fields are required in OpenAPI schemas.
|
|
7
|
+
* This decorator works with OAS 2.0, 3.0, and 3.1 specifications.
|
|
8
|
+
* @param options
|
|
9
|
+
* @example Basic usage in redocly.yaml
|
|
10
|
+
* ```yaml
|
|
11
|
+
* plugins:
|
|
12
|
+
* - '@ama-openapi/redocly-plugin'
|
|
13
|
+
*
|
|
14
|
+
* apis:
|
|
15
|
+
* mySpec:
|
|
16
|
+
* root: apis/mySpec.json
|
|
17
|
+
* decorators:
|
|
18
|
+
* ama-openapi/enforce-discriminator-mandatory: on
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export const enforceDiscriminatorMandatoryDecorator = (options) => {
|
|
22
|
+
return {
|
|
23
|
+
Schema: {
|
|
24
|
+
// use `any` type because schema OAS 2.0 is not exposed in the core, and we want to support both OAS 2.0 and 3.0 schemas
|
|
25
|
+
leave: (node) => {
|
|
26
|
+
// Check if schema has a discriminator
|
|
27
|
+
if (!node.discriminator) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
// Get the discriminator property name
|
|
31
|
+
// In OAS 2.0, discriminator is a string
|
|
32
|
+
// In OAS 3.0+, discriminator is an object with a propertyName field
|
|
33
|
+
const discriminatorProperty = typeof node.discriminator === 'string'
|
|
34
|
+
? node.discriminator
|
|
35
|
+
: node.discriminator.propertyName;
|
|
36
|
+
if (!discriminatorProperty) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
// Ensure the required array exists
|
|
40
|
+
node.required ||= [];
|
|
41
|
+
// Add discriminator property to required if not already present
|
|
42
|
+
if (!node.required.includes(discriminatorProperty)) {
|
|
43
|
+
node.required.push(discriminatorProperty);
|
|
44
|
+
if (options?.flagAddedDiscriminator) {
|
|
45
|
+
node[X_FLAG_ADDED_DISCRIMINATOR] = true;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=enforce-discriminator-mandatory.decorator.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enforce-discriminator-mandatory.decorator.mjs","sourceRoot":"","sources":["../../../../../../src/plugins/decorators/common/enforce-discriminator-mandatory/enforce-discriminator-mandatory.decorator.mts"],"names":[],"mappings":"AASA,mEAAmE;AACnE,MAAM,CAAC,MAAM,4CAA4C,GAAG,iCAAiC,CAAC;AAE9F,qFAAqF;AACrF,MAAM,0BAA0B,GAAG,gCAAgC,CAAC;AAWpE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,sCAAsC,GAAiB,CAAC,OAAsD,EAAE,EAAE;IAC7H,OAAO;QACL,MAAM,EAAE;YACN,wHAAwH;YACxH,KAAK,EAAE,CAAC,IAAS,EAAE,EAAE;gBACnB,sCAAsC;gBACtC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;oBACxB,OAAO;gBACT,CAAC;gBAED,sCAAsC;gBACtC,wCAAwC;gBACxC,oEAAoE;gBACpE,MAAM,qBAAqB,GAAG,OAAO,IAAI,CAAC,aAAa,KAAK,QAAQ;oBAClE,CAAC,CAAC,IAAI,CAAC,aAAa;oBACpB,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC;gBAEpC,IAAI,CAAC,qBAAqB,EAAE,CAAC;oBAC3B,OAAO;gBACT,CAAC;gBAED,mCAAmC;gBACnC,IAAI,CAAC,QAAQ,KAAK,EAAE,CAAC;gBAErB,gEAAgE;gBAChE,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,qBAAqB,CAAC,EAAE,CAAC;oBACnD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;oBAC1C,IAAI,OAAO,EAAE,sBAAsB,EAAE,CAAC;wBACpC,IAAI,CAAC,0BAA0B,CAAC,GAAG,IAAI,CAAC;oBAC1C,CAAC;gBACH,CAAC;YACH,CAAC;SACF;KACF,CAAC;AACJ,CAAC,CAAC"}
|