Skip to content

Commit

Permalink
bodyが無い(空オブジェクト)のときはrequestBodyを描画しないようにする
Browse files Browse the repository at this point in the history
  • Loading branch information
samunohito committed Nov 22, 2023
1 parent b043aaa commit 819f2a2
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions packages/backend/src/server/api/openapi/gen-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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': {
Expand Down

0 comments on commit 819f2a2

Please sign in to comment.