C# 自动测试为方法返回类型生成可为null的布尔值

C# 自动测试为方法返回类型生成可为null的布尔值,c#,visual-studio-2019,autorest,C#,Visual Studio 2019,Autorest,我对CSharp的generat RestapicClient有问题。 问题是在VisualStudioAutoRest中发现的,所以我下载了AutoRest CLI,但生成了相同的错误方法返回类型 AutoRest code generation utility [cli version: 3.0.6187; node: v12.14.1, max-memory: 8192 gb] (C) 2018 Microsoft Corporation. https://aka.ms/autorest

我对CSharp的generat RestapicClient有问题。 问题是在VisualStudioAutoRest中发现的,所以我下载了AutoRest CLI,但生成了相同的错误方法返回类型

AutoRest code generation utility [cli version: 3.0.6187; node: v12.14.1, max-memory: 8192 gb]
(C) 2018 Microsoft Corporation.
https://aka.ms/autorest


Showing All Installed Extensions

 Type       Extension Name                           Version 
 core       @autorest/core                           3.0.6274     
 core       @microsoft.azure/autorest-core           2.0.4417     
 extension  @microsoft.azure/autorest.csharp         2.3.84      
 extension  @microsoft.azure/autorest.modeler        2.3.55       
这是Swashbucke 5.6.0从WebApi生成的Swagger.json

{
    "swagger": "2.0",
    "info": {
        "version": "v1",
        "title": "Server"
    },
    "host": "localhost:5992",
    "schemes": [
        "http"
    ],
    "paths": {
        "/api/User/HasUser": {
            "post": {
                "tags": [
                    "User"
                ],
                "operationId": "User_HasUser",
                "consumes": [],
                "produces": [
                    "application/json",
                    "text/json",
                    "application/xml",
                    "text/xml"
                ],
                "parameters": [
                    {
                        "name": "username",
                        "in": "query",
                        "required": true,
                        "type": "string"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                            "schema": {
                              "x-nullable": false,
                              "type": "boolean"
                            }
                    }
                }
            }
        }
    },
    "definitions": {}
}
带参数的命令

c:\> autorest --input-file=swagger.json --output-folder=autorest --csharp --clear-output-folder
自动测试输出

namespace Api
{
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Threading;
    using System.Threading.Tasks;
    using Microsoft.Rest;

    public static partial class UserExtensions
    {
            public static bool? HasUser(this IUser operations, string username) ...    
    }
}
我期待的是“bool”而不是“bool?”


根据autorest GitHub:上的这个问题,autorest Generator版本2存在一个问题,即它们不处理基元类型的x-nullable

由于现在有了新版本(3)的生成器,这将不会被修复。你能更新自动测试并试用新的生成器吗

更新2020-05-11:

我做了一个小测试(在回答之前应该做这个测试,对此我很抱歉),对原始返回类型的x-nullable的支持似乎还没有实现。因此,使用autorest,您可能会运气不佳

我用nswag尝试了你的swagger.json:

nswag openapi2csclient /input:swagger.json /classname:UserApiClient /namespace:UserApi /output:UserApiClient.cs
并生成一个返回类型正确的方法:

public System.Threading.Tasks.Task<bool> HasUserAsync(string username)
public System.Threading.Tasks.Task HasUserAsync(字符串用户名)

这是否回答了您的问题?你什么都没回答,这只是我问的另一个问题的链接,你也没回答。你能说得更具体些吗?我用v3开关尝试了最新的自动测试
autorest--input file=swagger.json--output folder=autorest--csharp--clear output folder--v3
,但它不起作用。你的回答是正确的。也许我错过了你的回答。您的答案是正确的,并被标记为正确答案,并被投票表决。很抱歉错过了赏金。@Mertuarez,没问题。奖金和积分固然不错,但重要的是帮助他人:-)。不过,autorest的落后实在是太糟糕了。我们以前经常使用autorest,但由于autorest在功能上落后,所以我们不再使用它(并转移到nswag)。
public System.Threading.Tasks.Task<bool> HasUserAsync(string username)