[英]Swagger 3 generates Properties with missing type if type is missing in OpenApi-Specification
I try to generate c# code out of an openApi specification which is missing the type element on some properties with swagger 3.我尝试根据 openApi 规范生成 c# 代码,该规范缺少 swagger 3 的某些属性上的类型元素。
The properties with missing type are generated in code also without type , which is an compiler error.缺少类型的属性在代码中生成也没有type ,这是编译器错误。
As far as I understand type is not mandatory in openApi spec, but shouldn't be there some fallback to csharps object
or string
to keep the code compiling?据我了解,openApi 规范中的类型不是强制性的,但不应该有一些回退到 csharp object
或string
来保持代码编译?
Is there any swagger option to force this behavior or has anyone some other idea how to solve this?是否有任何 swagger 选项可以强制执行此行为,或者有其他想法如何解决此问题?
Regards问候
To answer it myself, I now use NSwag (I have to run OpenApi Generator before I can perform Nswag) with Visual Studio 2019 REST API Client Code Generator .为了自己回答这个问题,我现在使用 NSwag(我必须先运行 OpenApi Generator 才能执行 Nswag)和Visual Studio 2019 REST API Client Code Generator 。
Output is more leightweight, as it generates all code into one file. Output 更轻巧,因为它将所有代码生成到一个文件中。 The types like body-types are in my case not always properly named (rather body0, body1,...) which is no problem, as I have to convert into my own interface anyway.在我的情况下,像 body-types 这样的类型并不总是正确命名(而是 body0,body1,...),这没问题,因为无论如何我都必须转换为我自己的接口。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.