From d25a969364c984b253bc49455b3c1f17252f07d1 Mon Sep 17 00:00:00 2001 From: Gerson Goulart Date: Mon, 29 Jan 2024 15:54:21 -0300 Subject: [PATCH] In the OpenAPI v3 spec, the `requestBody` does not have a name. By default, it will be passed into the generated function as `requestBody`. Accept the commonly used `x-body-name` property in the operation schema to override this name. #2011 --- src/openApi/v3/interfaces/OpenApiRequestBody.d.ts | 1 + src/openApi/v3/parser/getOperationRequestBody.ts | 4 ++-- src/utils/writeClient.ts | 1 - 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/openApi/v3/interfaces/OpenApiRequestBody.d.ts b/src/openApi/v3/interfaces/OpenApiRequestBody.d.ts index 1a687b8b9..5fa152753 100644 --- a/src/openApi/v3/interfaces/OpenApiRequestBody.d.ts +++ b/src/openApi/v3/interfaces/OpenApiRequestBody.d.ts @@ -10,4 +10,5 @@ export interface OpenApiRequestBody extends OpenApiReference { content: Dictionary; required?: boolean; nullable?: boolean; + 'x-body-name'?: string; } diff --git a/src/openApi/v3/parser/getOperationRequestBody.ts b/src/openApi/v3/parser/getOperationRequestBody.ts index 9f9cca241..b27ab1284 100644 --- a/src/openApi/v3/parser/getOperationRequestBody.ts +++ b/src/openApi/v3/parser/getOperationRequestBody.ts @@ -10,8 +10,8 @@ export const getOperationRequestBody = (openApi: OpenApi, body: OpenApiRequestBo const requestBody: OperationParameter = { in: 'body', export: 'interface', - prop: 'requestBody', - name: 'requestBody', + prop: body['x-body-name'] ?? 'requestBody', + name: body['x-body-name'] ?? 'requestBody', type: 'any', base: 'any', template: null, diff --git a/src/utils/writeClient.ts b/src/utils/writeClient.ts index cea2f3d88..1a202440f 100644 --- a/src/utils/writeClient.ts +++ b/src/utils/writeClient.ts @@ -26,7 +26,6 @@ import { writeClientServices } from './writeClientServices'; * @param exportServices Generate services * @param exportModels Generate models * @param exportSchemas Generate schemas - * @param exportSchemas Generate schemas * @param indent Indentation options (4, 2 or tab) * @param postfixServices Service name postfix * @param postfixModels Model name postfix