From ef107f2deb9467263fdfc081d469a8024058aac8 Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Wed, 13 Aug 2025 11:45:26 +0100 Subject: [PATCH 1/4] fix(ipa): Validate both inline and reusable enums --- .../IPA123EnumValuesShouldNotExceed20.test.js | 70 +++++++++++++++++-- .../IPA123EnumValuesShouldNotExceed20.js | 7 +- 2 files changed, 67 insertions(+), 10 deletions(-) diff --git a/tools/spectral/ipa/__tests__/IPA123EnumValuesShouldNotExceed20.test.js b/tools/spectral/ipa/__tests__/IPA123EnumValuesShouldNotExceed20.test.js index 18c1acb1e8..20cd7454d9 100644 --- a/tools/spectral/ipa/__tests__/IPA123EnumValuesShouldNotExceed20.test.js +++ b/tools/spectral/ipa/__tests__/IPA123EnumValuesShouldNotExceed20.test.js @@ -100,7 +100,7 @@ testRule('xgen-IPA-123-allowable-enum-values-should-not-exceed-20', [ errors: [ { code: 'xgen-IPA-123-allowable-enum-values-should-not-exceed-20', - message: 'Inline enum arrays should not exceed 20 values. Current count: 21', + message: 'The number of allowable enum values should not exceed 20 values. Current count: 21', path: ['components', 'schemas', 'TestSchema', 'properties', 'status', 'enum'], severity: DiagnosticSeverity.Error, }, @@ -172,7 +172,7 @@ testRule('xgen-IPA-123-allowable-enum-values-should-not-exceed-20', [ errors: [ { code: 'xgen-IPA-123-allowable-enum-values-should-not-exceed-20', - message: 'Inline enum arrays should not exceed 20 values. Current count: 21', + message: 'The number of allowable enum values should not exceed 20 values. Current count: 21', path: ['components', 'schemas', 'TestSchema', 'properties', 'priority', 'enum'], severity: DiagnosticSeverity.Error, }, @@ -245,7 +245,7 @@ testRule('xgen-IPA-123-allowable-enum-values-should-not-exceed-20', [ errors: [ { code: 'xgen-IPA-123-allowable-enum-values-should-not-exceed-20', - message: 'Inline enum arrays should not exceed 20 values. Current count: 21', + message: 'The number of allowable enum values should not exceed 20 values. Current count: 21', path: ['paths', '/resources', 'get', 'parameters', '0', 'schema', 'enum'], severity: DiagnosticSeverity.Error, }, @@ -303,7 +303,7 @@ testRule('xgen-IPA-123-allowable-enum-values-should-not-exceed-20', [ errors: [], }, { - name: 'valid on with reusable schemas', + name: 'invalid on with reusable schemas', document: { paths: { '/resources': { @@ -362,6 +362,68 @@ testRule('xgen-IPA-123-allowable-enum-values-should-not-exceed-20', [ }, }, }, + errors: [ + { + code: 'xgen-IPA-123-allowable-enum-values-should-not-exceed-20', + message: 'The number of allowable enum values should not exceed 20 values. Current count: 25', + path: ['components', 'schemas', 'StatusEnum', 'enum'], + severity: DiagnosticSeverity.Error, + }, + ], + }, + { + name: 'valid enum array in items schema', + document: { + components: { + schemas: { + TestSchema: { + properties: { + statusList: { + type: 'array', + items: { + type: 'string', + enum: ['PENDING', 'ACTIVE', 'COMPLETE', 'FAILED', 'CANCELLED'], + }, + }, + }, + }, + }, + }, + }, errors: [], }, + { + name: 'invalid enum array in items schema exceeding limit', + document: { + components: { + schemas: { + TestSchema: { + properties: { + statusList: { + type: 'array', + items: { + type: 'string', + enum: [ + 'VAL_1', 'VAL_2', 'VAL_3', 'VAL_4', 'VAL_5', + 'VAL_6', 'VAL_7', 'VAL_8', 'VAL_9', 'VAL_10', + 'VAL_11', 'VAL_12', 'VAL_13', 'VAL_14', 'VAL_15', + 'VAL_16', 'VAL_17', 'VAL_18', 'VAL_19', 'VAL_20', + 'VAL_21', + ], + }, + }, + }, + }, + }, + }, + }, + errors: [ + { + code: 'xgen-IPA-123-allowable-enum-values-should-not-exceed-20', + message: 'The number of allowable enum values should not exceed 20 values. Current count: 21', + path: ['components', 'schemas', 'TestSchema', 'properties', 'statusList', 'items', 'enum'], + severity: DiagnosticSeverity.Error, + }, + ], + }, ]); diff --git a/tools/spectral/ipa/rulesets/functions/IPA123EnumValuesShouldNotExceed20.js b/tools/spectral/ipa/rulesets/functions/IPA123EnumValuesShouldNotExceed20.js index 1870117920..fb79a51b15 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA123EnumValuesShouldNotExceed20.js +++ b/tools/spectral/ipa/rulesets/functions/IPA123EnumValuesShouldNotExceed20.js @@ -3,18 +3,13 @@ import { getSchemaPathFromEnumPath } from './utils/schemaUtils.js'; import { resolveObject } from './utils/componentUtils.js'; const RULE_NAME = 'xgen-IPA-123-allowable-enum-values-should-not-exceed-20'; -const ERROR_MESSAGE = 'Inline enum arrays should not exceed 20 values. Current count: '; +const ERROR_MESSAGE = 'The number of allowable enum values should not exceed 20 values. Current count: '; export default (input, { maxEnumValues }, { path, documentInventory }) => { const oas = documentInventory.resolved; const schemaPath = getSchemaPathFromEnumPath(path); const schemaObject = resolveObject(oas, schemaPath); - //Ignore if the schemaObject belongs to a reusable enum - if (!schemaPath.includes('properties') && !schemaPath.includes('parameters')) { - return; - } - if (!Array.isArray(input)) { return; } From b2ac284f55130e7aadb9db5f2cb9ecb2780e05f0 Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Wed, 13 Aug 2025 11:51:53 +0100 Subject: [PATCH 2/4] Doc fix --- .../IPA123EnumValuesShouldNotExceed20.test.js | 24 +++++++++++++++---- tools/spectral/ipa/rulesets/IPA-123.yaml | 4 +--- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/tools/spectral/ipa/__tests__/IPA123EnumValuesShouldNotExceed20.test.js b/tools/spectral/ipa/__tests__/IPA123EnumValuesShouldNotExceed20.test.js index 20cd7454d9..ed9ce64708 100644 --- a/tools/spectral/ipa/__tests__/IPA123EnumValuesShouldNotExceed20.test.js +++ b/tools/spectral/ipa/__tests__/IPA123EnumValuesShouldNotExceed20.test.js @@ -404,10 +404,26 @@ testRule('xgen-IPA-123-allowable-enum-values-should-not-exceed-20', [ items: { type: 'string', enum: [ - 'VAL_1', 'VAL_2', 'VAL_3', 'VAL_4', 'VAL_5', - 'VAL_6', 'VAL_7', 'VAL_8', 'VAL_9', 'VAL_10', - 'VAL_11', 'VAL_12', 'VAL_13', 'VAL_14', 'VAL_15', - 'VAL_16', 'VAL_17', 'VAL_18', 'VAL_19', 'VAL_20', + 'VAL_1', + 'VAL_2', + 'VAL_3', + 'VAL_4', + 'VAL_5', + 'VAL_6', + 'VAL_7', + 'VAL_8', + 'VAL_9', + 'VAL_10', + 'VAL_11', + 'VAL_12', + 'VAL_13', + 'VAL_14', + 'VAL_15', + 'VAL_16', + 'VAL_17', + 'VAL_18', + 'VAL_19', + 'VAL_20', 'VAL_21', ], }, diff --git a/tools/spectral/ipa/rulesets/IPA-123.yaml b/tools/spectral/ipa/rulesets/IPA-123.yaml index e73513a57e..0e9ec84509 100644 --- a/tools/spectral/ipa/rulesets/IPA-123.yaml +++ b/tools/spectral/ipa/rulesets/IPA-123.yaml @@ -28,9 +28,7 @@ rules: ##### Implementation details Rule checks for the following conditions: - - Applies to inline enum values - - Validates that each enum array has 20 or fewer values - - Reusable enum schemas will be ignored + - Validates that each enum set has 20 or fewer values - Skips validation if the schema has an exception defined for this rule - This validation threshold can be adjusted by changing the functionOptions.maxEnumValues parameter message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-123-allowable-enum-values-should-not-exceed-20' From 172a341d74f96a39ab0d3dc19fc8645a9fc8dec0 Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Wed, 13 Aug 2025 12:07:56 +0100 Subject: [PATCH 3/4] Doc fix --- tools/spectral/ipa/rulesets/README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tools/spectral/ipa/rulesets/README.md b/tools/spectral/ipa/rulesets/README.md index cc5951de30..af80e9a52a 100644 --- a/tools/spectral/ipa/rulesets/README.md +++ b/tools/spectral/ipa/rulesets/README.md @@ -910,9 +910,7 @@ Allowable enum values should not exceed 20 entries. ##### Implementation details Rule checks for the following conditions: - - Applies to inline enum values - - Validates that each enum array has 20 or fewer values - - Reusable enum schemas will be ignored + - Validates that each enum set has 20 or fewer values - Skips validation if the schema has an exception defined for this rule - This validation threshold can be adjusted by changing the functionOptions.maxEnumValues parameter From 1058aed274e9fffaa8d03a271c8f9de19eedffec Mon Sep 17 00:00:00 2001 From: Yeliz Henden Date: Wed, 13 Aug 2025 12:12:44 +0100 Subject: [PATCH 4/4] add overrides --- tools/spectral/ipa/ipa-spectral.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/spectral/ipa/ipa-spectral.yaml b/tools/spectral/ipa/ipa-spectral.yaml index 95a3677643..63edceb147 100644 --- a/tools/spectral/ipa/ipa-spectral.yaml +++ b/tools/spectral/ipa/ipa-spectral.yaml @@ -102,6 +102,17 @@ overrides: - '**#/components/schemas/CloudRegionConfig/properties/regionName/oneOf/2' # reference to support future investigation - CLOUDP-310775 - '**#/components/schemas/InvoiceLineItem/properties/sku' # reference to support future investigation - CLOUDP-310775 - '**#/components/schemas/Collation/properties/locale' # reference to support future investigation - CLOUDP-310775 + - '**#/components/schemas/BaseCloudProviderInstanceSize/oneOf/0' # reference to support future investigation - CLOUDP-310775 + - '**#/components/schemas/BaseCloudProviderInstanceSize/oneOf/1' # reference to support future investigation - CLOUDP-310775 + - '**#/components/schemas/BillingEventTypeViewForOrg' # reference to support future investigation - CLOUDP-310775 + - '**#/components/schemas/EventTypeForNdsGroup/oneOf/24' # reference to support future investigation - CLOUDP-310775 + - '**#/components/schemas/EventTypeForNdsGroup/oneOf/27' # reference to support future investigation - CLOUDP-310775 + - '**#/components/schemas/EventTypeForOrg/oneOf/4' # reference to support future investigation - CLOUDP-310775 + - '**#/components/schemas/EventTypeForOrg/oneOf/5' # reference to support future investigation - CLOUDP-310775 + - '**#/components/schemas/EventTypeForOrg/oneOf/9' # reference to support future investigation - CLOUDP-310775 + - '**#/components/schemas/HostEventTypeViewForNdsGroup' # reference to support future investigation - CLOUDP-310775 + - '**#/components/schemas/NDSAuditTypeViewForNdsGroup' # reference to support future investigation - CLOUDP-310775 + - '**#/components/schemas/OrgEventTypeViewForOrg' # reference to support future investigation - CLOUDP-310775 - '**#/components/schemas/tokenFiltersnowballStemming/properties/stemmerName' # external field, to be covered by CLOUDP-293178 - '**#/components/schemas/DataLakeS3StoreSettings/allOf/1/properties/region' # external field, to be covered by CLOUDP-293178 - '**#/components/schemas/DataLakeDLSAWSStore/allOf/1/properties/region' # external field, to be covered by CLOUDP-293178