Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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': {
Expand Down Expand Up @@ -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,
},
],
},
]);
11 changes: 11 additions & 0 deletions tools/spectral/ipa/ipa-spectral.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: These will be reverted after the relevant exceptions are defined for them

- '**#/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
Expand Down
4 changes: 1 addition & 3 deletions tools/spectral/ipa/rulesets/IPA-123.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 1 addition & 3 deletions tools/spectral/ipa/rulesets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading