Skip to content

Commit 456f9b0

Browse files
prettier fix
1 parent 2ba7eac commit 456f9b0

File tree

4 files changed

+118
-99
lines changed

4 files changed

+118
-99
lines changed

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

Lines changed: 87 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ testRule('xgen-IPA-112-avoid-project-field-names', [
1111
properties: {
1212
group: { type: 'string' },
1313
groupId: { type: 'string' },
14-
otherField: { type: 'number' }
15-
}
16-
}
17-
}
18-
}
14+
otherField: { type: 'number' },
15+
},
16+
},
17+
},
18+
},
1919
},
20-
errors: []
20+
errors: [],
2121
},
2222
{
2323
name: 'invalid schema - with project field name',
@@ -26,20 +26,20 @@ testRule('xgen-IPA-112-avoid-project-field-names', [
2626
schemas: {
2727
SchemaName: {
2828
properties: {
29-
project: { type: 'string' }
30-
}
31-
}
32-
}
33-
}
29+
project: { type: 'string' },
30+
},
31+
},
32+
},
33+
},
3434
},
3535
errors: [
3636
{
3737
code: 'xgen-IPA-112-avoid-project-field-names',
3838
message: 'Field name "project" should be avoided. Consider using "group", "groups", or "groupId" instead.',
3939
path: ['components', 'schemas', 'SchemaName', 'properties', 'project'],
40-
severity: DiagnosticSeverity.Warning
41-
}
42-
]
40+
severity: DiagnosticSeverity.Warning,
41+
},
42+
],
4343
},
4444
{
4545
name: 'invalid schema - with projects field name',
@@ -48,20 +48,20 @@ testRule('xgen-IPA-112-avoid-project-field-names', [
4848
schemas: {
4949
SchemaName: {
5050
properties: {
51-
projects: { type: 'array' }
52-
}
53-
}
54-
}
55-
}
51+
projects: { type: 'array' },
52+
},
53+
},
54+
},
55+
},
5656
},
5757
errors: [
5858
{
5959
code: 'xgen-IPA-112-avoid-project-field-names',
6060
message: 'Field name "projects" should be avoided. Consider using "group", "groups", or "groupId" instead.',
6161
path: ['components', 'schemas', 'SchemaName', 'properties', 'projects'],
62-
severity: DiagnosticSeverity.Warning
63-
}
64-
]
62+
severity: DiagnosticSeverity.Warning,
63+
},
64+
],
6565
},
6666
{
6767
name: 'invalid schema - with projectId field name',
@@ -70,20 +70,20 @@ testRule('xgen-IPA-112-avoid-project-field-names', [
7070
schemas: {
7171
SchemaName: {
7272
properties: {
73-
projectId: { type: 'string' }
74-
}
75-
}
76-
}
77-
}
73+
projectId: { type: 'string' },
74+
},
75+
},
76+
},
77+
},
7878
},
7979
errors: [
8080
{
8181
code: 'xgen-IPA-112-avoid-project-field-names',
8282
message: 'Field name "projectId" should be avoided. Consider using "group", "groups", or "groupId" instead.',
8383
path: ['components', 'schemas', 'SchemaName', 'properties', 'projectId'],
84-
severity: DiagnosticSeverity.Warning
85-
}
86-
]
84+
severity: DiagnosticSeverity.Warning,
85+
},
86+
],
8787
},
8888
{
8989
name: 'invalid schema - with different case variants',
@@ -93,26 +93,26 @@ testRule('xgen-IPA-112-avoid-project-field-names', [
9393
SchemaName: {
9494
properties: {
9595
Project: { type: 'string' },
96-
PROJECTID: { type: 'string' }
97-
}
98-
}
99-
}
100-
}
96+
PROJECTID: { type: 'string' },
97+
},
98+
},
99+
},
100+
},
101101
},
102102
errors: [
103103
{
104104
code: 'xgen-IPA-112-avoid-project-field-names',
105105
message: 'Field name "Project" should be avoided. Consider using "group", "groups", or "groupId" instead.',
106106
path: ['components', 'schemas', 'SchemaName', 'properties', 'Project'],
107-
severity: DiagnosticSeverity.Warning
107+
severity: DiagnosticSeverity.Warning,
108108
},
109109
{
110110
code: 'xgen-IPA-112-avoid-project-field-names',
111111
message: 'Field name "PROJECTID" should be avoided. Consider using "group", "groups", or "groupId" instead.',
112112
path: ['components', 'schemas', 'SchemaName', 'properties', 'PROJECTID'],
113-
severity: DiagnosticSeverity.Warning
114-
}
115-
]
113+
severity: DiagnosticSeverity.Warning,
114+
},
115+
],
116116
},
117117
{
118118
name: 'invalid schema with exception - project field name with exception',
@@ -124,15 +124,15 @@ testRule('xgen-IPA-112-avoid-project-field-names', [
124124
project: {
125125
type: 'string',
126126
'x-xgen-IPA-exception': {
127-
'xgen-IPA-112-avoid-project-field-names': 'reason'
128-
}
129-
}
130-
}
131-
}
132-
}
133-
}
127+
'xgen-IPA-112-avoid-project-field-names': 'reason',
128+
},
129+
},
130+
},
131+
},
132+
},
133+
},
134134
},
135-
errors: []
135+
errors: [],
136136
},
137137
{
138138
name: 'field name containing project substring',
@@ -141,20 +141,21 @@ testRule('xgen-IPA-112-avoid-project-field-names', [
141141
schemas: {
142142
SchemaName: {
143143
properties: {
144-
myProjectDetails: { type: 'object' }
145-
}
146-
}
147-
}
148-
}
144+
myProjectDetails: { type: 'object' },
145+
},
146+
},
147+
},
148+
},
149149
},
150150
errors: [
151151
{
152152
code: 'xgen-IPA-112-avoid-project-field-names',
153-
message: 'Field name "myProjectDetails" should be avoided. Consider using "group", "groups", or "groupId" instead.',
153+
message:
154+
'Field name "myProjectDetails" should be avoided. Consider using "group", "groups", or "groupId" instead.',
154155
path: ['components', 'schemas', 'SchemaName', 'properties', 'myProjectDetails'],
155-
severity: DiagnosticSeverity.Warning
156-
}
157-
]
156+
severity: DiagnosticSeverity.Warning,
157+
},
158+
],
158159
},
159160
{
160161
name: 'exception - field with project substring',
@@ -166,15 +167,15 @@ testRule('xgen-IPA-112-avoid-project-field-names', [
166167
myProjectDetails: {
167168
type: 'object',
168169
'x-xgen-IPA-exception': {
169-
'xgen-IPA-112-avoid-project-field-names': 'Legacy field name that cannot be changed'
170-
}
171-
}
172-
}
173-
}
174-
}
175-
}
170+
'xgen-IPA-112-avoid-project-field-names': 'Legacy field name that cannot be changed',
171+
},
172+
},
173+
},
174+
},
175+
},
176+
},
176177
},
177-
errors: []
178+
errors: [],
178179
},
179180
{
180181
name: 'exception - multiple project fields',
@@ -186,21 +187,21 @@ testRule('xgen-IPA-112-avoid-project-field-names', [
186187
projectId: {
187188
type: 'string',
188189
'x-xgen-IPA-exception': {
189-
'xgen-IPA-112-avoid-project-field-names': 'External API compatibility'
190-
}
190+
'xgen-IPA-112-avoid-project-field-names': 'External API compatibility',
191+
},
191192
},
192193
projects: {
193194
type: 'array',
194195
'x-xgen-IPA-exception': {
195-
'xgen-IPA-112-avoid-project-field-names': 'External API compatibility'
196-
}
197-
}
198-
}
199-
}
200-
}
201-
}
196+
'xgen-IPA-112-avoid-project-field-names': 'External API compatibility',
197+
},
198+
},
199+
},
200+
},
201+
},
202+
},
202203
},
203-
errors: []
204+
errors: [],
204205
},
205206
{
206207
name: 'mixed valid, invalid, and exception fields',
@@ -212,23 +213,23 @@ testRule('xgen-IPA-112-avoid-project-field-names', [
212213
project: {
213214
type: 'string',
214215
'x-xgen-IPA-exception': {
215-
'xgen-IPA-112-avoid-project-field-names': 'Legacy field'
216-
}
216+
'xgen-IPA-112-avoid-project-field-names': 'Legacy field',
217+
},
217218
},
218219
projectId: { type: 'string' },
219-
group: { type: 'string' }
220-
}
221-
}
222-
}
223-
}
220+
group: { type: 'string' },
221+
},
222+
},
223+
},
224+
},
224225
},
225226
errors: [
226227
{
227228
code: 'xgen-IPA-112-avoid-project-field-names',
228229
message: 'Field name "projectId" should be avoided. Consider using "group", "groups", or "groupId" instead.',
229230
path: ['components', 'schemas', 'SchemaName', 'properties', 'projectId'],
230-
severity: DiagnosticSeverity.Warning
231-
}
232-
]
233-
}
234-
]);
231+
severity: DiagnosticSeverity.Warning,
232+
},
233+
],
234+
},
235+
]);

