Skip to content

Commit aa6b264

Browse files
CLOUDP-291457: IPA-123 ArraySchema fix
1 parent 1157520 commit aa6b264

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

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

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,25 @@ testRule('xgen-IPA-123-enum-values-must-be-upper-snake-case', [
77
document: {
88
components: {
99
schemas: {
10-
SchemaName: {
10+
SchemaName1: {
1111
properties: {
1212
exampleProperty: {
1313
enum: ['EXAMPLE_A', 'EXAMPLE_B'],
1414
type: 'string',
1515
},
1616
},
1717
},
18+
SchemaName2: {
19+
properties: {
20+
exampleProperty: {
21+
type: 'array',
22+
items: {
23+
type: 'string',
24+
enum: ['EXAMPLE_A', 'EXAMPLE_B'],
25+
}
26+
},
27+
},
28+
},
1829
},
1930
},
2031
},
@@ -36,6 +47,20 @@ testRule('xgen-IPA-123-enum-values-must-be-upper-snake-case', [
3647
},
3748
},
3849
},
50+
SchemaName2: {
51+
properties: {
52+
exampleProperty: {
53+
type: 'array',
54+
items: {
55+
type: 'string',
56+
enum: ['exampleA', 'exampleB'],
57+
},
58+
'x-xgen-IPA-exception': {
59+
'xgen-IPA-123-enum-values-must-be-upper-snake-case': 'reason',
60+
},
61+
},
62+
},
63+
},
3964
},
4065
},
4166
},
@@ -54,6 +79,17 @@ testRule('xgen-IPA-123-enum-values-must-be-upper-snake-case', [
5479
},
5580
},
5681
},
82+
SchemaName2: {
83+
properties: {
84+
exampleProperty: {
85+
type: 'array',
86+
items: {
87+
type: 'string',
88+
enum: ['exampleA', 'exampleB'],
89+
},
90+
},
91+
},
92+
},
5793
},
5894
},
5995
},
@@ -70,6 +106,18 @@ testRule('xgen-IPA-123-enum-values-must-be-upper-snake-case', [
70106
path: ['components', 'schemas', 'SchemaName', 'properties', 'exampleProperty'],
71107
severity: DiagnosticSeverity.Warning,
72108
},
109+
{
110+
code: 'xgen-IPA-123-enum-values-must-be-upper-snake-case',
111+
message: 'enum[0]:exampleA enum value must be UPPER_SNAKE_CASE. http://go/ipa/123',
112+
path: ['components', 'schemas', 'SchemaName2', 'properties', 'exampleProperty'],
113+
severity: DiagnosticSeverity.Warning,
114+
},
115+
{
116+
code: 'xgen-IPA-123-enum-values-must-be-upper-snake-case',
117+
message: 'enum[1]:exampleB enum value must be UPPER_SNAKE_CASE. http://go/ipa/123',
118+
path: ['components', 'schemas', 'SchemaName2', 'properties', 'exampleProperty'],
119+
severity: DiagnosticSeverity.Warning,
120+
},
73121
],
74122
},
75123
{

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ const RULE_NAME = 'xgen-IPA-123-enum-values-must-be-upper-snake-case';
66
const ERROR_MESSAGE = 'enum value must be UPPER_SNAKE_CASE.';
77

88
export function getSchemaPathFromEnumPath(path) {
9-
return path.slice(0, path.length - 1);
9+
if(path.includes('items')) {
10+
path = path.slice(0, - 1);
11+
}
12+
return path.slice(0, - 1);
1013
}
1114

1215
export default (input, _, { path, documentInventory }) => {

0 commit comments

Comments
 (0)