Skip to content

Commit 163614e

Browse files
IPA 106: Create : A Request object must include only input fields
1 parent 0e988e5 commit 163614e

File tree

4 files changed

+37
-19
lines changed

4 files changed

+37
-19
lines changed

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ testRule('xgen-IPA-106-create-method-request-has-no-readonly-fields', [
8080
schema: {
8181
$ref: '#/components/schemas/SchemaWithoutReadOnly'
8282
}
83+
},
84+
'application/vnd.atlas.2024-01-01+json': {
85+
schema: {
86+
type: "string"
87+
}
8388
}
8489
}
8590
}
@@ -124,6 +129,12 @@ testRule('xgen-IPA-106-create-method-request-has-no-readonly-fields', [
124129
schema: {
125130
$ref: '#/components/schemas/SchemaWithReadOnly'
126131
}
132+
},
133+
'application/vnd.atlas.2024-01-01+json': {
134+
schema: {
135+
type: "string",
136+
readOnly: true
137+
}
127138
}
128139
}
129140
}
@@ -134,9 +145,15 @@ testRule('xgen-IPA-106-create-method-request-has-no-readonly-fields', [
134145
errors: [
135146
{
136147
code: 'xgen-IPA-106-create-method-request-has-no-readonly-fields',
137-
message: 'The Create method request object must not include input fields (readOnly properties). Found readOnly property at: id http://go/ipa/106',
148+
message: 'The Create method request object must not include input fields (readOnly properties). Found readOnly property at: id. http://go/ipa/106',
138149
path: ['paths', '/invalid-resource', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'],
139150
severity: DiagnosticSeverity.Warning,
151+
},
152+
{
153+
code: 'xgen-IPA-106-create-method-request-has-no-readonly-fields',
154+
message: 'The Create method request object must not include input fields (readOnly properties). Found readOnly property at one of the inline schemas. http://go/ipa/106',
155+
path: ['paths', '/invalid-resource', 'post', 'requestBody', 'content', 'application/vnd.atlas.2024-01-01+json'],
156+
severity: DiagnosticSeverity.Warning,
140157
}
141158
]
142159
},
@@ -163,7 +180,7 @@ testRule('xgen-IPA-106-create-method-request-has-no-readonly-fields', [
163180
errors: [
164181
{
165182
code: 'xgen-IPA-106-create-method-request-has-no-readonly-fields',
166-
message: 'The Create method request object must not include input fields (readOnly properties). Found readOnly property at: user.userId http://go/ipa/106',
183+
message: 'The Create method request object must not include input fields (readOnly properties). Found readOnly property at: user.userId. http://go/ipa/106',
167184
path: ['paths', '/nested-invalid-resource', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'],
168185
severity: DiagnosticSeverity.Warning,
169186
}
@@ -192,7 +209,7 @@ testRule('xgen-IPA-106-create-method-request-has-no-readonly-fields', [
192209
errors: [
193210
{
194211
code: 'xgen-IPA-106-create-method-request-has-no-readonly-fields',
195-
message: 'The Create method request object must not include input fields (readOnly properties). Found readOnly property at: items.items.itemId http://go/ipa/106',
212+
message: 'The Create method request object must not include input fields (readOnly properties). Found readOnly property at: items.items.itemId. http://go/ipa/106',
196213
path: ['paths', '/array-invalid-resource', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'],
197214
severity: DiagnosticSeverity.Warning,
198215
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ testRule('xgen-IPA-104-get-method-response-has-no-input-fields', [
131131
{
132132
code: 'xgen-IPA-104-get-method-response-has-no-input-fields',
133133
message:
134-
'The get method response object must not include output fields (writeOnly properties). Found writeOnly property at: name http://go/ipa/104',
134+
'The get method response object must not include output fields (writeOnly properties). Found writeOnly property at: name. http://go/ipa/104',
135135
path: [
136136
'paths',
137137
'/resource/{id}',
@@ -146,7 +146,7 @@ testRule('xgen-IPA-104-get-method-response-has-no-input-fields', [
146146
{
147147
code: 'xgen-IPA-104-get-method-response-has-no-input-fields',
148148
message:
149-
'The get method response object must not include output fields (writeOnly properties). Found writeOnly property at: name http://go/ipa/104',
149+
'The get method response object must not include output fields (writeOnly properties). Found writeOnly property at: name. http://go/ipa/104',
150150
path: [
151151
'paths',
152152
'/resource/{id}/singleton',

tools/spectral/ipa/__tests__/utils/schemaUtils.test.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('findPropertiesByAttribute', () => {
2525
expect(errors).toHaveLength(1);
2626
expect(errors[0]).toEqual({
2727
path: mockPath,
28-
message: `${errorMessage} Found readOnly property at: `
28+
message: `${errorMessage} Found readOnly property at one of the inline schemas.`
2929
});
3030
});
3131

@@ -50,12 +50,12 @@ describe('findPropertiesByAttribute', () => {
5050
// Testing readOnly detection
5151
let errors = findPropertiesByAttribute(schema, 'readOnly', mockPath, [], errorMessage);
5252
expect(errors).toHaveLength(1);
53-
expect(errors[0].message).toContain('Found readOnly property at: id');
53+
expect(errors[0].message).toContain('Found readOnly property at: id.');
5454

5555
// Testing writeOnly detection
5656
errors = findPropertiesByAttribute(schema, 'writeOnly', mockPath, [], errorMessage);
5757
expect(errors).toHaveLength(1);
58-
expect(errors[0].message).toContain('Found writeOnly property at: password');
58+
expect(errors[0].message).toContain('Found writeOnly property at: password.');
5959
});
6060

6161
it('detects nested properties with the specified attribute', () => {
@@ -86,12 +86,12 @@ describe('findPropertiesByAttribute', () => {
8686
// Testing deep readOnly detection
8787
let errors = findPropertiesByAttribute(schema, 'readOnly', mockPath, [], errorMessage);
8888
expect(errors).toHaveLength(1);
89-
expect(errors[0].message).toContain('Found readOnly property at: user.id');
89+
expect(errors[0].message).toContain('Found readOnly property at: user.id.');
9090

9191
// Testing deep writeOnly detection
9292
errors = findPropertiesByAttribute(schema, 'writeOnly', mockPath, [], errorMessage);
9393
expect(errors).toHaveLength(1);
94-
expect(errors[0].message).toContain('Found writeOnly property at: user.credentials.password');
94+
expect(errors[0].message).toContain('Found writeOnly property at: user.credentials.password.');
9595
});
9696

9797
it('detects properties in array items', () => {
@@ -120,12 +120,12 @@ describe('findPropertiesByAttribute', () => {
120120
// Testing readOnly in array items
121121
let errors = findPropertiesByAttribute(schema, 'readOnly', mockPath, [], errorMessage);
122122
expect(errors).toHaveLength(1);
123-
expect(errors[0].message).toContain('Found readOnly property at: items.items.id');
123+
expect(errors[0].message).toContain('Found readOnly property at: items.items.id.');
124124

125125
// Testing writeOnly in array items
126126
errors = findPropertiesByAttribute(schema, 'writeOnly', mockPath, [], errorMessage);
127127
expect(errors).toHaveLength(1);
128-
expect(errors[0].message).toContain('Found writeOnly property at: items.items.secret');
128+
expect(errors[0].message).toContain('Found writeOnly property at: items.items.secret.');
129129
});
130130

131131
it('detects properties in schema combiners', () => {
@@ -171,13 +171,13 @@ describe('findPropertiesByAttribute', () => {
171171
// Testing readOnly in combiners
172172
let errors = findPropertiesByAttribute(schema, 'readOnly', mockPath, [], errorMessage);
173173
expect(errors).toHaveLength(2);
174-
expect(errors[0].message).toContain('Found readOnly property at: allOf.0.id');
175-
expect(errors[1].message).toContain('Found readOnly property at: oneOf.1.token');
174+
expect(errors[0].message).toContain('Found readOnly property at: allOf.0.id.');
175+
expect(errors[1].message).toContain('Found readOnly property at: oneOf.1.token.');
176176

177177
// Testing writeOnly in combiners
178178
errors = findPropertiesByAttribute(schema, 'writeOnly', mockPath, [], errorMessage);
179179
expect(errors).toHaveLength(1);
180-
expect(errors[0].message).toContain('Found writeOnly property at: anyOf.0.key');
180+
expect(errors[0].message).toContain('Found writeOnly property at: anyOf.0.key.');
181181
});
182182

183183
it('correctly accumulates multiple errors', () => {
@@ -209,9 +209,9 @@ describe('findPropertiesByAttribute', () => {
209209
const errors = findPropertiesByAttribute(schema, 'readOnly', mockPath, [], errorMessage);
210210

211211
expect(errors).toHaveLength(3);
212-
expect(errors[0].message).toContain('Found readOnly property at: id');
213-
expect(errors[1].message).toContain('Found readOnly property at: nested.innerId');
214-
expect(errors[2].message).toContain('Found readOnly property at: items.items');
212+
expect(errors[0].message).toContain('Found readOnly property at: id.');
213+
expect(errors[1].message).toContain('Found readOnly property at: nested.innerId.');
214+
expect(errors[2].message).toContain('Found readOnly property at: items.items.');
215215
});
216216

217217
it('handles empty objects', () => {

tools/spectral/ipa/rulesets/functions/utils/schemaUtils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ export function findPropertiesByAttribute(schema, attributeName, path, errors =
4747
if (schema[attributeName] === true) {
4848
errors.push({
4949
path,
50-
message: `${errorMessage} Found ${attributeName} property at: ${propPath.join('.')}`,
50+
message: propPath.length > 0 ? `${errorMessage} Found ${attributeName} property at: ${propPath.join('.')}.`:
51+
`${errorMessage} Found ${attributeName} property at one of the inline schemas.`,
5152
});
5253
return errors;
5354
}

0 commit comments

Comments
 (0)