服务如何将通用 JsonPatchDocument<> 传输到另一个服务?

Kzr*_*tof 6 c# swagger microservices autorest asp.net-core

我构建了一个在 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 使用,它有一个类似的控制器,接受 JsonPatchDocument。

问题

然而,我似乎失去了类型约束:不再宣传微服务B需要一个EntityModel类型的更新列表。

微服务A如何JsonPatchDocument<>在不操作数据的情况下将泛型传输到微服务B