diff --git a/tools/spectral/ipa/__tests__/IPA123EnumValuesShouldNotExceed20.test.js b/tools/spectral/ipa/__tests__/IPA123EnumValuesShouldNotExceed20.test.js index 18c1acb1e8..ed9ce64708 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,84 @@ 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/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 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' 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 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; }