Skip to content

Commit 1609a16

Browse files
CLOUDP-305831: Fix IPA validation failed on OAS release
1 parent 698e772 commit 1609a16

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
lines changed

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ const componentSchemas = {
99
Schema: {
1010
type: 'object',
1111
},
12+
BadRequest: {
13+
content: {
14+
'application/json': {
15+
schema: {
16+
type: 'string',
17+
},
18+
},
19+
},
20+
},
1221
},
1322
};
1423

@@ -42,6 +51,9 @@ testRule('xgen-IPA-104-get-method-returns-response-suffixed-object', [
4251
},
4352
},
4453
},
54+
401: {
55+
$ref: '#/components/schemas/BadRequest',
56+
},
4557
400: {
4658
content: {
4759
'application/vnd.atlas.2023-01-01+json': {
@@ -140,7 +152,7 @@ testRule('xgen-IPA-104-get-method-returns-response-suffixed-object', [
140152
errors: [
141153
{
142154
code: 'xgen-IPA-104-get-method-returns-response-suffixed-object',
143-
message: 'The request schema must reference a schema with a Response suffix. http://go/ipa/104',
155+
message: 'The response body schema must reference a schema with a Response suffix. http://go/ipa/104',
144156
path: [
145157
'paths',
146158
'/resource/{id}',
@@ -154,7 +166,7 @@ testRule('xgen-IPA-104-get-method-returns-response-suffixed-object', [
154166
},
155167
{
156168
code: 'xgen-IPA-104-get-method-returns-response-suffixed-object',
157-
message: 'The request schema must reference a schema with a Response suffix. http://go/ipa/104',
169+
message: 'The response body schema must reference a schema with a Response suffix. http://go/ipa/104',
158170
path: [
159171
'paths',
160172
'/resource/{id}',
@@ -168,7 +180,7 @@ testRule('xgen-IPA-104-get-method-returns-response-suffixed-object', [
168180
},
169181
{
170182
code: 'xgen-IPA-104-get-method-returns-response-suffixed-object',
171-
message: 'The request schema must reference a schema with a Response suffix. http://go/ipa/104',
183+
message: 'The response body schema must reference a schema with a Response suffix. http://go/ipa/104',
172184
path: [
173185
'paths',
174186
'/resource/{id}',
@@ -182,7 +194,7 @@ testRule('xgen-IPA-104-get-method-returns-response-suffixed-object', [
182194
},
183195
{
184196
code: 'xgen-IPA-104-get-method-returns-response-suffixed-object',
185-
message: 'The request schema must reference a schema with a Response suffix. http://go/ipa/104',
197+
message: 'The response body schema must reference a schema with a Response suffix. http://go/ipa/104',
186198
path: [
187199
'paths',
188200
'/resource/{id}/singleton',

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ export default (input, _, { path }) => {
3131

3232
function checkViolationsAndReturnErrors(input, path) {
3333
try {
34-
console.log(input);
3534
const responses = input.responses;
36-
console.log(responses);
3735
// If there is no 204 response, return a violation
3836
if (!responses || !responses['204']) {
3937
return [{ path, message: ERROR_MESSAGE }];

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ export default (input, _, { path, documentInventory }) => {
1919
const contentPerMediaType = resolveObject(oas, path);
2020

2121
if (
22-
!contentPerMediaType.schema ||
2322
!responseCode.startsWith('2') ||
23+
!contentPerMediaType ||
24+
!contentPerMediaType.schema ||
2425
!input.endsWith('json') ||
2526
(!isSingleResourceIdentifier(resourcePath) &&
2627
!(isResourceCollectionIdentifier(resourcePath) && isSingletonResource(resourcePaths)))

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
import { getSchemaRef } from './utils/methodUtils.js';
1616

1717
const RULE_NAME = 'xgen-IPA-104-get-method-returns-response-suffixed-object';
18-
const ERROR_MESSAGE_SCHEMA_NAME = 'The request schema must reference a schema with a Response suffix.';
18+
const ERROR_MESSAGE_SCHEMA_NAME = 'The response body schema must reference a schema with a Response suffix.';
1919
const ERROR_MESSAGE_SCHEMA_REF = 'The response body schema is defined inline and must reference a predefined schema.';
2020

2121
export default (input, _, { path, documentInventory }) => {
@@ -26,8 +26,9 @@ export default (input, _, { path, documentInventory }) => {
2626
const contentPerMediaType = resolveObject(oas, path);
2727

2828
if (
29-
!contentPerMediaType.schema ||
3029
!responseCode.startsWith('2') ||
30+
!contentPerMediaType ||
31+
!contentPerMediaType.schema ||
3132
!input.endsWith('json') ||
3233
(!isSingleResourceIdentifier(resourcePath) &&
3334
!(isResourceCollectionIdentifier(resourcePath) && isSingletonResource(resourcePaths)))

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ export default (input, _, { path, documentInventory }) => {
3131
const isSingleton = isResourceCollectionIdentifier(resourcePath) && isSingletonResource(resourcePaths);
3232

3333
if (
34-
!contentPerMediaType.schema ||
3534
!responseCode.startsWith('2') ||
35+
!contentPerMediaType ||
36+
!contentPerMediaType.schema ||
3637
!input.endsWith('json') ||
3738
(!isSingleResource && !isSingleton)
3839
) {

0 commit comments

Comments
 (0)