ant-design/ant-design-pro

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

fanhualei opened this issue · 2 comments

🧐 问题描述 | 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": {}
}

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

openAPI: [{
    schemaPath: '接口文档',
}]

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