Skip to content

Commit 29c75ff

Browse files
rule implementation fix
1 parent eed1a14 commit 29c75ff

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@ import { getResponseOfGetMethodByMediaType, isCustomMethodIdentifier } from './u
22
import { resolveObject } from './utils/componentUtils.js';
33
import { compareSchemas } from './utils/schemaUtils.js';
44
import { hasException } from './utils/exceptions.js';
5-
import {
6-
collectAdoption,
7-
collectAndReturnViolation,
8-
collectException,
9-
} from './utils/collectionUtils.js';
5+
import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js';
106

117
const RULE_NAME = 'xgen-IPA-106-create-method-request-body-is-get-method-response';
12-
const ERROR_MESSAGE = 'The request body schema properties must match the response body schema properties of the Get method.';
13-
8+
const ERROR_MESSAGE =
9+
'The request body schema properties must match the response body schema properties of the Get method.';
1410

1511
export default (input, _, { path, documentInventory }) => {
1612
const oas = documentInventory.resolved;
@@ -20,10 +16,10 @@ export default (input, _, { path, documentInventory }) => {
2016
return;
2117
}
2218

23-
const contentPerMediaType = resolveObject(oas, path);
19+
const postMethodRequestContentPerMediaType = resolveObject(oas, path);
2420

25-
if (hasException(contentPerMediaType, RULE_NAME)) {
26-
collectException(contentPerMediaType, RULE_NAME, path);
21+
if (hasException(postMethodRequestContentPerMediaType, RULE_NAME)) {
22+
collectException(postMethodRequestContentPerMediaType, RULE_NAME, path);
2723
return;
2824
}
2925

@@ -33,9 +29,14 @@ export default (input, _, { path, documentInventory }) => {
3329
return;
3430
}
3531

36-
const postMethodRequestContentPerMediaType = resolveObject(oas, path);
37-
if (compareSchemas(postMethodRequestContentPerMediaType.schema, getMethodResponseContentPerMediaType.schema)) {
32+
const inconsistentFields = compareSchemas(
33+
postMethodRequestContentPerMediaType.schema,
34+
getMethodResponseContentPerMediaType.schema
35+
);
36+
if (inconsistentFields.length === 0) {
3837
collectAdoption(path, RULE_NAME);
38+
} else {
39+
return collectAndReturnViolation(path, RULE_NAME, ERROR_MESSAGE);
3940
}
40-
return collectAndReturnViolation(path, RULE_NAME, ERROR_MESSAGE);
41+
4142
};

0 commit comments

Comments
 (0)