我正在使用 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/