c# - 为什么 Swagger CodeGen 3.0.x 使用 AllOf[Classname] 生成类

标签 c# swagger swagger-codegen

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

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

为什么 Swagger CodeGen 会生成这些类?他们的豚鼠是什么?他们在我的分类中也有多个错误。

生成的json相关改动部分:

"components": {
  "schemas": {
    "MyClass": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64"
          },
          "propertyTwo": {
            "type": "integer",
            "format": "int64"
          },
          "propertyThree": {
            "allOf": [
              {
                "$ref": "#/components/schemas/MySecondClass"
              }
            ],
            "nullable": true
          },
          "propertyFour": {
            "allOf": [
              {
                "$ref": "#/components/schemas/MyThirdClass"
              }
            ],
            "nullable": true
          },
          "propertyFive": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/MyFourthClass"
            },
            "nullable": true
          },
          "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 的建议这很有魅力。

关于c# - 为什么 Swagger CodeGen 3.0.x 使用 AllOf[Classname] 生成类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64030275/

相关文章:

c# - OAuth2和MFA有什么关系

c# - 外部从内部服务器下载文档

java - 为 @ApiOperations 为 springfox swagger2 定义自定义 json 序列化器

具有相同代码的多个响应的 PHP swagger 注释

c# - 如何在asp.net c#中根据URL获取https文件

c# - 使用 Protobuf-net 将大数据文件流式传输为 IEnumerable

spring-boot - 我想将 Keycloak 与 Spring Boot 2 和 Swagger 集成

java - 使用 swagger-codegen maven 插件生成代码时删除默认实现

swagger-codegen - Swagger Codegen使用现有类

spring-cloud - 如何使用swagger-codegen-maven-plugin生成spring cloud feign客户端