From bbaa039d62e59a623355eeceff8c30e61b40e0bc Mon Sep 17 00:00:00 2001 From: Ferdi Koomen Date: Thu, 11 Nov 2021 15:33:06 +0100 Subject: [PATCH] - Updated code to work with media types like "application/json; type=collection" where type is the first part of the header --- src/openApi/v3/parser/getContent.ts | 5 ++++- test/spec/v3.json | 7 +------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/openApi/v3/parser/getContent.ts b/src/openApi/v3/parser/getContent.ts index 38a43238..84f5cc11 100644 --- a/src/openApi/v3/parser/getContent.ts +++ b/src/openApi/v3/parser/getContent.ts @@ -23,7 +23,10 @@ const BASIC_MEDIA_TYPES = [ export function getContent(openApi: OpenApi, content: Dictionary): Content | null { const basicMediaTypeWithSchema = Object.keys(content) - .filter(mediaType => BASIC_MEDIA_TYPES.includes(mediaType)) + .filter(mediaType => { + const cleanMediaType = mediaType.split(';')[0].trim(); + return BASIC_MEDIA_TYPES.includes(cleanMediaType); + }) .find(mediaType => isDefined(content[mediaType]?.schema)); if (basicMediaTypeWithSchema) { return { diff --git a/test/spec/v3.json b/test/spec/v3.json index 9e3b25eb..83c9f819 100644 --- a/test/spec/v3.json +++ b/test/spec/v3.json @@ -127,7 +127,6 @@ "nullable": true, "content": { "application/json": { - "description": "Message for default response", "schema": { "$ref": "#/components/schemas/ModelWithString" } @@ -239,7 +238,6 @@ "nullable": true, "content": { "application/json": { - "description": "Message for default response", "schema": { "$ref": "#/components/schemas/ModelWithString" } @@ -270,7 +268,6 @@ "required": true, "content": { "application/json": { - "description": "Message for default response", "schema": { "$ref": "#/components/schemas/ModelWithString" } @@ -299,7 +296,6 @@ "required": false, "content": { "application/json": { - "description": "Message for default response", "schema": { "$ref": "#/components/schemas/ModelWithString" } @@ -611,7 +607,6 @@ "default": { "content": { "application/json": { - "description": "Message for default response", "schema": { "$ref": "#/components/schemas/ModelWithString" } @@ -1303,7 +1298,7 @@ "200": { "description": "Success", "content": { - "application/json": { + "application/json; type=collection": { "schema": { "$ref": "#/components/schemas/ModelWithString" }