标签: autorest

编译 Autorest 生成的客户端时出错

使用 Swagger OpenApi 3.0 规范自动生成客户端后,我无法编译生成的客户端。我在对象ClientDiagnosticsRawRequestUriBuilderUtf8JsonRequestContent上收到错误。

RestClient.cs

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

// <auto-generated/>

#nullable disable

using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Core.Pipeline;
using Planner.Client.Models;

namespace Planner.Client
{
    internal partial class RestClient
    {
        private Uri endpoint;
        private ClientDiagnostics _clientDiagnostics;
        private HttpPipeline _pipeline;

        /// <summary> Initializes a new instance of RestClient. </summary>
        /// <param name="clientDiagnostics"> The handler for …
Run Code Online (Sandbox Code Playgroud)

c# autorest

7
推荐指数
2
解决办法
3606
查看次数

我们应该对从 C# 中的 Microsoft.Rest.ServiceClient 派生的客户端使用单例吗?

使用从 swagger 规范(例如与 Azure 资源管理器相关联的规范)生成的 Azure .NET SDK 时,生成的库利用 Microsoft AutoRest 客户端运行时和各种“客户端”,所有这些“客户端”都继承自“ServiceClient”。

我们一直在使用 DocumentDB Client,并阅读了很多关于在 .NET 中使用本机 HttpClient 的问题。Microsoft 建议对这两个客户端使用单例模式,因为它们在内部是如何工作的,尽管使用单例模式存在众所周知的问题。在这些情况下,这是必要的。

因此,我们为这些情况制定了使用和管理单例的策略,因此我们想知道是否应该对派生自 ServiceClient 的 Azure REST 客户端使用相同的策略。如果它使用 HttpClient 就有意义了。

注意:这个问题不是寻求关于单例或客户端的一般开发人员建议的问题,而是针对与 AutoRest 客户端运行时相关的 Microsoft 开发团队基于其内部工作原理的知识的特定问题。

.net c# azure autorest

6
推荐指数
1
解决办法
2208
查看次数

如何在Visual Studio 2017中更新AutoRest

上下文 我想在Visual Studio 2017中使用"添加"/"REST API客户端..."将AutoRest生成的客户端用于webapi服务.但是,它会出现以下错误:

