Skip to content

Commit 51d0efd

Browse files
dpopp07padamstx
authored andcommitted
fix(pagination-utils): recognize all json mime types
The old code was inflexible with respect to content types other than 'application/json'. This commit adjusts the logic to use our utility for recognizing json mime types. Signed-off-by: Dustin Popp <[email protected]>
1 parent df8f213 commit 51d0efd

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

packages/ruleset/src/utils/pagination-utils.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
const { isArraySchema } = require('@ibm-cloud/openapi-ruleset-utilities');
66
const mergeAllOfSchemaProperties = require('./merge-allof-schema-properties');
7+
const { isJsonMimeType } = require('./mimetype-utils');
78

89
/**
910
* Looks for a query parameter called "offset" and returns the
@@ -80,7 +81,19 @@ function getResponseSchema(response) {
8081

8182
// Find the json content of the response.
8283
const content = response.content;
83-
const jsonResponse = content && content['application/json'];
84+
if (!content) {
85+
return;
86+
}
87+
88+
const jsonMimeType = Object.keys(content).find(mimeType =>
89+
isJsonMimeType(mimeType)
90+
);
91+
92+
if (!jsonMimeType) {
93+
return;
94+
}
95+
96+
const jsonResponse = content[jsonMimeType];
8497

8598
if (!jsonResponse || !jsonResponse.schema) {
8699
return;

packages/ruleset/test/utils/pagination-utils.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ describe('Pagination utility functions', () => {
129129
const schema = { type: 'object' };
130130
const response = {
131131
content: {
132-
'application/json': {
132+
'application/json; charset=utf-8': {
133133
schema,
134134
},
135135
},

0 commit comments

Comments
 (0)