我创建了一个自定义readonly
struct
来定义我称之为的不可变值类型TenantId
:
[DebuggerDisplay("ID={m_internalId.ToString()}")]
[JsonConverter(typeof(TenantIdJsonConverter))]
public readonly struct TenantId : IEquatable<TenantId>
{
private readonly Guid m_internalId;
public static TenantId New => new(Guid.NewGuid());
private TenantId(Guid id)
{
m_internalId = id;
}
public TenantId(TenantId otherTenantId)
{
m_internalId = otherTenantId.m_internalId;
}
...
}
我还定义了一个名为的合同PurchaseContract
,它是 HTTP 响应的一部分:
[JsonObject(MemberSerialization.OptIn)]
public sealed class PurchaseContract
{
[JsonProperty(PropertyName = "tenantId")]
public TenantId TenantId { get; }
[JsonProperty(PropertyName = "total")]
public double Total { get; }
}
最后,我设置了一个 HTTP 触发函数,该函数将返回一个PurchaseContract
. 目前,它已在以下内容中进行了描述ProducesResponseTypeAttribute
:
[ApiExplorerSettings(GroupName = "Purchases")]
[ProducesResponseType(typeof(PurchaseContract), (int) HttpStatusCode.OK)]
[FunctionName("v1-get-purchase")]
public Task<IActionResult> RunAsync
(
[HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "v1/purchases")]
HttpRequest httpRequest,
[SwaggerIgnore]
ClaimsPrincipal claimsPrincipal
)
{
// Stuff to do.
return Task.FromResult((IActionResult)new OkResult());
}
在我的Startup
课堂上,我正在设置这样的招摇:
private static void ConfigureSwashBuckle(IFunctionsHostBuilder functionsHostBuilder)
{
functionsHostBuilder.AddSwashBuckle(Assembly.GetExecutingAssembly(), options =>
{
options.SpecVersion = OpenApiSpecVersion.OpenApi3_0;
options.AddCodeParameter = true;
options.PrependOperationWithRoutePrefix = true;
options.XmlPath = "FunctionApp.xml";
options.Documents = new []
{
new SwaggerDocument
{
Title = "My API,
Version = "v1",
Name = "v1",
Description = "Description of my API",
}
};
});
}
在 swagger UI 页面中,我可以看到它看起来不错:
问题
使用 Autorest 创建 C# 客户端时出现意外结果。不知何故,该TenantId
结构被删除并替换为object
:
为什么会这样,我应该怎么做才能自动生成TenantId
,就像PurchaseContract
在客户端一样?
细节
这是版本信息。
- 在 netcore3.1 上运行的 Function App V3;
- 开放API 3.0;
- Autorest Core 3.0.6274、autorest.csharp' (~2.3.79->2.3.91) 和 autorest.modeler' (2.3.55->2.3.55);
- NuGet 包AzureExtensions.Swashbuckle;