Skip to content

Commit 18f9ffd

Browse files
CLOUDP-304938: Error for create is get rule missing get schema
1 parent 77cbbf7 commit 18f9ffd

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,31 @@ testRule('xgen-IPA-106-create-method-request-body-is-get-method-response', [
318318
},
319319
},
320320
},
321+
// Missing schema for Get method
322+
'/resourceFour': {
323+
post: {
324+
requestBody: {
325+
content: {
326+
'application/vnd.atlas.2023-01-01+json': {
327+
schema: {
328+
$ref: '#/components/schemas/SchemaOne',
329+
},
330+
},
331+
},
332+
},
333+
},
334+
},
335+
'/resourceFour/{id}': {
336+
get: {
337+
responses: {
338+
200: {
339+
content: {
340+
'application/vnd.atlas.2023-01-01+json': {},
341+
},
342+
},
343+
},
344+
},
345+
},
321346
'/resourceCircular': {
322347
post: {
323348
requestBody: {
@@ -389,6 +414,13 @@ testRule('xgen-IPA-106-create-method-request-body-is-get-method-response', [
389414
path: ['paths', '/resourceThree', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'],
390415
severity: DiagnosticSeverity.Warning,
391416
},
417+
{
418+
code: 'xgen-IPA-106-create-method-request-body-is-get-method-response',
419+
message:
420+
'Could not validate that the Create request body schema matches the response schema of the Get method. The Get method does not have a schema. http://go/ipa/106',
421+
path: ['paths', '/resourceFour', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'],
422+
severity: DiagnosticSeverity.Warning,
423+
},
392424
{
393425
code: 'xgen-IPA-106-create-method-request-body-is-get-method-response',
394426
message:

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default (input, opts, { path, documentInventory }) => {
2626
}
2727

2828
const getMethodResponseContentPerMediaType = getResponseOfGetMethodByMediaType(mediaType, resourcePath, oas);
29-
if (!getMethodResponseContentPerMediaType || !getMethodResponseContentPerMediaType.schema) {
29+
if (!getMethodResponseContentPerMediaType) {
3030
return;
3131
}
3232

@@ -62,14 +62,22 @@ function checkViolationsAndReturnErrors(
6262
const errors = [];
6363

6464
const ignoredValues = opts?.ignoredValues || [];
65+
if (!getMethodResponseContentPerMediaType.schema) {
66+
return [
67+
{
68+
path,
69+
message: `Could not validate that the Create request body schema matches the response schema of the Get method. The Get method does not have a schema.`,
70+
},
71+
];
72+
}
6573
if (
6674
!isDeepEqual(
6775
omitDeep(postMethodRequestContentPerMediaType.schema, ...ignoredValues),
6876
omitDeep(getMethodResponseContentPerMediaType.schema, ...ignoredValues)
6977
)
7078
) {
7179
errors.push({
72-
path: path,
80+
path,
7381
message: ERROR_MESSAGE,
7482
});
7583
}

0 commit comments

Comments
 (0)