From c4153b9bb06436bc8b719c338573fe180e2cb321 Mon Sep 17 00:00:00 2001 From: shibeshduw <166374073+shibeshduw@users.noreply.github.com> Date: Wed, 25 Sep 2024 09:13:26 +0200 Subject: [PATCH] fix: Ignore charset parameter in media-types (#5022) * ignore charset * Changes from lint:fix * Update .changeset/plenty-vans-mix.md --------- Co-authored-by: cloud-sdk-js Co-authored-by: Marika Marszalkowski <868536+marikaner@users.noreply.github.com> --- .changeset/plenty-vans-mix.md | 5 +++++ packages/openapi-generator/src/parser/media-type.spec.ts | 4 +++- packages/openapi-generator/src/parser/media-type.ts | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 .changeset/plenty-vans-mix.md diff --git a/.changeset/plenty-vans-mix.md b/.changeset/plenty-vans-mix.md new file mode 100644 index 0000000000..da23b35207 --- /dev/null +++ b/.changeset/plenty-vans-mix.md @@ -0,0 +1,5 @@ +--- +'@sap-cloud-sdk/openapi-generator': minor +--- + +[Fixed Issue] Ignore charset parameter in media types given in OpenAPI specification. diff --git a/packages/openapi-generator/src/parser/media-type.spec.ts b/packages/openapi-generator/src/parser/media-type.spec.ts index 87fa005766..2f0a3f1308 100644 --- a/packages/openapi-generator/src/parser/media-type.spec.ts +++ b/packages/openapi-generator/src/parser/media-type.spec.ts @@ -19,7 +19,9 @@ describe('parseTopLevelMediaType', () => { expect( parseTopLevelMediaType( { - content: { 'application/json': { schema: { type: 'object' } } } + content: { + 'application/json;charset=utf-8': { schema: { type: 'object' } } + } }, await createTestRefs(), defaultOptions diff --git a/packages/openapi-generator/src/parser/media-type.ts b/packages/openapi-generator/src/parser/media-type.ts index 164a3665d4..37f9e4211f 100644 --- a/packages/openapi-generator/src/parser/media-type.ts +++ b/packages/openapi-generator/src/parser/media-type.ts @@ -104,7 +104,7 @@ function getMediaTypeObject( ): OpenAPIV3.MediaTypeObject | undefined { if (bodyOrResponseObject?.content) { return Object.entries(bodyOrResponseObject.content).find(([key]) => - contentType.includes(key) + contentType.includes(key.split(';')[0]) )?.[1]; } return undefined;