bodyが無い(空オブジェクト)のときはrequestBodyを描画しないようにする

This commit is contained in:
osamu 2023-11-22 13:59:35 +09:00
parent b043aaa97c
commit 819f2a296c
1 changed files with 10 additions and 6 deletions

View File

@ -85,6 +85,8 @@ export function genOpenapiSpec(config: Config) {
schema.required = undefined; schema.required = undefined;
} }
const hasBody = (schema.type === 'object' && schema.properties && Object.keys(schema.properties).length >= 1);
const info = { const info = {
operationId: endpoint.name, operationId: endpoint.name,
summary: endpoint.name, summary: endpoint.name,
@ -101,14 +103,16 @@ export function genOpenapiSpec(config: Config) {
bearerAuth: [], bearerAuth: [],
}], }],
} : {}), } : {}),
requestBody: { ...(hasBody ? {
required: true, requestBody: {
content: { required: true,
[requestType]: { content: {
schema, [requestType]: {
schema,
},
}, },
}, },
}, } : {}),
responses: { responses: {
...(endpoint.meta.res ? { ...(endpoint.meta.res ? {
'200': { '200': {