Swagger CodeGen 3.0.x为什么生成具有AllOf [Classname]

问题描述

我正在使用swagger代码生成器3.0.21生成C#api客户端。

生成器在/ Model中为所有引用的类创建以AllOf [Classname]开头的其他类。

为什么Swagger CodeGen生成这些类?他们的po是什么?我的分隔符也存在多个错误

生成的json的相关更改部分:

"components": {
  "schemas": {
    "MyClass": {
        "type": "object","properties": {
          "id": {
            "type": "integer","format": "int64"
          },"propertyTwo": {
            "type": "integer","propertyThree": {
            "allOf": [
              {
                "$ref": "#/components/schemas/MySecondClass"
              }
            ],"nullable": true
          },"propertyFour": {
            "allOf": [
              {
                "$ref": "#/components/schemas/MyThirdClass"
              }
            ],"propertyFive": {
            "type": "array","items": {
              "$ref": "#/components/schemas/MyFourthClass"
            },"propertySix": {
            "type": "boolean"
          }
        },"additionalProperties": false
    },}
}

MyClass的构造函数生成如下:

public MyClass(long? id = default(long?),long? propertyTwo = default(long?),propertyThree = default(),propertyFour = default(),List<MyThirdClass> propertyFive = default(List<MyFourthClass>),bool? propertySix = default(bool?))

如您所见,propertyThree和propertyFour的数据类型只是空白。

解决方法

我们遇到了同样的问题。为了生成 csharp 客户端/模型,我们实际上使用了 https://github.com/RicoSuter/NSwag/wiki/NSwagStudio,它也为您提供了很多选项并且可以正确生成模型

但是对于客户端,我们也需要一个 java 生成器,而 nswagstudio 仅支持 csharp 和 typescript。我尝试了 @NickSim 的建议,很有魅力。