Skip to content

Commit bbaa039

Browse files
committed
- Updated code to work with media types like "application/json; type=collection" where type is the first part of the header
1 parent f083ffb commit bbaa039

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/openApi/v3/parser/getContent.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ const BASIC_MEDIA_TYPES = [
2323

2424
export function getContent(openApi: OpenApi, content: Dictionary<OpenApiMediaType>): Content | null {
2525
const basicMediaTypeWithSchema = Object.keys(content)
26-
.filter(mediaType => BASIC_MEDIA_TYPES.includes(mediaType))
26+
.filter(mediaType => {
27+
const cleanMediaType = mediaType.split(';')[0].trim();
28+
return BASIC_MEDIA_TYPES.includes(cleanMediaType);
29+
})
2730
.find(mediaType => isDefined(content[mediaType]?.schema));
2831
if (basicMediaTypeWithSchema) {
2932
return {

test/spec/v3.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@
127127
"nullable": true,
128128
"content": {
129129
"application/json": {
130-
"description": "Message for default response",
131130
"schema": {
132131
"$ref": "#/components/schemas/ModelWithString"
133132
}
@@ -239,7 +238,6 @@
239238
"nullable": true,
240239
"content": {
241240
"application/json": {
242-
"description": "Message for default response",
243241
"schema": {
244242
"$ref": "#/components/schemas/ModelWithString"
245243
}
@@ -270,7 +268,6 @@
270268
"required": true,
271269
"content": {
272270
"application/json": {
273-
"description": "Message for default response",
274271
"schema": {
275272
"$ref": "#/components/schemas/ModelWithString"
276273
}
@@ -299,7 +296,6 @@
299296
"required": false,
300297
"content": {
301298
"application/json": {
302-
"description": "Message for default response",
303299
"schema": {
304300
"$ref": "#/components/schemas/ModelWithString"
305301
}
@@ -611,7 +607,6 @@
611607
"default": {
612608
"content": {
613609
"application/json": {
614-
"description": "Message for default response",
615610
"schema": {
616611
"$ref": "#/components/schemas/ModelWithString"
617612
}
@@ -1303,7 +1298,7 @@
13031298
"200": {
13041299
"description": "Success",
13051300
"content": {
1306-
"application/json": {
1301+
"application/json; type=collection": {
13071302
"schema": {
13081303
"$ref": "#/components/schemas/ModelWithString"
13091304
}

0 commit comments

Comments
 (0)