  • [Info] AutoRest Core 0.16.0.0
  • ...
  • [致命]生成客户端模型时出错:不支持集合格式"multi"(在参数"xxx"中).

较早版本的AutoRest(例如0.16.0)不支持"多"收集格式.所以我安装了最新版本AutoRest 0.17.3.使用Nuget.但是,当我使用"添加"/"REST API客户端..."时,它仍然使用0.16.0版本的AutoRest并给我相同的错误.视觉工作室2017似乎有内置的AutoRest版本0.16组装.

问题 如何获取最新版本的AutoRest并将其集成到Visual Studio 2017中?

asp.net-web-api swagger-2.0 autorest visual-studio-2017

6
推荐指数
1
解决办法
1364
查看次数

如何在 Microsoft.Rest.ServiceClient 中使用 Windows 身份验证

我有一个Microsoft.Rest.ServiceClient生成的autorest. 我想访问受 Windows 身份验证和基本身份验证保护的 REST API。

目标是使用 Windows 身份验证。我试过如下:

var handler = new HttpClientHandler
{
    UseDefaultCredentials = true,
};
this.InitializeHttpClient(handler);
Run Code Online (Sandbox Code Playgroud)

这不起作用,我得到:

System.Net.Http.HttpRequestException: An error occurred while sending the request. 
---> System.Net.WebException: The remote server returned an error: (401) Unauthorized. 
---> System.ComponentModel.Win32Exception: The target principal name is incorrect
Run Code Online (Sandbox Code Playgroud)

当我使用基本身份验证时,它可以工作。

this.Credentials = new BasicAuthenticationCredentials
{
    UserName = Configuration.User,
    Password = Configuration.Password
};
Run Code Online (Sandbox Code Playgroud)

这个设置ServiceClient是在构造函数中完成的

MyClient : Microsoft.Rest.ServiceClient
Run Code Online (Sandbox Code Playgroud)

我需要向客户端添加什么才能使 Windows 身份验证正常工作?

编辑:

看起来问题出在服务器端。IIS 中的设置。

客户端将按预期工作。

.net c# windows-authentication autorest

6
推荐指数
1
解决办法
1668
查看次数

服务如何将通用 JsonPatchDocument&lt;&gt; 传输到另一个服务?

我构建了一个在 Azure (ASP.Net Core 2.1) 上运行的应用程序,它涉及微服务和客户端应用程序:

客户端应用程序 (Android) --calls--> 微服务 A (网关) --forwards-> 微服务 B

在微服务B 中,我在 an 中定义了以下方法Controller

[HttpPatch]
[SwaggerOperation(OperationId = nameof(PatchEntityAsync))]
[Route(ApiConstants.Constraints.ControlId, Name = nameof(PatchEntityAsync))]
[SwaggerResponse(StatusCodes.Status204NoContent, "Result of the patch")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[Consumes(MediaTypes.Application.JsonPatch)]
public async Task PatchEntityAsync(string tenantId, Guid entityId, JsonPatchDocument<EntityModel> entityUpdates)
{
   //
}
Run Code Online (Sandbox Code Playgroud)

该方法接受 aJsonPatchDocument以应用于EntityModel。生成 swagger 并运行 autorest 后,我​​得到以下自动生成的方法:

Task<HttpOperationResponse> PatchEntityWithHttpMessagesAsync(string tenantId, System.Guid controlId, IList<Operation> entityPatches = default(IList<Operation>), Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
Run Code Online (Sandbox Code Playgroud)

这个自动生成的客户端正被微服务A …

c# swagger microservices autorest asp.net-core

6
推荐指数
0
解决办法
344
查看次数

Autorest 错误 - swagger.json' 不是有效的 OpenAPI 2.0 定义(预期为 'swagger: 2.0')

我的 api 正在使用 Swashbuckle.AspNetCore 5.0.0-rc5 运行 net core 3.0

当我在生成的 swagger.json 文件上运行 autorest 时,我得到:

swagger.json is not a valid OpenAPI 2.0 definition (expected 'swagger: 2.0')
Run Code Online (Sandbox Code Playgroud)

我的 swagger.json 文件确实说“openapi”:“3.0.1”。它曾经是 v2.0 但自从我升级到 net core 3.0 我不得不升级现在用 v3.0.1 创建 json 文件的 Swashbuckle

我运行了“choco install autorest”,所以我应该运行最新版本

如果 autorest 不支持 openapi3.0,那么肯定还有一种方法可以生成 openapi2.0 json 文件吗?

swagger autorest openapi asp.net-core-webapi

6
推荐指数
1
解决办法
2075
查看次数

服务器REST API更改后如何更新生成的AutoRest代码?

上下文

我正在编写客户端代码来访问Web API REST服务.我使用Visual Studio 2015"添加"/"REST API客户端..."使用类型化客户端类

现在服务器端API已更改,我想相应地更新生成的客户端代码.

除了删除所有生成的类的明显解决方案,然后从零开始启动Visual Studio 2015"添加"/"REST API客户端...",还有更好的方法吗?

rest asp.net-web-api swagger autorest

5
推荐指数
0
解决办法
579
查看次数

Autorest + Swagger无法正确生成ENUM

我有两个应用程序一个.在A上我使用swagger来描述API.在A我还有一些枚举属性的类的定义.我想在B上生成一个客户端API .为此,我使用Autorest.一切都很好,除了一件事 - 枚举.由于某种原因,枚举没有正确生成,一种属性(最初是枚举)是string或int的类型(取决于DescribeAllEnumsAsStrings()的使用.我在下面的例子中使用它,所以在这种情况下它是字符串) .

枚举定义由swagger生成JSON:

        "Car": {
        "properties": {
            "color": {
                "enum": [
                    "Red",
                    "Blue",
                    "Green"
                ],
                "type": "string"
            }
        },
        "type": "object"
    }
Run Code Online (Sandbox Code Playgroud)

Startup.cs中的Swagger注册

// Register the Swagger generator, defining one or more Swagger documents
        services.AddSwaggerGen(c =>
        {
            c.SwaggerDoc("v1", new Info { Title = "Car API", Version = "v1" });
            c.AddSecurityDefinition("Bearer", new ApiKeyScheme { In = "header", Description = "description", Name = "Authorization", Type = "apiKey" …
Run Code Online (Sandbox Code Playgroud)

c# swagger autorest asp.net-core

5
推荐指数
1
解决办法
3726
查看次数

Autorest 无法生成任何内容,并且没有错误

我正在github上尝试 petshop 客户端生成示例,autorest 只是退出而不会创建任何内容或引发任何错误。自动休息的表现就像我没有传递任何参数。附件是我的 powershell 执行的屏幕截图。

在此输入图像描述

azure npm swagger autorest openapi

5
推荐指数
1
解决办法
2575
查看次数

参考包括不在存储库中的源

我已经克隆了autorest.csharp的代码和它的子模块但是测试项目缺少依赖项

构建错误是

Error   CS0234  The type or namespace name 'Modeler' 
does not exist in the namespace 'AutoRest' 
(are you missing an assembly reference?)    autorest.csharp.test
Run Code Online (Sandbox Code Playgroud)

但是,解决方案文件包含以下内容

  <ItemGroup>
   <Reference Include="autorest.modeler">
      <HintPath>$(SolutionDir)\node_modules\@microsoft.azure\autorest.modeler\src\bin\netcoreapp2.0\autorest.modeler.dll</HintPath>
      <!-- <HintPath>C:\work\oneautorest\autorest.modeler\src\bin\netcoreapp2.0\autorest.modeler.dll</HintPath> -->
    </Reference>
    <ProjectReference Include="$(SolutionDir)src/autorest.csharp.csproj" />
  </ItemGroup>
Run Code Online (Sandbox Code Playgroud)

如何为缺少的依赖项包含代码(或必要时包含.dll)?

我可以看到建模者的来源是在 这个存储库但是我应该如何访问它?

autorest

5
推荐指数
1
解决办法
90
查看次数