tools/spectral/ipa/rulesets/IPA-112.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ rules:
88
xgen-IPA-112-avoid-project-field-names:
99
description: |
1010
Schema field names should avoid using "project", "projects", or "projectId".
11-
11+
1212
##### Implementation details
1313
Rule checks for the following conditions:
1414
- Searches through all schemas in the API definition
@@ -17,8 +17,8 @@ rules:
1717
- Suggests using "group", "groups", or "groupId" as alternatives
1818
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-112-avoid-project-field-names'
1919
severity: warn
20-
given: "$.components.schemas..properties[*]~"
20+
given: '$.components.schemas..properties[*]~'
2121
then:
2222
function: 'IPA112AvoidProjectFieldNames'
2323
functionOptions:
24-
prohibitedFieldName: "project"
24+
prohibitedFieldName: 'project'

tools/spectral/ipa/rulesets/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,24 @@ Rule checks for the following conditions:
426426

427427

428428

429+
### IPA-112
430+
431+
Rules are based on [http://go/ipa/IPA-112](http://go/ipa/IPA-112).
432+
433+
#### xgen-IPA-112-avoid-project-field-names
434+
435+
![warn](https://img.shields.io/badge/warning-yellow)
436+
Schema field names should avoid using "project", "projects", or "projectId".
437+
438+
##### Implementation details
439+
Rule checks for the following conditions:
440+
- Searches through all schemas in the API definition
441+
- Identifies property names that match "project" (case-insensitive)
442+
- Reports any instances where these field names are used
443+
- Suggests using "group", "groups", or "groupId" as alternatives
444+
445+
446+
429447
### IPA-113
430448

431449
Rules are based on [http://go/ipa/IPA-113](http://go/ipa/IPA-113).
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
21
import { hasException } from './utils/exceptions.js';
32
import {
43
collectAdoption,
54
collectAndReturnViolation,
6-
collectException, handleInternalError,
5+
collectException,
6+
handleInternalError,
77
} from './utils/collectionUtils.js';
88
import { resolveObject } from './utils/componentUtils.js';
99

1010
const RULE_NAME = 'xgen-IPA-112-avoid-project-field-names';
1111

1212
export default (input, options, { path, documentInventory }) => {
13-
1413
const oas = documentInventory.resolved;
1514
const property = resolveObject(oas, path);
1615

@@ -24,22 +23,23 @@ export default (input, options, { path, documentInventory }) => {
2423
return collectAndReturnViolation(path, RULE_NAME, errors);
2524
}
2625
collectAdoption(path, RULE_NAME);
27-
2826
};
2927

3028
function checkViolationsAndReturnErrors(input, options, path) {
3129
try {
32-
const prohibitedFieldName = options?.prohibitedFieldName || "";
30+
const prohibitedFieldName = options?.prohibitedFieldName || '';
3331
const lowerPropertyName = input.toLowerCase();
3432
if (lowerPropertyName.includes(prohibitedFieldName)) {
35-
return [{
36-
path,
37-
message: `Field name "${input}" should be avoided. Consider using "group", "groups", or "groupId" instead.`
38-
}];
33+
return [
34+
{
35+
path,
36+
message: `Field name "${input}" should be avoided. Consider using "group", "groups", or "groupId" instead.`,
37+
},
38+
];
3939
}
4040

4141
return [];
4242
} catch (e) {
4343
handleInternalError(RULE_NAME, path, e);
4444
}
45-
}
45+
}

0 commit comments

Comments
 (0)