ant-design / ant-design-pro

👨🏻‍💻👩🏻‍💻 Use Ant Design like a Pro!
https://pro.ant.design
MIT License
36.34k stars 8.14k forks source link

🧐[问题 | question] 如何使用OpenAPI生成代码呢? #11181

Open fanhualei opened 6 months ago

fanhualei commented 6 months ago

🧐 问题描述 | Problem description

按照官方文档的做了,但是报错。

fatal - AssertionError [ERR_ASSERTION]: Invalid config keys: model, initialState, layout, moment2dayjs, locale, antd, request, access
    at Config.validateConfig (/home/fanhl/08-web/test/pro2024/aifarm/node_modules/@umijs/core/dist/config/config.js:209:31)
    at Config.getConfig (/home/fanhl/08-web/test/pro2024/aifarm/node_modules/@umijs/core/dist/config/config.js:67:12)
    at Service.resolveConfig (/home/fanhl/08-web/test/pro2024/aifarm/node_modules/@umijs/core/dist/service/service.js:352:55)
    at Service.run (/home/fanhl/08-web/test/pro2024/aifarm/node_modules/@umijs/core/dist/service/service.js:276:42)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Service.run2 (/home/fanhl/08-web/test/pro2024/aifarm/node_modules/umi/dist/service/service.js:65:12)
    at async Object.run (/home/fanhl/08-web/test/pro2024/aifarm/node_modules/umi/dist/cli/cli.js:56:7) {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: false,
  expected: true,
  operator: '=='
}

我的openAPI文件如下,是用的apifox到处的文件,是不是文件格式有问题?

{
    "info": {
        "title": "个人项目",
        "description": "",
        "version": "1.0.0"
    },
    "tags": [],
    "paths": {
        "/getStudent": {
            "get": {
                "summary": "得到学生信息",
                "deprecated": false,
                "description": "",
                "tags": [],
                "parameters": [
                    {
                        "name": "studentId",
                        "in": "query",
                        "description": "",
                        "required": false,
                        "type": "number"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "success": {
                                    "type": "boolean",
                                    "title": "是否成功"
                                },
                                "data": {
                                    "type": "object",
                                    "properties": {
                                        "sutdentId": {
                                            "type": "number",
                                            "title": "学生编号"
                                        },
                                        "studentName": {
                                            "type": "string",
                                            "title": "姓名"
                                        },
                                        "age": {
                                            "type": "number",
                                            "title": "年龄"
                                        },
                                        "address": {
                                            "type": "string",
                                            "title": "住址"
                                        }
                                    },
                                    "x-apifox-orders": [
                                        "sutdentId",
                                        "studentName",
                                        "age",
                                        "address"
                                    ],
                                    "required": [
                                        "sutdentId",
                                        "studentName",
                                        "age",
                                        "address"
                                    ],
                                    "title": "学生信息",
                                    "x-apifox-ignore-properties": []
                                }
                            },
                            "x-apifox-orders": [
                                "success",
                                "data"
                            ],
                            "required": [
                                "success",
                                "data"
                            ],
                            "x-apifox-ignore-properties": []
                        }
                    }
                },
                "security": [],
                "x-apifox-folder": "",
                "x-apifox-status": "developing",
                "x-run-in-apifox": "https://apifox.com/web/project/4147484/apis/api-154765495-run",
                "produces": [
                    "application/json"
                ]
            }
        }
    },
    "swagger": "2.0",
    "definitions": {},
    "securityDefinitions": {},
    "x-components": {}
}
Edisonchow119 commented 5 months ago

你可以尝试把后端给你的接口文档(json格式)添加到 congig/config.ts下面的路径中, 再运行openapi脚本

openAPI: [{
    schemaPath: '接口文档',
}]
njflove commented 4 months ago

有解决办法吗,我也是这个问题,执行umi openapi包上面的错

huyiqiu commented 3 weeks ago

我也遇到了这个问题,使用max openapi替换umi openapi

image

然后运行 npm run openapi,就可以生成代码了 可能是ant design pro默认使用umi max,详见文档:https://umijs.org/docs/max/introduce#:~:text=%E5%9C%A8%20Umi%20Max%20%E9%A1%B9%E7%9B%AE%E4%B8%AD%E5%91%BD%E4%BB%A4%E8%A1%8C%E8%AF%B7%E4%BD%BF%E7%94%A8%20max%7B%3Abash%7D%EF%BC%8C%E8%80%8C%E4%B8%8D%E6%98%AF%E5%8E%9F%E6%9D%A5%E7%9A%84%20umi%7B%3Abash%7D%EF%BC%8C%E7%A4%BA%E4%BE%8B%E5%A6%82%E4%B8%8B