alibaba / pont

🌉数据服务层解决方案
MIT License
3.04k stars 251 forks source link

nestjs swagger3.0 mods为空 #390

Closed zlyyyy closed 9 months ago

zlyyyy commented 1 year ago

What happens(发生了什么)?

swagger3.0接口数据如下,生成的lock文件中mods为空,service列表也没有

{
    "openapi": "3.0.0",
    "paths": {
        "/api/getCurrentUserInfo": {
            "get": {
                "operationId": "UserController_getCurrentUserInfo",
                "summary": "获取当前用户信息",
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "schema": {}
                    }
                ],
                "responses": {
                    "200": {
                        "description": ""
                    }
                },
                "tags": [
                    "用户"
                ],
                "security": [
                    {
                        "bearer": []
                    }
                ]
            }
        }
    },
    "info": {
        "title": "接口信息",
        "description": "接口文档",
        "version": "1.0",
        "contact": {}
    },
    "tags": [],
    "servers": [],
    "components": {
        "securitySchemes": {
            "bearer": {
                "scheme": "bearer",
                "bearerFormat": "JWT",
                "type": "http"
            },
            "cookie": {
                "type": "apiKey",
                "in": "cookie",
                "name": "atom-cookie"
            }
        },
        "schemas": {
            "LoginDto": {
                "type": "object",
                "properties": {
                    "username": {
                        "type": "string",
                        "description": "用户名"
                    },
                    "password": {
                        "type": "string",
                        "description": "密码"
                    }
                },
                "required": [
                    "username",
                    "password"
                ]
            }
        }
    }
}

A clear and concise description of what the bug is(对错误的清晰而简明的描述).

Mini Showcase Repository(迷你展示库)

Provide a mini GitHub repository which can reproduce the issue(提供一个可以重现问题的小型 Github 存储库).

How To Reproduce(如何重现)

Steps to reproduce the behavior(重现行为的步骤): 1. 2.

Expected behavior(预期行为) 1. 2.

Context(上下文)

FrankCheungDev commented 9 months ago

我的做法是,要做两个处理:

  1. 自定义数据获取方法
    
    // pont-config.json

"fetchMethodPath": "./request"

// request.ts import axios from 'axios';

export default async function (url: string): Promise { return axios.get(url).then((res) => { const { tags, ...ext } = res.data; // 关键步骤,去掉tags,交给pont内部处理 return JSON.stringify(ext); }); }


2. nestjs的接口声明的tag,修改为或者增加一个英文tag

... @ApiTags('登录模块', 'Login') @Controller() export class LoginController { constructor(private loginService: LoginService, private utils: UtilService) {} ...