Skip to content

Commit 0a65b64

Browse files
CLOUDP-304938: Add error for inline get schema
1 parent be555c1 commit 0a65b64

File tree

2 files changed

+59
-7
lines changed

2 files changed

+59
-7
lines changed

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,37 @@ testRule('xgen-IPA-105-list-method-response-is-get-method-response', [
360360
},
361361
},
362362
},
363+
// Get without schema ref
364+
'/resourceThree': {
365+
get: {
366+
responses: {
367+
200: {
368+
content: {
369+
'application/vnd.atlas.2024-01-05+json': {
370+
schema: {
371+
$ref: '#/components/schemas/PaginatedResourceSchema',
372+
},
373+
},
374+
},
375+
},
376+
},
377+
},
378+
},
379+
'/resourceThree/{id}': {
380+
get: {
381+
responses: {
382+
200: {
383+
content: {
384+
'application/vnd.atlas.2024-01-05+json': {
385+
schema: {
386+
type: 'object',
387+
},
388+
},
389+
},
390+
},
391+
},
392+
},
393+
},
363394
},
364395
components: componentSchemas,
365396
},
@@ -393,6 +424,21 @@ testRule('xgen-IPA-105-list-method-response-is-get-method-response', [
393424
path: ['paths', '/resourceTwo', 'get', 'responses', '200', 'content', 'application/vnd.atlas.2024-01-05+json'],
394425
severity: DiagnosticSeverity.Warning,
395426
},
427+
{
428+
code: 'xgen-IPA-105-list-method-response-is-get-method-response',
429+
message:
430+
'Could not validate that the List method returns the same resource object as the Get method. The Get method does not have a schema reference. http://go/ipa/105',
431+
path: [
432+
'paths',
433+
'/resourceThree',
434+
'get',
435+
'responses',
436+
'200',
437+
'content',
438+
'application/vnd.atlas.2024-01-05+json',
439+
],
440+
severity: DiagnosticSeverity.Warning,
441+
},
396442
],
397443
},
398444
{

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@ import {
1111
collectException,
1212
handleInternalError,
1313
} from './utils/collectionUtils.js';
14-
import {
15-
getResponseOfListMethodByMediaType,
16-
getSchemaRef,
17-
getSchemaNameFromRef,
18-
getResponseOfGetMethodByMediaType,
19-
} from './utils/methodUtils.js';
14+
import { getSchemaRef, getSchemaNameFromRef, getResponseOfGetMethodByMediaType } from './utils/methodUtils.js';
2015
import { schemaIsPaginated } from './utils/schemaUtils.js';
2116

2217
const RULE_NAME = 'xgen-IPA-105-list-method-response-is-get-method-response';
@@ -39,7 +34,8 @@ export default (input, _, { path, documentInventory }) => {
3934
}
4035

4136
// Ignore if the List method does not have a response schema
42-
const listMethodResponse = getResponseOfListMethodByMediaType(mediaType, resourcePath, oas);
37+
const listMethodResponse = oas.paths[resourcePath].get.responses['200'].content[mediaType];
38+
4339
if (!listMethodResponse || !listMethodResponse.schema) {
4440
return;
4541
}
@@ -98,6 +94,16 @@ function checkViolationsAndReturnErrors(path, listMethodResultItems, getMethodRe
9894
const listMethodSchemaRef = getSchemaRef(listMethodResultItems);
9995
const getMethodSchemaRef = getSchemaRef(getMethodResponseContent.schema);
10096

97+
// Error if the Get method does not have a schema ref
98+
if (!getMethodSchemaRef) {
99+
return [
100+
{
101+
path,
102+
message: `Could not validate that the List method returns the same resource object as the Get method. The Get method does not have a schema reference.`,
103+
},
104+
];
105+
}
106+
101107
// Error if the get method resource is not the same as the list method resource
102108
if (getMethodSchemaRef !== listMethodSchemaRef) {
103109
return [{ path, message: ERROR_MESSAGE }];

0 commit comments

Comments
 (0)