Skip to content

Commit 5f83dac

Browse files
CLOUDP-306576: IPA-119: Multi-Cloud Support (Fix) (#647)
1 parent aa841d5 commit 5f83dac

File tree

2 files changed

+42
-27
lines changed

2 files changed

+42
-27
lines changed

tools/spectral/ipa/__tests__/IPA119NoDefaultForCloudProviders.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ testRule('xgen-IPA-119-no-default-for-cloud-providers', [
2121
errors: [],
2222
},
2323
{
24-
name: 'invalid when cloud provider field has default value',
24+
name: 'invalid when cloudProvider field has default value',
2525
document: {
2626
components: {
2727
schemas: {
@@ -47,7 +47,7 @@ testRule('xgen-IPA-119-no-default-for-cloud-providers', [
4747
],
4848
},
4949
{
50-
name: 'invalid when cloud provider field has default value',
50+
name: 'invalid when provider field has default value',
5151
document: {
5252
components: {
5353
schemas: {

tools/spectral/ipa/rulesets/functions/IPA119NoDefaultForCloudProviders.js

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,20 @@ export default (input, { propertyNameToLookFor, cloudProviderEnumValues }, { pat
2323
return;
2424
}
2525

26-
const errors = checkViolationsAndReturnErrors(
26+
const result = checkViolationsAndReturnErrors(
2727
input,
2828
propertyObject,
2929
path,
3030
propertyNameToLookFor,
3131
fieldType,
3232
cloudProviderEnumValues
3333
);
34-
if (errors.length !== 0) {
35-
return collectAndReturnViolation(path, RULE_NAME, errors);
34+
if (result.errors.length !== 0) {
35+
return collectAndReturnViolation(path, RULE_NAME, result.errors);
36+
}
37+
if (result.isCloudProviderField) {
38+
collectAdoption(path, RULE_NAME);
3639
}
37-
collectAdoption(path, RULE_NAME);
3840
};
3941

4042
function checkViolationsAndReturnErrors(
@@ -46,38 +48,49 @@ function checkViolationsAndReturnErrors(
4648
cloudProviderEnumValues
4749
) {
4850
try {
51+
const result = {
52+
errors: [],
53+
isCloudProviderField: false,
54+
};
55+
4956
if (fieldType === 'properties') {
50-
if (propertyName === propertyNameToLookFor && propertyObject.default !== undefined) {
51-
return [
52-
{
57+
if (propertyName === propertyNameToLookFor) {
58+
result.isCloudProviderField = true;
59+
if (propertyObject.default !== undefined) {
60+
result.errors.push({
5361
path,
5462
message: ERROR_MESSAGE,
55-
},
56-
];
63+
});
64+
return result;
65+
}
5766
}
5867

5968
if (Array.isArray(propertyObject.enum) && propertyObject.enum.length > 0) {
6069
const enumValues = propertyObject.enum;
6170
const hasCloudProviderEnumValue = cloudProviderEnumValues.every((cloudProviderValue) =>
6271
enumValues.includes(cloudProviderValue)
6372
);
64-
if (hasCloudProviderEnumValue && propertyObject.default !== undefined) {
65-
return [
66-
{
73+
if (hasCloudProviderEnumValue) {
74+
result.isCloudProviderField = true;
75+
if (propertyObject.default !== undefined) {
76+
result.errors.push({
6777
path,
6878
message: ERROR_MESSAGE,
69-
},
70-
];
79+
});
80+
return result;
81+
}
7182
}
7283
}
7384
} else if (fieldType === 'parameters') {
74-
if (propertyObject.name === propertyNameToLookFor && propertyObject.schema.default !== undefined) {
75-
return [
76-
{
85+
if (propertyObject.name === propertyNameToLookFor) {
86+
result.isCloudProviderField = true;
87+
if (propertyObject.schema.default !== undefined) {
88+
result.errors.push({
7789
path,
7890
message: ERROR_MESSAGE,
79-
},
80-
];
91+
});
92+
return result;
93+
}
8194
}
8295

8396
if (Array.isArray(propertyObject.schema.enum) && propertyObject.schema.enum.length > 0) {
@@ -86,18 +99,20 @@ function checkViolationsAndReturnErrors(
8699
enumValues.includes(cloudProviderValue)
87100
);
88101

89-
if (hasCloudProviderEnumValue && propertyObject.schema.default !== undefined) {
90-
return [
91-
{
102+
if (hasCloudProviderEnumValue) {
103+
result.isCloudProviderField = true;
104+
if (propertyObject.schema.default !== undefined) {
105+
result.errors.push({
92106
path,
93107
message: ERROR_MESSAGE,
94-
},
95-
];
108+
});
109+
return result;
110+
}
96111
}
97112
}
98113
}
99114

100-
return [];
115+
return result;
101116
} catch (e) {
102117
handleInternalError(RULE_NAME, path, e);
103118
}

0 commit comments

Comments
 (0)