Skip to content

Commit 93331b3

Browse files
IPA-112: Field names must use camelCase (#589)
1 parent a03dee2 commit 93331b3

File tree

5 files changed

+629
-99
lines changed

5 files changed

+629
-99
lines changed

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

Lines changed: 110 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,41 @@ testRule('xgen-IPA-112-avoid-project-field-names', [
1818
},
1919
},
2020
},
21+
paths: {
22+
'/users': {
23+
post: {
24+
requestBody: {
25+
content: {
26+
'application/vnd.atlas.2024-01-01+json': {
27+
schema: {
28+
type: 'object',
29+
properties: {
30+
group: { type: 'string' },
31+
groupId: { type: 'string' },
32+
gcpProjectId: { type: 'string' },
33+
},
34+
},
35+
},
36+
},
37+
},
38+
responses: {
39+
201: {
40+
content: {
41+
'application/vnd.atlas.2024-01-01+json': {
42+
schema: {
43+
type: 'object',
44+
properties: {
45+
group: { type: 'string' },
46+
gcpProjectId: { type: 'string' },
47+
},
48+
},
49+
},
50+
},
51+
},
52+
},
53+
},
54+
},
55+
},
2156
},
2257
errors: [],
2358
},
@@ -29,6 +64,41 @@ testRule('xgen-IPA-112-avoid-project-field-names', [
2964
SchemaName: {
3065
properties: {
3166
project: { type: 'string' },
67+
projects: { type: 'array' },
68+
projectId: { type: 'string' },
69+
myProjectDetails: { type: 'object' },
70+
},
71+
},
72+
},
73+
},
74+
paths: {
75+
'/users': {
76+
post: {
77+
requestBody: {
78+
content: {
79+
'application/vnd.atlas.2024-01-01+json': {
80+
schema: {
81+
type: 'object',
82+
properties: {
83+
projectId: { type: 'string' },
84+
},
85+
},
86+
},
87+
},
88+
},
89+
responses: {
90+
201: {
91+
content: {
92+
'application/vnd.atlas.2024-01-01+json': {
93+
schema: {
94+
type: 'object',
95+
properties: {
96+
projectId: { type: 'string' },
97+
},
98+
},
99+
},
100+
},
101+
},
32102
},
33103
},
34104
},
@@ -41,105 +111,70 @@ testRule('xgen-IPA-112-avoid-project-field-names', [
41111
path: ['components', 'schemas', 'SchemaName', 'properties', 'project'],
42112
severity: DiagnosticSeverity.Warning,
43113
},
44-
],
45-
},
46-
{
47-
name: 'invalid schema - with projects field name',
48-
document: {
49-
components: {
50-
schemas: {
51-
SchemaName: {
52-
properties: {
53-
projects: { type: 'array' },
54-
},
55-
},
56-
},
57-
},
58-
},
59-
errors: [
60114
{
61115
code: 'xgen-IPA-112-avoid-project-field-names',
62116
message: 'Field name "projects" should be avoided. Consider using "groups" instead.',
63117
path: ['components', 'schemas', 'SchemaName', 'properties', 'projects'],
64118
severity: DiagnosticSeverity.Warning,
65119
},
66-
],
67-
},
68-
{
69-
name: 'invalid schema - with projectId field name',
70-
document: {
71-
components: {
72-
schemas: {
73-
SchemaName: {
74-
properties: {
75-
projectId: { type: 'string' },
76-
},
77-
},
78-
},
79-
},
80-
},
81-
errors: [
82120
{
83121
code: 'xgen-IPA-112-avoid-project-field-names',
84122
message: 'Field name "projectId" should be avoided. Consider using "group" instead.',
85123
path: ['components', 'schemas', 'SchemaName', 'properties', 'projectId'],
86124
severity: DiagnosticSeverity.Warning,
87125
},
88-
],
89-
},
90-
{
91-
name: 'invalid schema with exception - project field name with exception',
92-
document: {
93-
components: {
94-
schemas: {
95-
SchemaName: {
96-
properties: {
97-
project: {
98-
type: 'string',
99-
'x-xgen-IPA-exception': {
100-
'xgen-IPA-112-avoid-project-field-names': 'reason',
101-
},
102-
},
103-
},
104-
},
105-
},
106-
},
107-
},
108-
errors: [],
109-
},
110-
{
111-
name: 'field name containing project substring',
112-
document: {
113-
components: {
114-
schemas: {
115-
SchemaName: {
116-
properties: {
117-
myProjectDetails: { type: 'object' },
118-
},
119-
},
120-
},
121-
},
122-
},
123-
errors: [
124126
{
125127
code: 'xgen-IPA-112-avoid-project-field-names',
126128
message: 'Field name "myProjectDetails" should be avoided. Consider using "group" instead.',
127129
path: ['components', 'schemas', 'SchemaName', 'properties', 'myProjectDetails'],
128130
severity: DiagnosticSeverity.Warning,
129131
},
132+
{
133+
code: 'xgen-IPA-112-avoid-project-field-names',
134+
message: 'Field name "projectId" should be avoided. Consider using "group" instead.',
135+
path: [
136+
'paths',
137+
'/users',
138+
'post',
139+
'requestBody',
140+
'content',
141+
'application/vnd.atlas.2024-01-01+json',
142+
'schema',
143+
'properties',
144+
'projectId',
145+
],
146+
severity: DiagnosticSeverity.Warning,
147+
},
148+
{
149+
code: 'xgen-IPA-112-avoid-project-field-names',
150+
message: 'Field name "projectId" should be avoided. Consider using "group" instead.',
151+
path: [
152+
'paths',
153+
'/users',
154+
'post',
155+
'responses',
156+
'201',
157+
'content',
158+
'application/vnd.atlas.2024-01-01+json',
159+
'schema',
160+
'properties',
161+
'projectId',
162+
],
163+
severity: DiagnosticSeverity.Warning,
164+
},
130165
],
131166
},
132167
{
133-
name: 'exception - field with project substring',
168+
name: 'invalid schema with exception - project field name with exception',
134169
document: {
135170
components: {
136171
schemas: {
137172
SchemaName: {
138173
properties: {
139-
myProjectDetails: {
140-
type: 'object',
174+
project: {
175+
type: 'string',
141176
'x-xgen-IPA-exception': {
142-
'xgen-IPA-112-avoid-project-field-names': 'Reason',
177+
'xgen-IPA-112-avoid-project-field-names': 'reason',
143178
},
144179
},
145180
},
@@ -168,40 +203,17 @@ testRule('xgen-IPA-112-avoid-project-field-names', [
168203
'xgen-IPA-112-avoid-project-field-names': 'Reason',
169204
},
170205
},
171-
},
172-
},
173-
},
174-
},
175-
},
176-
errors: [],
177-
},
178-
{
179-
name: 'mixed valid, invalid, and exception fields',
180-
document: {
181-
components: {
182-
schemas: {
183-
SchemaName: {
184-
properties: {
185-
project: {
186-
type: 'string',
206+
myProjectDetails: {
207+
type: 'object',
187208
'x-xgen-IPA-exception': {
188209
'xgen-IPA-112-avoid-project-field-names': 'Reason',
189210
},
190211
},
191-
projectId: { type: 'string' },
192-
group: { type: 'string' },
193212
},
194213
},
195214
},
196215
},
197216
},
198-
errors: [
199-
{
200-
code: 'xgen-IPA-112-avoid-project-field-names',
201-
message: 'Field name "projectId" should be avoided. Consider using "group" instead.',
202-
path: ['components', 'schemas', 'SchemaName', 'properties', 'projectId'],
203-
severity: DiagnosticSeverity.Warning,
204-
},
205-
],
217+
errors: [],
206218
},
207219
]);

0 commit comments

Comments
 (0)