umijs / plugins

🍣 The one-stop shop for official Umi plugins and presets.
349 stars 238 forks source link

[plugin-openapi] 生成的实体,不支持嵌套类型 #859

Open crashsol opened 2 years ago

crashsol commented 2 years ago

  "components": {
    "schemas": {
      "ComBaseWell": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "nullable": true
          },
          "name": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "Test": {
        "type": "object",
        "properties": {
          "comBaseWell": {
            "$ref": "#/components/schemas/ComBaseWell"
          },
          "userDto": {
            "$ref": "#/components/schemas/UserDto"
          }
        },
        "additionalProperties": false
      },
      "UserDto": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "nullable": true
          },
          "name": {
            "type": "string",
            "nullable": true
          },
          "age": {
            "type": "integer",
            "format": "int32"
          },
          "sex": {
            "type": "boolean"
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "nullable": true
          }
        },
        "additionalProperties": false
      },

    }
  }
}

生成的types.d Test 没有下级内容

declare namespace API {
  type ComBaseWell = {
    id?: string;
    name?: string;
  };
  type Test = ComBaseWell;

  type UserDto = {
    id?: string;
    name?: string;
    age?: number;
    sex?: boolean;
    tags?: string[];
  };

  type WeatherForecast = {
    date?: string;
    temperatureC?: number;
    temperatureF?: number;
    summary?: string;
  };
}

正确的应该是 type Test = { comBaseWell:ComBaseWell , userDto:UserDto }

yangxyo commented 2 years ago

我也遇到了同样的问题 "@umijs/openapi": "^1.3.0", "@umijs/plugin-openapi": "^1.3.0",

ghost commented 2 years ago
  1. 将本地的版本 yarn remove 再 yarn add 最新版也出现这种情况 @umijs/openapi 实际版本都是 1.3.2 应该是包的依赖升级导致

  2. 当代码里有 下面代码会报错

    "Map«string,List«***»»": {
      "type": "object",
      "additionalProperties": { "$ref": "#/definitions/List" }
    },

    找到的原因就是definitions/list does not exist 需要删除"$ref": "#/definitions/List"才可以生成 希望能修复

tankpanv commented 2 years ago

"additionalProperties": { "$ref": "#/definitions/List" }

问一下,这个问题解决了吗,我也遇到了这个问题

weitangli commented 2 years ago

新版本才出现的问题,可以回退到旧版本上使用

weitangli commented 2 years ago

例如:

{
    "devDependencies":{
        // 省略其它依赖
        "@umijs/openapi": "^1.3.0",
        "@umijs/plugin-openapi": "^1.3.0"
    },
    "resolutions":{
        "@umijs/openapi":"1.4.4"
    }
}