3

我有一个由 Swashbuckle 从我的 Web Api 服务生成的 swagger 元数据文件。当我尝试生成 Azure API 应用程序客户端(使用 Visual Studio 2015 > 添加 > Azure API 应用程序客户端 > Swagger 元数据文件时,会引发以下错误:

Generating client code and adding to project started
Generate client code for Microsoft Azure API App with following parameters:
Microsoft Azure API App Name: Contoso.Api1, Base namespace: Automation.Http, Metadata file path: C:\Users\contoso\Desktop\swagger_current.json
[Info]AutoRest Core 0.9.7.0
[Info]Initializing code generator.
[Info]Successfully initialized CSharp Code Generator 1.0.5584.22489
[Info]Initializing modeler.
[Info]Successfully initialized Swagger Modeler 1.0.5584.22490
[Info]Parsing swagger json file.
[Info]Generating client model from swagger model.
[Info]Initializing code generator.
[Info]Successfully initialized CSharp Code Generator 1.0.5584.22489
[Fatal]Error generating syntax tree: Failure during generation of method PutItem.
Failure during serialization generation of method PutItem.
System.NotSupportedException: Contoso.Api.Types.ContosoModel - False

System.NotSupportedException: Contoso.Api.Types.ContosoModel - False
   at Hyak.SerializationGenerator.CreateSerializationMethod(ISerializationBase serializationFormat)
   at Hyak.JsonSerializationGenerator.SerializeJsonRequest[T](StatementsBuilder`1 builder, IJsonBase root)
   at Hyak.JsonSerializationFramework.Serialize[T](ISerializationBase serialization, StatementsBuilder`1& builder)
   at Hyak.CodeGeneratorExtensions.SerializationExtensions`1.Serialize(IDictionary`2 requestBodyDefinitions, Type& requestType)
   at Hyak.ClientGenerator.<>c__DisplayClass3a`1.<SerializeRequest>b__37()
   at Hyak.Ensure.ErrorContext(Action action, String context)
Exception: There was an error during code generation when trying to add a client for the Microsoft Azure API App
Generating client code and adding to project failed
Adding client for Microsoft Azure API App failed

我想我在我的模型中使用了生成器不支持的东西。我能以某种方式获得更详细的错误消息来解释问题所在吗?

4

1 回答 1

0

我遇到了同样的问题,我在 SwaggerConfig.cs 中使用/启用了“ c.UseFullTypeNameInSchemaIds ,这导致了问题:错误生成语法树+方法生成期间失败+方法序列化生成期间失败+ System.NotSupportedException的后果这是 .json 中的定义 "items": { "$ref":" 生成不正确。

于 2016-10-26T12:59:26.553 回答