diff --git a/package.json b/package.json index 423bbb20..e32b5e42 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "openapi-typescript-codegen", - "version": "0.11.3", + "version": "0.11.4", "description": "Library that generates Typescript clients based on the OpenAPI specification.", "author": "Ferdi Koomen", "homepage": "https://github.com/ferdikoomen/openapi-typescript-codegen", diff --git a/src/openApi/v3/parser/getContent.ts b/src/openApi/v3/parser/getContent.ts index 7e0d58e5..ae7def03 100644 --- a/src/openApi/v3/parser/getContent.ts +++ b/src/openApi/v3/parser/getContent.ts @@ -12,6 +12,7 @@ export interface Content { const BASIC_MEDIA_TYPES = [ 'application/json-patch+json', 'application/json', + 'application/x-www-form-urlencoded', 'text/json', 'text/plain', 'multipart/form-data', diff --git a/src/openApi/v3/parser/getMediaType.ts b/src/openApi/v3/parser/getMediaType.ts deleted file mode 100644 index 273b1654..00000000 --- a/src/openApi/v3/parser/getMediaType.ts +++ /dev/null @@ -1,18 +0,0 @@ -import type { Dictionary } from '../../../utils/types'; -import type { OpenApi } from '../interfaces/OpenApi'; -import type { OpenApiMediaType } from '../interfaces/OpenApiMediaType'; - -const supportedMediaTypes = [ - 'application/json-patch+json', - 'application/json', - 'text/json', - 'text/plain', - 'multipart/form-data', - 'multipart/mixed', - 'multipart/related', - 'multipart/batch', -]; - -export function getMediaType(openApi: OpenApi, content: Dictionary): string | null { - return Object.keys(content).find(key => supportedMediaTypes.includes(key)) || null; -} diff --git a/src/openApi/v3/parser/getOperationRequestBody.ts b/src/openApi/v3/parser/getOperationRequestBody.ts index 1453adc9..8d3d5709 100644 --- a/src/openApi/v3/parser/getOperationRequestBody.ts +++ b/src/openApi/v3/parser/getOperationRequestBody.ts @@ -34,10 +34,13 @@ export function getOperationRequestBody(openApi: OpenApi, parameter: OpenApiRequ const content = getContent(openApi, parameter.content); if (content) { requestBody.mediaType = content.mediaType; - if (requestBody.mediaType === 'multipart/form-data') { - requestBody.in = 'formData'; - requestBody.name = 'formData'; - requestBody.prop = 'formData'; + switch (requestBody.mediaType) { + case 'application/x-www-form-urlencoded': + case 'multipart/form-data': + requestBody.in = 'formData'; + requestBody.name = 'formData'; + requestBody.prop = 'formData'; + break; } if (content.schema.$ref) { const model = getType(content.schema.$ref);