Skip to content

Commit

Permalink
fix(api): allow overriding request body name with x-body-name key
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlubos committed Feb 4, 2024
1 parent 80f0dbf commit d9daebd
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/openApi/v3/interfaces/OpenApiRequestBody.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import type { OpenApiReference } from './OpenApiReference';
* https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#requestBodyObject
*/
export interface OpenApiRequestBody extends OpenApiReference {
description?: string;
'x-body-name'?: string;
content: Dictionary<OpenApiMediaType>;
required?: boolean;
description?: string;
nullable?: boolean;
required?: boolean;
}
4 changes: 2 additions & 2 deletions src/openApi/v3/parser/getOperationRequestBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/utils/writeClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,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
Expand Down
6 changes: 3 additions & 3 deletions test/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7583,20 +7583,20 @@ import { request as __request } from '../core/request';
export class RequestBodyService {
/**
* @param parameter This is a reusable parameter
* @param requestBody A reusable request body
* @param foo A reusable request body
* @throws ApiError
*/
public static postApiRequestBody(
parameter?: string,
requestBody?: ModelWithString,
foo?: ModelWithString,
): CancelablePromise<void> {
return __request(OpenAPI, {
method: 'POST',
url: '/api/v{api-version}/requestBody/',
query: {
'parameter': parameter,
},
body: requestBody,
body: foo,
mediaType: 'application/json',
});
}
Expand Down
1 change: 1 addition & 0 deletions test/spec/v3.json
Original file line number Diff line number Diff line change
Expand Up @@ -1493,6 +1493,7 @@
"components": {
"requestBodies": {
"SimpleRequestBody": {
"x-body-name": "foo",
"description": "A reusable request body",
"required": false,
"content": {
Expand Down

0 comments on commit d9daebd

Please sign in to comment.