我对generat RestApiClient for CSharp有问题。在Visual中发现了问题,所以我下载了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 这是斯瓦什布克5.6.0从Swagger.json生成的WebApi
{
"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-folderAutoRest输出
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?”
public static bool HasUser(this IUser operations, string username) ... 发布于 2020-05-08 09:04:02
根据autorest GitHub:不能用于响应原语的X-空上的这个问题,autorest生成器version 2存在一个问题,它们不能处理基元类型的x-空。
由于现在有一个新的版本(3)的发电机,这将不会被修复。你能更新自动休息并尝试使用新的发电机吗?
更新2020-05-11:
我做了一个小测试(在回答之前应该这样做,很抱歉),并且对基元返回类型上的x-空的支持似乎还没有实现。所以有了自动休息,你可能就倒霉了。
我在nswag上试用了你的swagger.json:
nswag openapi2csclient /input:swagger.json /classname:UserApiClient /namespace:UserApi /output:UserApiClient.cs并生成一个具有正确返回类型的方法:
public System.Threading.Tasks.Task<bool> HasUserAsync(string username)https://stackoverflow.com/questions/61222623
复制相似问题