简体   繁体   English

Swagger 3 如果 OpenApi-Specification 中缺少类型,则生成缺少类型的属性

[英]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 objectstring来保持代码编译?

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.

相关问题 .NetStandard:缺少类型方法和属性 - .NetStandard: Missing Type Methods and Properties Swagger-Codegen C#:缺少类型为byte []的客户端成员 - Swagger-codegen c#: Missing client member of type byte[] Swashbuckle正在生成没有域类型信息的Swagger定义文件(缺少#/ definition / domain-type部分) - Swashbuckle is generating Swagger definition file without domain-type information (missing #/definition/domain-type part) 通用类型的 Json 模式 $ref 名称随 Swagger 和 OpenApi 更改 - Json schema $ref name for generic type changed with Swagger and OpenApi 单人游戏“精灵”类型缺失 - Monogame “Sprite” type missing 缺少类型或命名空间名称 - Missing type or namespace name @protocol缺少基本类型 - Base type is missing for @protocol Swagger - .NET 核心 API 中的字符串数据类型查询参数缺少必需的标记 - Swagger - required mark missing for string data type query parameter in .NET core API AutoMapper.AutoMapperMappingException:缺少类型 map 配置或不支持的映射。 Swagger 消费另一个 API - .net 6 - AutoMapper.AutoMapperMappingException: Missing type map configuration or unsupported mapping. Swagger Consuming another API - .net 6 C#字体类型丢失 - C# Font type missing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM