From 46ec20de524173fe396315b86194a1713feeb207 Mon Sep 17 00:00:00 2001 From: Kyun Wong <56475308+7kyun@users.noreply.github.com> Date: Thu, 19 Sep 2024 02:49:47 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20swagger=E7=BB=84=E4=BB=B6=E4=B8=AD?= =?UTF-8?q?=EF=BC=8CApiResponse=20=E7=9A=84=E5=88=B6=E5=AE=9A=20schema=20?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E7=9A=84=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/swagger/src/swaggerExplorer.ts | 30 ++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/packages/swagger/src/swaggerExplorer.ts b/packages/swagger/src/swaggerExplorer.ts index 717db36b388..ec1baff9990 100644 --- a/packages/swagger/src/swaggerExplorer.ts +++ b/packages/swagger/src/swaggerExplorer.ts @@ -643,7 +643,35 @@ export class SwaggerExplorer { for (const k of keys) { // 这里是引用,赋值可以直接更改 const tt = resp[k]; - if (tt.type) { + + /** + * 针对直接配置了scheme的写法 适用于统一的响应格式的情况 + * + * 例如以下例子,只需要配置data的类型即可 + * ApiOkResponse({ + * description: '请求成功描述', + * schema: { + * title: `响应数据`, + * allOf: [ + * { + * $ref: getSchemaPath(ResponsOkDto), + * }, + * { + * properties: { + * data: Data, + * }, + * }, + * ], + * }, + * }) + */ + if (tt.schema) { + tt.content = { + 'application/json': { + schema: tt.schema + } + } + } else if (tt.type) { if (Types.isClass(tt.type)) { this.parseClzz(tt.type);