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