Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Swagger CodeGen 3.0.x generates classes with AllOf[Classname]

I'm using swagger codegen 3.0.21 for generating a C# api client.

The generators creates for all referenced classes additional classes in /Model beginning with AllOf[Classname].

Why does Swagger CodeGen generate these classes? What is their porpuse? They also have multiple errors with my sepcification.

Relevant changed part of the generated 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
    },
  }
}

The constructor for MyClass is generated as following:

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

As you can see the datatypes for propertyThree and propertyFour are just empty spaces.

like image 401
RumelDilDumpel Avatar asked May 28 '26 14:05

RumelDilDumpel


1 Answers

We ran into the same issue. For generating a csharp client/models we actually use https://github.com/RicoSuter/NSwag/wiki/NSwagStudio which also provide you a lot of options and does generate the models properly

However for a client we needed a java generator as well and nswagstudio only supports csharp and typescript. I tried the suggestion of @NickSim that worked as a charm.

like image 200
Maarten Kieft Avatar answered May 31 '26 05:05

Maarten Kieft



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!