Skip to content

Commit 3e9dd33

Browse files
CLOUDP-291457: IPA-123 ArraySchema fix (#338)
1 parent ead9f92 commit 3e9dd33

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
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: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ import { casing } from '@stoplight/spectral-functions';
55
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

8-
export function getSchemaPathFromEnumPath(path) {
9-
return path.slice(0, path.length - 1);
8+
function getSchemaPathFromEnumPath(path) {
9+
const enumIndex = path.lastIndexOf('enum');
10+
if (path[enumIndex - 1] === 'items') {
11+
return path.slice(0, enumIndex - 1);
12+
}
13+
return path.slice(0, enumIndex);
1014
}
1115

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

0 commit comments

Comments
 (0)